@dxos/network-manager 0.6.13 → 0.6.14-main.2b6a0f3
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.
- package/dist/lib/browser/chunk-GW3YM55A.mjs +14 -0
- package/dist/lib/browser/chunk-GW3YM55A.mjs.map +7 -0
- package/dist/lib/browser/{chunk-XYSYUN63.mjs → chunk-V3IRGRVX.mjs} +1501 -1655
- package/dist/lib/browser/chunk-V3IRGRVX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +347 -22
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +22 -32
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/transport/tcp/index.mjs +39 -0
- package/dist/lib/browser/transport/tcp/index.mjs.map +7 -0
- package/dist/lib/node/{chunk-4YAYC7WN.cjs → chunk-4TTFBX3M.cjs} +1504 -1782
- package/dist/lib/node/chunk-4TTFBX3M.cjs.map +7 -0
- package/dist/lib/node/index.cjs +356 -37
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +24 -34
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node/transport/tcp/index.cjs +191 -0
- package/dist/lib/node/transport/tcp/index.cjs.map +7 -0
- package/dist/lib/node-esm/chunk-6MN5JVRP.mjs +4035 -0
- package/dist/lib/node-esm/chunk-6MN5JVRP.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +382 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +279 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/transport/tcp/index.mjs +159 -0
- package/dist/lib/node-esm/transport/tcp/index.mjs.map +7 -0
- package/dist/types/src/network-manager.d.ts +2 -1
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/ice.d.ts.map +1 -1
- package/dist/types/src/signal/integration.node.test.d.ts +2 -0
- package/dist/types/src/signal/integration.node.test.d.ts.map +1 -0
- package/dist/types/src/signal/swarm-messenger.node.test.d.ts +2 -0
- package/dist/types/src/signal/swarm-messenger.node.test.d.ts.map +1 -0
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts +2 -2
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts +1 -2
- package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/tcp-transport.node.test.d.ts +2 -0
- package/dist/types/src/tests/tcp-transport.node.test.d.ts.map +1 -0
- package/dist/types/src/tests/utils.d.ts.map +1 -1
- package/dist/types/src/transport/index.d.ts +1 -5
- package/dist/types/src/transport/index.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts +2 -2
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/index.d.ts +2 -0
- package/dist/types/src/transport/tcp/index.d.ts.map +1 -0
- package/dist/types/src/transport/{tcp-transport.browser.d.ts → tcp/tcp-transport.browser.d.ts} +3 -3
- package/dist/types/src/transport/tcp/tcp-transport.browser.d.ts.map +1 -0
- package/dist/types/src/transport/{tcp-transport.d.ts → tcp/tcp-transport.d.ts} +3 -3
- package/dist/types/src/transport/tcp/tcp-transport.d.ts.map +1 -0
- package/dist/types/src/transport/transport.d.ts +7 -6
- package/dist/types/src/transport/transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/index.d.ts +4 -0
- package/dist/types/src/transport/webrtc/index.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-connection-factory.d.ts +14 -0
- package/dist/types/src/transport/webrtc/rtc-connection-factory.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +68 -0
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts +33 -0
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-channel.test.d.ts +2 -0
- package/dist/types/src/transport/webrtc/rtc-transport-channel.test.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts +4 -0
- package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -0
- package/dist/types/src/transport/{simplepeer-transport-proxy.d.ts → webrtc/rtc-transport-proxy.d.ts} +10 -12
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.test.d.ts +2 -0
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.test.d.ts.map +1 -0
- package/dist/types/src/transport/{simplepeer-transport-service.d.ts → webrtc/rtc-transport-service.d.ts} +9 -7
- package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts +4 -0
- package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport.test.d.ts +2 -0
- package/dist/types/src/transport/webrtc/rtc-transport.test.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/test-utils.d.ts +5 -0
- package/dist/types/src/transport/webrtc/test-utils.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/utils.d.ts +3 -0
- package/dist/types/src/transport/webrtc/utils.d.ts.map +1 -0
- package/package.json +56 -30
- package/src/network-manager.ts +5 -13
- package/src/signal/ice.test.ts +1 -3
- package/src/signal/ice.ts +6 -1
- package/src/signal/{integration.test.ts → integration.node.test.ts} +9 -15
- package/src/signal/{swarm-messenger.test.ts → swarm-messenger.node.test.ts} +13 -23
- package/src/swarm/connection-limiter.test.ts +3 -6
- package/src/swarm/connection.test.ts +63 -38
- package/src/swarm/connection.ts +5 -5
- package/src/swarm/swarm.test.ts +10 -12
- package/src/swarm/swarm.ts +1 -1
- package/src/testing/test-builder.ts +13 -29
- package/src/testing/test-wire-protocol.ts +1 -4
- package/src/tests/basic-test-suite.ts +34 -33
- package/src/tests/memory-transport.test.ts +40 -42
- package/src/tests/property-test-suite.ts +21 -22
- package/src/tests/tcp-transport.node.test.ts +65 -0
- package/src/tests/utils.ts +3 -2
- package/src/tests/webrtc-transport.test.ts +9 -9
- package/src/transport/index.ts +1 -5
- package/src/transport/memory-transport.ts +2 -0
- package/src/transport/tcp/index.ts +5 -0
- package/src/transport/{tcp-transport.browser.ts → tcp/tcp-transport.browser.ts} +7 -3
- package/src/transport/{tcp-transport.ts → tcp/tcp-transport.ts} +3 -1
- package/src/transport/transport.ts +8 -7
- package/src/transport/webrtc/index.ts +7 -0
- package/src/transport/webrtc/rtc-connection-factory.ts +82 -0
- package/src/transport/webrtc/rtc-peer-connection.ts +472 -0
- package/src/transport/webrtc/rtc-transport-channel.test.ts +176 -0
- package/src/transport/webrtc/rtc-transport-channel.ts +195 -0
- package/src/transport/webrtc/rtc-transport-factory.ts +28 -0
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +413 -0
- package/src/transport/webrtc/rtc-transport-proxy.ts +264 -0
- package/src/transport/webrtc/rtc-transport-service.ts +192 -0
- package/src/transport/webrtc/rtc-transport-stats.ts +67 -0
- package/src/transport/webrtc/rtc-transport.test.ts +198 -0
- package/src/transport/webrtc/test-utils.ts +22 -0
- package/src/transport/webrtc/utils.ts +36 -0
- package/src/typings.d.ts +8 -2
- package/dist/lib/browser/chunk-XYSYUN63.mjs.map +0 -7
- package/dist/lib/node/chunk-4YAYC7WN.cjs.map +0 -7
- package/dist/types/src/signal/integration.test.d.ts +0 -2
- package/dist/types/src/signal/integration.test.d.ts.map +0 -1
- package/dist/types/src/signal/swarm-messenger.test.d.ts +0 -2
- package/dist/types/src/signal/swarm-messenger.test.d.ts.map +0 -1
- package/dist/types/src/tests/tcp-transport.test.d.ts +0 -2
- package/dist/types/src/tests/tcp-transport.test.d.ts.map +0 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts +0 -42
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +0 -1
- package/dist/types/src/transport/libdatachannel-transport.test.d.ts +0 -2
- package/dist/types/src/transport/libdatachannel-transport.test.d.ts.map +0 -1
- package/dist/types/src/transport/memory-transport.test.d.ts +0 -2
- package/dist/types/src/transport/memory-transport.test.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-simple-peer.d.ts +0 -2
- package/dist/types/src/transport/simplepeer-simple-peer.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport-proxy-test.d.ts +0 -2
- package/dist/types/src/transport/simplepeer-transport-proxy-test.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts +0 -36
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport.test.d.ts +0 -2
- package/dist/types/src/transport/simplepeer-transport.test.d.ts.map +0 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts.map +0 -1
- package/dist/types/src/transport/tcp-transport.d.ts.map +0 -1
- package/dist/types/src/transport/webrtc.d.ts +0 -6
- package/dist/types/src/transport/webrtc.d.ts.map +0 -1
- package/src/globals.d.ts +0 -7
- package/src/tests/tcp-transport.test.ts +0 -67
- package/src/transport/libdatachannel-transport.test.ts +0 -100
- package/src/transport/libdatachannel-transport.ts +0 -376
- package/src/transport/memory-transport.test.ts +0 -74
- package/src/transport/simplepeer-simple-peer.ts +0 -26
- package/src/transport/simplepeer-transport-proxy-test.ts +0 -181
- package/src/transport/simplepeer-transport-proxy.ts +0 -246
- package/src/transport/simplepeer-transport-service.ts +0 -160
- package/src/transport/simplepeer-transport.test.ts +0 -61
- package/src/transport/simplepeer-transport.ts +0 -250
- package/src/transport/webrtc.ts +0 -15
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { onTestFinished, describe, expect, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { sleep, TestStream } from '@dxos/async';
|
|
8
|
+
import { PublicKey } from '@dxos/keys';
|
|
9
|
+
|
|
10
|
+
import { getRtcConnectionFactory } from './rtc-connection-factory';
|
|
11
|
+
import { RtcPeerConnection } from './rtc-peer-connection';
|
|
12
|
+
import { type RtcTransportChannel } from './rtc-transport-channel';
|
|
13
|
+
import { chooseInitiatorPeer } from './utils';
|
|
14
|
+
import { type TransportOptions } from '../transport';
|
|
15
|
+
|
|
16
|
+
const connectionFactory = getRtcConnectionFactory();
|
|
17
|
+
|
|
18
|
+
describe('RtcTransport', () => {
|
|
19
|
+
test('channel open and close', async () => {
|
|
20
|
+
const peer = await createConnection();
|
|
21
|
+
const channel = createChannel(peer);
|
|
22
|
+
|
|
23
|
+
await channel.open();
|
|
24
|
+
const wait = channel.closed.waitForCount(1);
|
|
25
|
+
await channel.close();
|
|
26
|
+
await wait;
|
|
27
|
+
|
|
28
|
+
expect(peer.connection.transportChannelCount).to.eq(0);
|
|
29
|
+
await expect.poll(() => channel.isRtcChannelCreationInProgress).toBeFalsy();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('establish connection and send data through with protocol', async () => {
|
|
33
|
+
const { initiator, another } = await createConnectedPeers();
|
|
34
|
+
const initiatorChannel = createChannel(initiator);
|
|
35
|
+
const anotherChannel = createChannel(another);
|
|
36
|
+
|
|
37
|
+
await initiatorChannel.open();
|
|
38
|
+
await anotherChannel.open();
|
|
39
|
+
|
|
40
|
+
await TestStream.assertConnectivity(initiator.stream, another.stream, { timeout: 1500 });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('initiator opens a channel before another peer', async () => {
|
|
44
|
+
const { initiator, another } = await createConnectedPeers();
|
|
45
|
+
const initiatorChannel = createChannel(initiator);
|
|
46
|
+
const anotherChannel = createChannel(another);
|
|
47
|
+
|
|
48
|
+
await initiatorChannel.open();
|
|
49
|
+
await sleep(50);
|
|
50
|
+
await anotherChannel.open();
|
|
51
|
+
|
|
52
|
+
await TestStream.assertConnectivity(initiator.stream, another.stream, { timeout: 1500 });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('initiator opens a channel after another peer', async () => {
|
|
56
|
+
const { initiator, another } = await createConnectedPeers();
|
|
57
|
+
const initiatorChannel = createChannel(initiator);
|
|
58
|
+
const anotherChannel = createChannel(another);
|
|
59
|
+
|
|
60
|
+
await anotherChannel.open();
|
|
61
|
+
await sleep(50);
|
|
62
|
+
await initiatorChannel.open();
|
|
63
|
+
|
|
64
|
+
await TestStream.assertConnectivity(initiator.stream, another.stream, { timeout: 1500 });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('signal delivery idempotency', async () => {
|
|
68
|
+
const { initiator, another } = await createConnectedPeers({ duplicateSignals: true });
|
|
69
|
+
const initiatorChannel = createChannel(initiator);
|
|
70
|
+
const anotherChannel = createChannel(another);
|
|
71
|
+
|
|
72
|
+
await anotherChannel.open();
|
|
73
|
+
await sleep(50);
|
|
74
|
+
await initiatorChannel.open();
|
|
75
|
+
|
|
76
|
+
await TestStream.assertConnectivity(initiator.stream, another.stream, { timeout: 1500 });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('initiator closes before connectivity is established', async () => {
|
|
80
|
+
const { initiator, another } = await createConnectedPeers();
|
|
81
|
+
const initiatorChannel = createChannel(initiator);
|
|
82
|
+
const anotherChannel = createChannel(another);
|
|
83
|
+
|
|
84
|
+
await initiatorChannel.open();
|
|
85
|
+
await sleep(20);
|
|
86
|
+
await anotherChannel.open();
|
|
87
|
+
await initiatorChannel.close();
|
|
88
|
+
|
|
89
|
+
initiatorChannel.errors.assertNoUnhandledErrors();
|
|
90
|
+
anotherChannel.errors.assertNoUnhandledErrors();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('initiator opens a channel after another peer closed it', async () => {
|
|
94
|
+
const { initiator, another } = await createConnectedPeers({ duplicateSignals: true });
|
|
95
|
+
const initiatorChannel = createChannel(initiator);
|
|
96
|
+
const anotherChannel = createChannel(another);
|
|
97
|
+
|
|
98
|
+
await anotherChannel.open();
|
|
99
|
+
await sleep(20);
|
|
100
|
+
await anotherChannel.close();
|
|
101
|
+
await initiatorChannel.open();
|
|
102
|
+
await initiatorChannel.close();
|
|
103
|
+
|
|
104
|
+
await expect.poll(() => anotherChannel.isRtcChannelCreationInProgress).toBeFalsy();
|
|
105
|
+
initiatorChannel.errors.assertNoUnhandledErrors();
|
|
106
|
+
anotherChannel.errors.assertNoUnhandledErrors();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const createConnectedPeers = async (options?: { duplicateSignals?: boolean }) => {
|
|
110
|
+
const peer1Signal = createSignalSender(options);
|
|
111
|
+
const peer2Signal = createSignalSender(options);
|
|
112
|
+
|
|
113
|
+
const peer1 = await createConnection({ sendSignal: peer1Signal.sendSignal }, peer2Signal.onChannelCreated);
|
|
114
|
+
const peer2 = await createConnection(
|
|
115
|
+
{
|
|
116
|
+
ownPeerKey: peer1.options.remotePeerKey,
|
|
117
|
+
remotePeerKey: peer1.options.ownPeerKey,
|
|
118
|
+
topic: peer1.options.topic,
|
|
119
|
+
sendSignal: peer2Signal.sendSignal,
|
|
120
|
+
},
|
|
121
|
+
peer1Signal.onChannelCreated,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return chooseInitiator(peer1, peer2);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const createSignalSender = (options?: { duplicateSignals?: boolean }) => {
|
|
128
|
+
const deliverSignal = (channel: RtcTransportChannel, signal: any) => {
|
|
129
|
+
void channel.onSignal(signal);
|
|
130
|
+
if (options?.duplicateSignals) {
|
|
131
|
+
void channel.onSignal(signal);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
let remoteChannel: RtcTransportChannel | undefined;
|
|
135
|
+
const signalBuffer: any[] = [];
|
|
136
|
+
const sendSignal = async (signal: any) => {
|
|
137
|
+
await sleep(10);
|
|
138
|
+
if (remoteChannel) {
|
|
139
|
+
deliverSignal(remoteChannel, signal);
|
|
140
|
+
} else {
|
|
141
|
+
signalBuffer.push(signal);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const onChannelCreated = (channel: RtcTransportChannel): void => {
|
|
145
|
+
remoteChannel = channel;
|
|
146
|
+
for (const signal of signalBuffer) {
|
|
147
|
+
deliverSignal(channel, signal);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return { sendSignal, onChannelCreated };
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const createConnection = async (
|
|
154
|
+
optionOverrides?: Partial<TransportOptions>,
|
|
155
|
+
onChannelCreated: (channel: RtcTransportChannel) => void = () => {},
|
|
156
|
+
): Promise<TestSetup> => {
|
|
157
|
+
const stream = new TestStream();
|
|
158
|
+
const options: TransportOptions = {
|
|
159
|
+
initiator: false,
|
|
160
|
+
stream,
|
|
161
|
+
sendSignal: async () => {},
|
|
162
|
+
remotePeerKey: PublicKey.random().toHex(),
|
|
163
|
+
ownPeerKey: PublicKey.random().toHex(),
|
|
164
|
+
topic: PublicKey.random().toHex(),
|
|
165
|
+
...optionOverrides,
|
|
166
|
+
};
|
|
167
|
+
const connection = new RtcPeerConnection(connectionFactory, options);
|
|
168
|
+
return { options, connection, stream, onChannelOpen: onChannelCreated };
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const chooseInitiator = (peer1: TestSetup, peer2: TestSetup) => {
|
|
172
|
+
const [initiator, another] =
|
|
173
|
+
chooseInitiatorPeer(peer1.options.ownPeerKey, peer2.options.ownPeerKey) === peer1.options.ownPeerKey
|
|
174
|
+
? [peer1, peer2]
|
|
175
|
+
: [peer2, peer1];
|
|
176
|
+
return { initiator, another };
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const createChannel = (args: TestSetup) => {
|
|
180
|
+
const channel = args.connection.createTransportChannel(args.options);
|
|
181
|
+
const originalOpen = channel.open.bind(channel);
|
|
182
|
+
(channel as any).open = async () => {
|
|
183
|
+
await originalOpen();
|
|
184
|
+
args.onChannelOpen(channel);
|
|
185
|
+
};
|
|
186
|
+
onTestFinished(async () => {
|
|
187
|
+
await channel.close();
|
|
188
|
+
});
|
|
189
|
+
return channel;
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
type TestSetup = {
|
|
194
|
+
stream: TestStream;
|
|
195
|
+
connection: RtcPeerConnection;
|
|
196
|
+
options: TransportOptions;
|
|
197
|
+
onChannelOpen: (channel: RtcTransportChannel) => void;
|
|
198
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { expect } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { sleep } from '@dxos/async';
|
|
8
|
+
|
|
9
|
+
import { type Transport } from '../transport';
|
|
10
|
+
|
|
11
|
+
export const handleChannelErrors = (channel: Transport) => {
|
|
12
|
+
let handled = false;
|
|
13
|
+
channel.errors.handle(() => (handled = true));
|
|
14
|
+
return {
|
|
15
|
+
expectErrorRaised: async () => {
|
|
16
|
+
if (!handled) {
|
|
17
|
+
await sleep(5);
|
|
18
|
+
}
|
|
19
|
+
expect(handled).toBeTruthy();
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
export const chooseInitiatorPeer = (peer1Key: string, peer2Key: string) => (peer1Key < peer2Key ? peer1Key : peer2Key);
|
|
6
|
+
|
|
7
|
+
export const areSdpEqual = (sdp1: string, sdp2: string) => {
|
|
8
|
+
const sdp1Lines = deduplicatedSdpLines(sdp1);
|
|
9
|
+
const sdp2Lines = deduplicatedSdpLines(sdp2);
|
|
10
|
+
if (sdp1Lines.length !== sdp2Lines.length) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return sdp1Lines.every((line, idx) => line === sdp2Lines[idx]);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* For some reason libdatachannel duplicates some attributes after an sdp is set.
|
|
18
|
+
* So the following test might fail:
|
|
19
|
+
* conn.setRemoteDescription(sdp);
|
|
20
|
+
* expect(conn.remoteDescription.sdp).toEqual(sdp);
|
|
21
|
+
*/
|
|
22
|
+
const deduplicatedSdpLines = (sdp: string) => {
|
|
23
|
+
const deduplicatedLines: string[] = [];
|
|
24
|
+
const seenLines: string[] = [];
|
|
25
|
+
for (const line of sdp.split('\r\n')) {
|
|
26
|
+
if (line.startsWith('m')) {
|
|
27
|
+
seenLines.length = 0;
|
|
28
|
+
}
|
|
29
|
+
if (seenLines.includes(line)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
seenLines.push(line);
|
|
33
|
+
deduplicatedLines.push(line);
|
|
34
|
+
}
|
|
35
|
+
return deduplicatedLines;
|
|
36
|
+
};
|
package/src/typings.d.ts
CHANGED
|
@@ -3,5 +3,11 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
declare module '@koush/wrtc';
|
|
6
|
-
|
|
7
|
-
declare module '
|
|
6
|
+
|
|
7
|
+
declare module '#node-datachannel' {
|
|
8
|
+
export * from 'node-datachannel';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module '#node-datachannel/polyfill' {
|
|
12
|
+
export * from 'node-datachannel/polyfill';
|
|
13
|
+
}
|