-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into public-pages-api
- Loading branch information
Showing
11 changed files
with
932 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { PeerConnection, IceServer } from 'node-datachannel' | ||
import type { DuplexRPCClient } from './DuplexRPCClient' | ||
import { | ||
HostSchema, | ||
PeerConnectionInitializer, | ||
ClientSchema, | ||
clientSchema, | ||
} from '../internalRpcSchema' | ||
import ISocket, { DataChannelSocket } from './ISocket' | ||
|
||
export default class DataChannelConnection { | ||
peer: PeerConnection | ||
ds?: DataChannelSocket | ||
rpc?: DuplexRPCClient<ClientSchema, HostSchema> | ||
|
||
constructor({ | ||
id, | ||
iceServers, | ||
send, | ||
rpcConstructor, | ||
}: { | ||
id: string | ||
iceServers: (string | IceServer)[] | ||
send: PeerConnectionInitializer | ||
rpcConstructor: (props: { | ||
communicator: ISocket | ||
canCall: ClientSchema | ||
}) => DuplexRPCClient<ClientSchema, HostSchema> | ||
}) { | ||
this.peer = new PeerConnection(id, { | ||
iceServers, | ||
}) | ||
// For some reason these cause segfaults? | ||
// this.peer.onStateChange(state => { | ||
// console.log('State:', state) | ||
// }) | ||
// this.peer.onGatheringStateChange(state => { | ||
// console.log('GatheringState:', state) | ||
// }) | ||
this.peer.onLocalDescription((description, type) => { | ||
send({ id, type, description }) | ||
}) | ||
this.peer.onLocalCandidate((candidate, mid) => { | ||
send({ id, type: 'candidate', candidate, mid }) | ||
}) | ||
this.peer.onDataChannel(dc => { | ||
const ds = new DataChannelSocket(dc) | ||
this.ds = ds | ||
|
||
const communicator = new ISocket(ds) | ||
|
||
this.rpc = rpcConstructor({ | ||
communicator, | ||
canCall: clientSchema, | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.