@dxos/network-manager 0.3.9-main.4e30508 → 0.3.9-main.4e39f3a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/lib/browser/{chunk-J7KS7JMZ.mjs → chunk-6B4JGIV2.mjs} +101 -63
  2. package/dist/lib/browser/chunk-6B4JGIV2.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -11
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +3 -3
  6. package/dist/lib/node/{chunk-55WTPQV5.cjs → chunk-Y2B5BDRH.cjs} +97 -65
  7. package/dist/lib/node/chunk-Y2B5BDRH.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +27 -36
  9. package/dist/lib/node/index.cjs.map +2 -2
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +18 -19
  12. package/dist/lib/node/testing/index.cjs.map +1 -1
  13. package/dist/types/src/transport/index.d.ts +0 -1
  14. package/dist/types/src/transport/index.d.ts.map +1 -1
  15. package/dist/types/src/transport/libdatachannel-transport.d.ts +1 -0
  16. package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
  17. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  18. package/package.json +18 -18
  19. package/src/topology/mmst-topology.ts +7 -7
  20. package/src/transport/index.ts +0 -1
  21. package/src/transport/libdatachannel-transport.ts +76 -34
  22. package/src/transport/simplepeer-transport.ts +4 -5
  23. package/dist/lib/browser/chunk-J7KS7JMZ.mjs.map +0 -7
  24. package/dist/lib/browser/chunk-YERMWDRB.mjs +0 -24
  25. package/dist/lib/browser/chunk-YERMWDRB.mjs.map +0 -7
  26. package/dist/lib/browser/index.browser-O53CPVK3.mjs +0 -14
  27. package/dist/lib/browser/index.browser-O53CPVK3.mjs.map +0 -7
  28. package/dist/lib/node/chunk-55WTPQV5.cjs.map +0 -7
  29. package/dist/lib/node/chunk-JDKM4UPJ.cjs +0 -470
  30. package/dist/lib/node/chunk-JDKM4UPJ.cjs.map +0 -7
  31. package/dist/lib/node/datachannel-3VTTIMR5.cjs +0 -35
  32. package/dist/lib/node/datachannel-3VTTIMR5.cjs.map +0 -7
  33. package/dist/types/src/transport/datachannel/index.browser.d.ts +0 -15
  34. package/dist/types/src/transport/datachannel/index.browser.d.ts.map +0 -1
  35. package/dist/types/src/transport/datachannel/index.d.ts +0 -8
  36. package/dist/types/src/transport/datachannel/index.d.ts.map +0 -1
  37. package/dist/types/src/transport/datachannel/rtc-data-channel.d.ts +0 -29
  38. package/dist/types/src/transport/datachannel/rtc-data-channel.d.ts.map +0 -1
  39. package/dist/types/src/transport/datachannel/rtc-events.d.ts +0 -9
  40. package/dist/types/src/transport/datachannel/rtc-events.d.ts.map +0 -1
  41. package/dist/types/src/transport/datachannel/rtc-ice-candidate.d.ts +0 -22
  42. package/dist/types/src/transport/datachannel/rtc-ice-candidate.d.ts.map +0 -1
  43. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts +0 -54
  44. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +0 -1
  45. package/dist/types/src/transport/datachannel/rtc-peer-connection.test.d.ts +0 -2
  46. package/dist/types/src/transport/datachannel/rtc-peer-connection.test.d.ts.map +0 -1
  47. package/dist/types/src/transport/datachannel/rtc-session-description.d.ts +0 -10
  48. package/dist/types/src/transport/datachannel/rtc-session-description.d.ts.map +0 -1
  49. package/src/transport/datachannel/README.md +0 -2
  50. package/src/transport/datachannel/index.browser.ts +0 -8
  51. package/src/transport/datachannel/index.ts +0 -17
  52. package/src/transport/datachannel/rtc-data-channel.ts +0 -148
  53. package/src/transport/datachannel/rtc-events.ts +0 -23
  54. package/src/transport/datachannel/rtc-ice-candidate.ts +0 -54
  55. package/src/transport/datachannel/rtc-peer-connection.test.ts +0 -112
  56. package/src/transport/datachannel/rtc-peer-connection.ts +0 -355
  57. package/src/transport/datachannel/rtc-session-description.ts +0 -23
