@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.
- package/dist/lib/browser/{chunk-J7KS7JMZ.mjs → chunk-6B4JGIV2.mjs} +101 -63
- package/dist/lib/browser/chunk-6B4JGIV2.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -11
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -3
- package/dist/lib/node/{chunk-55WTPQV5.cjs → chunk-Y2B5BDRH.cjs} +97 -65
- package/dist/lib/node/chunk-Y2B5BDRH.cjs.map +7 -0
- package/dist/lib/node/index.cjs +27 -36
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -19
- package/dist/lib/node/testing/index.cjs.map +1 -1
- package/dist/types/src/transport/index.d.ts +0 -1
- package/dist/types/src/transport/index.d.ts.map +1 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts +1 -0
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/topology/mmst-topology.ts +7 -7
- package/src/transport/index.ts +0 -1
- package/src/transport/libdatachannel-transport.ts +76 -34
- package/src/transport/simplepeer-transport.ts +4 -5
- package/dist/lib/browser/chunk-J7KS7JMZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-YERMWDRB.mjs +0 -24
- package/dist/lib/browser/chunk-YERMWDRB.mjs.map +0 -7
- package/dist/lib/browser/index.browser-O53CPVK3.mjs +0 -14
- package/dist/lib/browser/index.browser-O53CPVK3.mjs.map +0 -7
- package/dist/lib/node/chunk-55WTPQV5.cjs.map +0 -7
- package/dist/lib/node/chunk-JDKM4UPJ.cjs +0 -470
- package/dist/lib/node/chunk-JDKM4UPJ.cjs.map +0 -7
- package/dist/lib/node/datachannel-3VTTIMR5.cjs +0 -35
- package/dist/lib/node/datachannel-3VTTIMR5.cjs.map +0 -7
- package/dist/types/src/transport/datachannel/index.browser.d.ts +0 -15
- package/dist/types/src/transport/datachannel/index.browser.d.ts.map +0 -1
- package/dist/types/src/transport/datachannel/index.d.ts +0 -8
- package/dist/types/src/transport/datachannel/index.d.ts.map +0 -1
- package/dist/types/src/transport/datachannel/rtc-data-channel.d.ts +0 -29
- package/dist/types/src/transport/datachannel/rtc-data-channel.d.ts.map +0 -1
- package/dist/types/src/transport/datachannel/rtc-events.d.ts +0 -9
- package/dist/types/src/transport/datachannel/rtc-events.d.ts.map +0 -1
- package/dist/types/src/transport/datachannel/rtc-ice-candidate.d.ts +0 -22
- package/dist/types/src/transport/datachannel/rtc-ice-candidate.d.ts.map +0 -1
- package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts +0 -54
- package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +0 -1
- package/dist/types/src/transport/datachannel/rtc-peer-connection.test.d.ts +0 -2
- package/dist/types/src/transport/datachannel/rtc-peer-connection.test.d.ts.map +0 -1
- package/dist/types/src/transport/datachannel/rtc-session-description.d.ts +0 -10
- package/dist/types/src/transport/datachannel/rtc-session-description.d.ts.map +0 -1
- package/src/transport/datachannel/README.md +0 -2
- package/src/transport/datachannel/index.browser.ts +0 -8
- package/src/transport/datachannel/index.ts +0 -17
- package/src/transport/datachannel/rtc-data-channel.ts +0 -148
- package/src/transport/datachannel/rtc-events.ts +0 -23
- package/src/transport/datachannel/rtc-ice-candidate.ts +0 -54
- package/src/transport/datachannel/rtc-peer-connection.test.ts +0 -112
- package/src/transport/datachannel/rtc-peer-connection.ts +0 -355
- package/src/transport/datachannel/rtc-session-description.ts +0 -23
|
@@ -9,7 +9,6 @@ import { ErrorStream } from '@dxos/debug';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { type Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
11
11
|
|
|
12
|
-
import { type PeerConnection } from './datachannel/rtc-peer-connection';
|
|
13
12
|
import { type Transport, type TransportFactory, type TransportStats } from './transport';
|
|
14
13
|
|
|
15
14
|
export type LibDataChannelTransportParams = {
|
|
@@ -34,7 +33,7 @@ export class LibDataChannelTransport implements Transport {
|
|
|
34
33
|
private _connected = false;
|
|
35
34
|
readonly connected = new Event();
|
|
36
35
|
readonly errors = new ErrorStream();
|
|
37
|
-
private readonly _peer: Promise<
|
|
36
|
+
private readonly _peer: Promise<RTCPeerConnection>;
|
|
38
37
|
private _channel!: RTCDataChannel;
|
|
39
38
|
private _stream!: Duplex;
|
|
40
39
|
|
|
@@ -43,11 +42,20 @@ export class LibDataChannelTransport implements Transport {
|
|
|
43
42
|
|
|
44
43
|
constructor(private readonly params: LibDataChannelTransportParams) {
|
|
45
44
|
this._peer = (async () => {
|
|
46
|
-
|
|
45
|
+
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
|
46
|
+
const { RTCPeerConnection } = (await importESM('node-datachannel/polyfill'))
|
|
47
|
+
.default as typeof import('node-datachannel/polyfill');
|
|
48
|
+
/* eslint-enable @typescript-eslint/consistent-type-imports */
|
|
47
49
|
if (this._closed) {
|
|
48
50
|
this.errors.raise(new Error('connection already closed'));
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
// workaround https://github.com/murat-dogan/node-datachannel/pull/207
|
|
53
|
+
if (params.webrtcConfig) {
|
|
54
|
+
params.webrtcConfig.iceServers = params.webrtcConfig.iceServers ?? [];
|
|
55
|
+
} else {
|
|
56
|
+
params.webrtcConfig = { iceServers: [] };
|
|
57
|
+
}
|
|
58
|
+
const peer = new RTCPeerConnection(params.webrtcConfig);
|
|
51
59
|
|
|
52
60
|
peer.onicecandidateerror = (event) => {
|
|
53
61
|
log.error('peer.onicecandidateerror', { event });
|
|
@@ -84,10 +92,14 @@ export class LibDataChannelTransport implements Transport {
|
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
};
|
|
95
|
+
|
|
87
96
|
if (params.initiator) {
|
|
88
97
|
peer
|
|
89
98
|
.createOffer()
|
|
90
99
|
.then(async (offer) => {
|
|
100
|
+
if (this._closed) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
91
103
|
if (peer.connectionState !== 'connecting') {
|
|
92
104
|
log.error('i am initiator but peer not in state connecting', { peer });
|
|
93
105
|
this.errors.raise(new Error('invalid state: peer is initiator, but other peer not in state connecting'));
|
|
@@ -184,6 +196,12 @@ export class LibDataChannelTransport implements Transport {
|
|
|
184
196
|
return;
|
|
185
197
|
}
|
|
186
198
|
await this._disconnectStreams();
|
|
199
|
+
const peer = await this._peer;
|
|
200
|
+
try {
|
|
201
|
+
peer.close();
|
|
202
|
+
} catch (err: any) {
|
|
203
|
+
this.errors.raise(err);
|
|
204
|
+
}
|
|
187
205
|
this._closed = true;
|
|
188
206
|
this.closed.emit();
|
|
189
207
|
}
|
|
@@ -238,39 +256,60 @@ export class LibDataChannelTransport implements Transport {
|
|
|
238
256
|
}
|
|
239
257
|
|
|
240
258
|
async getDetails(): Promise<string> {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
259
|
+
const stats = await this._getStats();
|
|
260
|
+
const rc = stats?.remoteCandidate;
|
|
261
|
+
if (!rc) {
|
|
262
|
+
return 'unavailable';
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (rc.candidateType === 'relay') {
|
|
266
|
+
return `${rc.ip}:${rc.port} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
267
|
+
}
|
|
268
|
+
return `${rc.ip}:${rc.port} ${rc.candidateType}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async _getStats(): Promise<any> {
|
|
272
|
+
return this._peer.then(async (peer) => {
|
|
273
|
+
const stats = await peer.getStats();
|
|
274
|
+
|
|
275
|
+
const statsEntries = Array.from((stats as any).entries() as any[]);
|
|
276
|
+
const transport = statsEntries.filter((s) => s[1].type === 'transport')[0][1];
|
|
277
|
+
const candidatePair = statsEntries.filter((s: any) => s[0] === transport.selectedCandidatePairId);
|
|
278
|
+
let selectedCandidatePair: any;
|
|
279
|
+
let remoteCandidate: any;
|
|
280
|
+
if (candidatePair.length > 0) {
|
|
281
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
282
|
+
remoteCandidate = statsEntries.filter((s: any) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
transport,
|
|
287
|
+
selectedCandidatePair,
|
|
288
|
+
remoteCandidate,
|
|
289
|
+
raw: Object.fromEntries(stats as any),
|
|
290
|
+
};
|
|
291
|
+
});
|
|
253
292
|
}
|
|
254
293
|
|
|
255
294
|
async getStats(): Promise<TransportStats> {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
295
|
+
const stats = await this._getStats();
|
|
296
|
+
if (!stats) {
|
|
297
|
+
return {
|
|
298
|
+
bytesSent: 0,
|
|
299
|
+
bytesReceived: 0,
|
|
300
|
+
packetsSent: 0,
|
|
301
|
+
packetsReceived: 0,
|
|
302
|
+
rawStats: {},
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return {
|
|
307
|
+
bytesSent: stats.transport.bytesSent,
|
|
308
|
+
bytesReceived: stats.transport.bytesReceived,
|
|
309
|
+
packetsSent: 0,
|
|
310
|
+
packetsReceived: 0,
|
|
311
|
+
rawStats: stats.raw,
|
|
312
|
+
};
|
|
274
313
|
}
|
|
275
314
|
|
|
276
315
|
// TODO(nf): add classmethod to call node-datachannel.cleanup() when all instances have been destroyed?
|
|
@@ -290,3 +329,6 @@ export const createLibDataChannelTransportFactory = (webrtcConfig?: any): Transp
|
|
|
290
329
|
webrtcConfig,
|
|
291
330
|
}),
|
|
292
331
|
});
|
|
332
|
+
|
|
333
|
+
// eslint-disable-next-line no-new-func
|
|
334
|
+
const importESM = Function('path', 'return import(path)');
|
|
@@ -145,8 +145,8 @@ export class SimplePeerTransport implements Transport {
|
|
|
145
145
|
return {
|
|
146
146
|
bytesSent: stats.transport.bytesSent,
|
|
147
147
|
bytesReceived: stats.transport.bytesReceived,
|
|
148
|
-
packetsSent: stats.transport.
|
|
149
|
-
packetsReceived: stats.transport.
|
|
148
|
+
packetsSent: stats.transport.packetsSent,
|
|
149
|
+
packetsReceived: stats.transport.packetsReceived,
|
|
150
150
|
rawStats: stats.raw,
|
|
151
151
|
};
|
|
152
152
|
}
|
|
@@ -182,8 +182,8 @@ export class SimplePeerTransport implements Transport {
|
|
|
182
182
|
return 'unavailable';
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
if (rc.relay) {
|
|
186
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} relay for
|
|
185
|
+
if (rc.candidateType === 'relay') {
|
|
186
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
187
187
|
}
|
|
188
188
|
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
189
189
|
}
|
|
@@ -193,7 +193,6 @@ export class SimplePeerTransport implements Transport {
|
|
|
193
193
|
if (this._closed) {
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
this._closed = true;
|
|
197
196
|
this._disconnectStreams();
|
|
198
197
|
this._peer!.destroy();
|
|
199
198
|
this._closed = true;
|