@@ -1 +0,0 @@
1
- {"version":3,"file":"rtc-events.d.ts","sourceRoot":"","sources":["../../../../../src/transport/datachannel/rtc-events.ts"],"names":[],"mappings":"AAIA,qBAAa,sBAAuB,SAAQ,KAAM,YAAW,yBAAyB;IACpF,QAAQ,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;gBAE/B,SAAS,EAAE,eAAe;CAKvC;AAED,qBAAa,gBAAiB,SAAQ,KAAM,YAAW,mBAAmB;IACxE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;gBAErB,OAAO,EAAE,cAAc;CAKpC"}
@@ -1,22 +0,0 @@
1
- /**
2
- * @see https://developer.mozilla.org/docs/Web/API/RTCIceCandidate
3
- */
4
- export declare class IceCandidate implements RTCIceCandidate {
5
- readonly address: string | null;
6
- readonly candidate: string;
7
- readonly component: RTCIceComponent | null;
8
- readonly foundation: string | null;
9
- readonly port: number | null;
10
- readonly priority: number | null;
11
- readonly protocol: RTCIceProtocol | null;
12
- readonly relatedAddress: string | null;
13
- readonly relatedPort: number | null;
14
- readonly sdpMLineIndex: number | null;
15
- readonly sdpMid: string | null;
16
- readonly tcpType: RTCIceTcpCandidateType | null;
17
- readonly type: RTCIceCandidateType | null;
18
- readonly usernameFragment: string | null;
19
- constructor(init: RTCIceCandidateInit);
20
- toJSON(): RTCIceCandidateInit;
21
- }
22
- //# sourceMappingURL=rtc-ice-candidate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rtc-ice-candidate.d.ts","sourceRoot":"","sources":["../../../../../src/transport/datachannel/rtc-ice-candidate.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,qBAAa,YAAa,YAAW,eAAe;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;gBAE7B,IAAI,EAAE,mBAAmB;IAsBrC,MAAM,IAAI,mBAAmB;CAQ9B"}
@@ -1,54 +0,0 @@
1
- import { type SelectedCandidateInfo } from 'node-datachannel';
2
- export declare class PeerConnection extends EventTarget implements RTCPeerConnection {
3
- #private;
4
- static generateCertificate(keygenAlgorithm: AlgorithmIdentifier): Promise<RTCCertificate>;
5
- canTrickleIceCandidates: boolean | null;
6
- sctp: RTCSctpTransport | null;
7
- onconnectionstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
8
- ondatachannel: ((this: RTCPeerConnection, ev: RTCDataChannelEvent) => any) | null;
9
- onicecandidate: ((this: RTCPeerConnection, ev: RTCPeerConnectionIceEvent) => any) | null;
10
- onicecandidateerror: ((this: RTCPeerConnection, ev: Event) => any) | null;
11
- oniceconnectionstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
12
- onicegatheringstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
13
- onnegotiationneeded: ((this: RTCPeerConnection, ev: Event) => any) | null;
14
- onsignalingstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
15
- ontrack: ((this: RTCPeerConnection, ev: RTCTrackEvent) => any) | null;
16
- constructor(init?: RTCConfiguration);
17
- get connectionState(): RTCPeerConnectionState;
18
- get iceConnectionState(): RTCIceConnectionState;
19
- get iceGatheringState(): RTCIceGatheringState;
20
- get signalingState(): RTCSignalingState;
21
- get currentLocalDescription(): RTCSessionDescription | null;
22
- get localDescription(): RTCSessionDescription | null;
23
- get pendingLocalDescription(): RTCSessionDescription | null;
24
- get currentRemoteDescription(): RTCSessionDescription | null;
25
- get pendingRemoteDescription(): RTCSessionDescription | null;
26
- get remoteDescription(): RTCSessionDescription | null;
27
- addIceCandidate(candidate?: RTCIceCandidateInit): Promise<void>;
28
- getSelectedCandidatePair(): {
29
- local: SelectedCandidateInfo;
30
- remote: SelectedCandidateInfo;
31
- } | null;
32
- addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender;
33
- addTransceiver(trackOrKind: MediaStreamTrack | string, init?: RTCRtpTransceiverInit): RTCRtpTransceiver;
34
- close(): void;
35
- bytesSent(): number;
36
- bytesReceived(): number;
37
- createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel;
38
- createOffer(options?: RTCOfferOptions): Promise<RTCSessionDescriptionInit>;
39
- createOffer(successCallback: RTCSessionDescriptionCallback, failureCallback: RTCPeerConnectionErrorCallback, options?: RTCOfferOptions): Promise<void>;
40
- createAnswer(options?: RTCAnswerOptions): Promise<RTCSessionDescriptionInit>;
41
- createAnswer(successCallback: RTCSessionDescriptionCallback, failureCallback: RTCPeerConnectionErrorCallback): Promise<void>;
42
- getConfiguration(): RTCConfiguration;
43
- getReceivers(): RTCRtpReceiver[];
44
- getSenders(): RTCRtpSender[];
45
- getStats(selector?: MediaStreamTrack | null): Promise<RTCStatsReport>;
46
- getTransceivers(): RTCRtpTransceiver[];
47
- removeTrack(sender: RTCRtpSender): void;
48
- restartIce(): void;
49
- setConfiguration(configuration?: RTCConfiguration): void;
50
- setLocalDescription(description?: RTCLocalSessionDescriptionInit): Promise<void>;
51
- setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void>;
52
- }
53
- export { PeerConnection as RTCPeerConnection };
54
- //# sourceMappingURL=rtc-peer-connection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rtc-peer-connection.d.ts","sourceRoot":"","sources":["../../../../../src/transport/datachannel/rtc-peer-connection.ts"],"names":[],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=rtc-peer-connection.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rtc-peer-connection.test.d.ts","sourceRoot":"","sources":["../../../../../src/transport/datachannel/rtc-peer-connection.test.ts"],"names":[],"mappings":""}
@@ -1,10 +0,0 @@
1
- /**
2
- * @see https://developer.mozilla.org/docs/Web/API/RTCSessionDescription
3
- */
4
- export declare class SessionDescription implements RTCSessionDescription {
5
- readonly sdp: string;
6
- readonly type: RTCSdpType;
7
- constructor(init: RTCSessionDescriptionInit);
8
- toJSON(): RTCSessionDescriptionInit;
9
- }
10
- //# sourceMappingURL=rtc-session-description.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rtc-session-description.d.ts","sourceRoot":"","sources":["../../../../../src/transport/datachannel/rtc-session-description.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,qBAAa,kBAAmB,YAAW,qBAAqB;IAC9D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;gBAEd,IAAI,EAAE,yBAAyB;IAK3C,MAAM,IAAI,yBAAyB;CAMpC"}
@@ -1,2 +0,0 @@
1
- Code in this directory was adopted from https://github.com/libp2p/js-libp2p/tree/master/packages/transport-webrtc/src/webrtc
2
- at of commit e664d14f
@@ -1,8 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export const RTCPeerConnection = globalThis.RTCPeerConnection;
6
- export const RTCSessionDescription = globalThis.RTCSessionDescription;
7
- export const RTCIceCandidate = globalThis.RTCIceCandidate;
8
- export const cleanup = (): void => {};
@@ -1,17 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import node from 'node-datachannel';
6
-
7
- import { IceCandidate } from './rtc-ice-candidate';
8
- import { PeerConnection } from './rtc-peer-connection';
9
- import { SessionDescription } from './rtc-session-description';
10
-
11
- export { SessionDescription as RTCSessionDescription };
12
- export { IceCandidate as RTCIceCandidate };
13
- export { PeerConnection as RTCPeerConnection };
14
-
15
- export const cleanup = (): void => {
16
- node.cleanup();
17
- };
@@ -1,148 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import type node from 'node-datachannel';
6
-
7
- export class DataChannel extends EventTarget implements RTCDataChannel {
8
- binaryType: BinaryType;
9
-
10
- readonly maxPacketLifeTime: number | null;
11
- readonly maxRetransmits: number | null;
12
- readonly negotiated: boolean;
13
- readonly ordered: boolean;
14
-
15
- onbufferedamountlow: ((this: RTCDataChannel, ev: Event) => any) | null;
16
- onclose: ((this: RTCDataChannel, ev: Event) => any) | null;
17
- onclosing: ((this: RTCDataChannel, ev: Event) => any) | null;
18
- onerror: ((this: RTCDataChannel, ev: Event) => any) | null;
19
- onmessage: ((this: RTCDataChannel, ev: MessageEvent) => any) | null;
20
- onopen: ((this: RTCDataChannel, ev: Event) => any) | null;
21
-
22
- #dataChannel: node.DataChannel;
23
- #bufferedAmountLowThreshold: number;
24
- #readyState: RTCDataChannelState;
25
-
26
- constructor(dataChannel: node.DataChannel, dataChannelDict: RTCDataChannelInit = {}) {
27
- super();
28
-
29
- this.#dataChannel = dataChannel;
30
- this.#readyState = 'connecting';
31
- this.#bufferedAmountLowThreshold = 0;
32
-
33
- this.binaryType = 'arraybuffer';
34
-
35
- this.#dataChannel.onOpen(() => {
36
- this.#readyState = 'open';
37
- this.dispatchEvent(new Event('open'));
38
- });
39
- this.#dataChannel.onClosed(() => {
40
- this.#readyState = 'closed';
41
- this.dispatchEvent(new Event('close'));
42
- });
43
- this.#dataChannel.onError((msg) => {
44
- this.#readyState = 'closed';
45
- this.dispatchEvent(
46
- new RTCErrorEvent('error', {
47
- error: new RTCError(
48
- {
49
- errorDetail: 'data-channel-failure',
50
- },
51
- msg,
52
- ),
53
- }),
54
- );
55
- });
56
- this.#dataChannel.onBufferedAmountLow(() => {
57
- this.dispatchEvent(new Event('bufferedamountlow'));
58
- });
59
- this.#dataChannel.onMessage((data: string | Uint8Array) => {
60
- if (typeof data === 'string') {
61
- data = Buffer.from(data);
62
- }
63
-
64
- this.dispatchEvent(new MessageEvent('message', { data }));
65
- });
66
-
67
- // forward events to properties
68
- this.addEventListener('message', (event) => {
69
- this.onmessage?.(event as MessageEvent<ArrayBuffer>);
70
- });
71
- this.addEventListener('bufferedamountlow', (event) => {
72
- this.onbufferedamountlow?.(event);
73
- });
74
- this.addEventListener('error', (event) => {
75
- this.onerror?.(event);
76
- });
77
- this.addEventListener('close', (event) => {
78
- this.onclose?.(event);
79
- });
80
- this.addEventListener('closing', (event) => {
81
- this.onclosing?.(event);
82
- });
83
- this.addEventListener('open', (event) => {
84
- this.onopen?.(event);
85
- });
86
-
87
- this.onbufferedamountlow = null;
88
- this.onclose = null;
89
- this.onclosing = null;
90
- this.onerror = null;
91
- this.onmessage = null;
92
- this.onopen = null;
93
-
94
- this.maxPacketLifeTime = dataChannelDict.maxPacketLifeTime ?? null;
95
- this.maxRetransmits = dataChannelDict.maxRetransmits ?? null;
96
- this.negotiated = dataChannelDict.negotiated ?? false;
97
- this.ordered = dataChannelDict.ordered ?? true;
98
- }
99
-
100
- get id(): number {
101
- return this.#dataChannel.getId();
102
- }
103
-
104
- get label(): string {
105
- return this.#dataChannel.getLabel();
106
- }
107
-
108
- get protocol(): string {
109
- return this.#dataChannel.getProtocol();
110
- }
111
-
112
- get bufferedAmount(): number {
113
- return this.#dataChannel.bufferedAmount();
114
- }
115
-
116
- set bufferedAmountLowThreshold(threshold: number) {
117
- this.#bufferedAmountLowThreshold = threshold;
118
- this.#dataChannel.setBufferedAmountLowThreshold(threshold);
119
- }
120
-
121
- get bufferedAmountLowThreshold(): number {
122
- return this.#bufferedAmountLowThreshold;
123
- }
124
-
125
- get readyState(): RTCDataChannelState {
126
- return this.#readyState;
127
- }
128
-
129
- close(): void {
130
- this.#readyState = 'closing';
131
- this.dispatchEvent(new Event('closing'));
132
-
133
- this.#dataChannel.close();
134
- }
135
-
136
- send(data: string): void;
137
- send(data: Blob): void;
138
- send(data: ArrayBuffer): void;
139
- send(data: ArrayBufferView): void;
140
- send(data: any): void {
141
- // TODO: sending Blobs
142
- if (typeof data === 'string') {
143
- this.#dataChannel.sendMessage(data);
144
- } else {
145
- this.#dataChannel.sendMessageBinary(data);
146
- }
147
- }
148
- }
@@ -1,23 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export class PeerConnectionIceEvent extends Event implements RTCPeerConnectionIceEvent {
6
- readonly candidate: RTCIceCandidate | null;
7
-
8
- constructor(candidate: RTCIceCandidate) {
9
- super('icecandidate');
10
-
11
- this.candidate = candidate;
12
- }
13
- }
14
-
15
- export class DataChannelEvent extends Event implements RTCDataChannelEvent {
16
- readonly channel: RTCDataChannel;
17
-
18
- constructor(channel: RTCDataChannel) {
19
- super('datachannel');
20
-
21
- this.channel = channel;
22
- }
23
- }
@@ -1,54 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- /**
6
- * @see https://developer.mozilla.org/docs/Web/API/RTCIceCandidate
7
- */
8
- export class IceCandidate implements RTCIceCandidate {
9
- readonly address: string | null;
10
- readonly candidate: string;
11
- readonly component: RTCIceComponent | null;
12
- readonly foundation: string | null;
13
- readonly port: number | null;
14
- readonly priority: number | null;
15
- readonly protocol: RTCIceProtocol | null;
16
- readonly relatedAddress: string | null;
17
- readonly relatedPort: number | null;
18
- readonly sdpMLineIndex: number | null;
19
- readonly sdpMid: string | null;
20
- readonly tcpType: RTCIceTcpCandidateType | null;
21
- readonly type: RTCIceCandidateType | null;
22
- readonly usernameFragment: string | null;
23
-
24
- constructor(init: RTCIceCandidateInit) {
25
- if (init.candidate == null) {
26
- throw new DOMException('candidate must be specified');
27
- }
28
-
29
- this.candidate = init.candidate;
30
- this.sdpMLineIndex = init.sdpMLineIndex ?? null;
31
- this.sdpMid = init.sdpMid ?? null;
32
- this.usernameFragment = init.usernameFragment ?? null;
33
-
34
- this.address = null;
35
- this.component = null;
36
- this.foundation = null;
37
- this.port = null;
38
- this.priority = null;
39
- this.protocol = null;
40
- this.relatedAddress = null;
41
- this.relatedPort = null;
42
- this.tcpType = null;
43
- this.type = null;
44
- }
45
-
46
- toJSON(): RTCIceCandidateInit {
47
- return {
48
- candidate: this.candidate,
49
- sdpMLineIndex: this.sdpMLineIndex,
50
- sdpMid: this.sdpMid,
51
- usernameFragment: this.usernameFragment,
52
- };
53
- }
54
- }
@@ -1,112 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- // @dxos/test platform=nodejs
6
-
7
- import { expect } from 'chai';
8
- import nodeDataChannel from 'node-datachannel';
9
-
10
- import { Trigger, asyncTimeout } from '@dxos/async';
11
- import { log } from '@dxos/log';
12
- import { afterTest, describe, test } from '@dxos/test';
13
-
14
- import { PeerConnection } from './rtc-peer-connection';
15
-
16
- describe('Node WebRTC libdatachannel implementation', () => {
17
- test('Connect two datachannels', async () => {
18
- const msg1to2 = 'Hello from Peer1';
19
- const firstPeerReceived = new Trigger<string | Buffer>();
20
- const msg2to1 = 'Hello from Peer2';
21
- const secondPeerReceived = new Trigger<string | Buffer>();
22
-
23
- let dc2: nodeDataChannel.DataChannel;
24
- afterTest(() => dc2.close());
25
-
26
- const peer1 = new nodeDataChannel.PeerConnection('Peer1', { iceServers: ['stun:stun.l.google.com:19302'] });
27
- afterTest(() => peer1.close());
28
-
29
- // Set Callbacks
30
- peer1.onLocalDescription((sdp, type) => {
31
- peer2.setRemoteDescription(sdp, type);
32
- });
33
- peer1.onLocalCandidate((candidate, mid) => {
34
- peer2.addRemoteCandidate(candidate, mid);
35
- });
36
-
37
- const peer2 = new nodeDataChannel.PeerConnection('Peer2', { iceServers: ['stun:stun.l.google.com:19302'] });
38
- afterTest(() => peer2.close());
39
-
40
- // Set Callbacks
41
- peer2.onLocalDescription((sdp, type) => {
42
- peer1.setRemoteDescription(sdp, type);
43
- });
44
- peer2.onLocalCandidate((candidate, mid) => {
45
- peer1.addRemoteCandidate(candidate, mid);
46
- });
47
- peer2.onDataChannel((dc) => {
48
- dc2 = dc;
49
- dc2.onMessage((msg) => secondPeerReceived.wake(msg));
50
- dc2.sendMessage(msg2to1);
51
- });
52
-
53
- const dc1 = peer1.createDataChannel('test');
54
- afterTest(() => dc1.close());
55
-
56
- dc1.onOpen(() => dc1.sendMessage(msg1to2));
57
-
58
- dc1.onMessage((msg) => firstPeerReceived.wake(msg));
59
- dc1.onMessage((msg) => firstPeerReceived.wake(msg));
60
- expect(await asyncTimeout(firstPeerReceived.wait(), 3000)).to.eq(msg2to1);
61
- expect(await asyncTimeout(secondPeerReceived.wait(), 3000)).to.eq(msg1to2);
62
- });
63
-
64
- test('RTCPeerConnection', async () => {
65
- const msg1to2 = 'Hello from Peer1';
66
- const firstPeerReceived = new Trigger<string | Buffer>();
67
- const msg2to1 = 'Hello from Peer2';
68
- const secondPeerReceived = new Trigger<string | Buffer>();
69
-
70
- const peer1 = new PeerConnection();
71
- afterTest(() => peer1.close());
72
-
73
- const peer2 = new PeerConnection();
74
- afterTest(() => peer2.close());
75
-
76
- peer1
77
- .createOffer()
78
- .then(async (offer) => {
79
- await peer2.setRemoteDescription(offer);
80
- const answer = await peer2.createAnswer();
81
- await peer1.setRemoteDescription(answer);
82
- })
83
- .catch((err) => {
84
- log.catch(err);
85
- });
86
-
87
- peer1.onicecandidate = async (env) => {
88
- await peer2.addIceCandidate(env.candidate?.toJSON());
89
- };
90
- peer2.onicecandidate = async (env) => {
91
- await peer1.addIceCandidate(env.candidate?.toJSON());
92
- };
93
- let dc2: RTCDataChannel;
94
- peer2.ondatachannel = ({ channel }) => {
95
- dc2 = channel;
96
- dc2.onmessage = (msg) => {
97
- secondPeerReceived.wake(msg.data);
98
- };
99
- dc2.send(msg2to1);
100
- };
101
-
102
- const dc1 = peer1.createDataChannel('test');
103
- dc1.onmessage = (msg) => {
104
- firstPeerReceived.wake(msg.data);
105
- };
106
-
107
- dc1.onopen = () => dc1.send(msg1to2);
108
-
109
- expect((await asyncTimeout(firstPeerReceived.wait(), 3000)).toString()).to.eq(msg2to1);
110
- expect((await asyncTimeout(secondPeerReceived.wait(), 3000)).toString()).to.eq(msg1to2);
111
- });
112
- });