@dxos/network-manager 0.3.9-main.e6215fc → 0.3.9-main.eb5df3b
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-HJ6JLRZM.mjs → chunk-6B4JGIV2.mjs} +168 -70
- 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-XZF4MAFB.cjs → chunk-Y2B5BDRH.cjs} +164 -72
- 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/topology/mmst-topology.d.ts +1 -0
- package/dist/types/src/topology/mmst-topology.d.ts.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 +34 -6
- 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-HJ6JLRZM.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-JDKM4UPJ.cjs +0 -470
- package/dist/lib/node/chunk-JDKM4UPJ.cjs.map +0 -7
- package/dist/lib/node/chunk-XZF4MAFB.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
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined")
|
|
6
|
+
return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// inject-globals:@inject-globals
|
|
2
11
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
12
|
+
global,
|
|
13
|
+
Buffer as Buffer2,
|
|
14
|
+
process
|
|
15
|
+
} from "@dxos/node-std/inject-globals";
|
|
5
16
|
|
|
6
17
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
7
18
|
import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized } from "@dxos/async";
|
|
@@ -2349,9 +2360,12 @@ import distance from "xor-distance";
|
|
|
2349
2360
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2350
2361
|
import { log as log8 } from "@dxos/log";
|
|
2351
2362
|
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2363
|
+
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2364
|
+
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2352
2365
|
var MMSTTopology = class {
|
|
2353
2366
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2354
2367
|
this._sampleCollected = false;
|
|
2368
|
+
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2355
2369
|
this._originateConnections = originateConnections;
|
|
2356
2370
|
this._maxPeers = maxPeers;
|
|
2357
2371
|
this._sampleSize = sampleSize;
|
|
@@ -2359,7 +2373,7 @@ var MMSTTopology = class {
|
|
|
2359
2373
|
init(controller) {
|
|
2360
2374
|
invariant8(!this._controller, "Already initialized", {
|
|
2361
2375
|
F: __dxlog_file9,
|
|
2362
|
-
L:
|
|
2376
|
+
L: 51,
|
|
2363
2377
|
S: this,
|
|
2364
2378
|
A: [
|
|
2365
2379
|
"!this._controller",
|
|
@@ -2371,7 +2385,7 @@ var MMSTTopology = class {
|
|
|
2371
2385
|
update() {
|
|
2372
2386
|
invariant8(this._controller, "Not initialized", {
|
|
2373
2387
|
F: __dxlog_file9,
|
|
2374
|
-
L:
|
|
2388
|
+
L: 56,
|
|
2375
2389
|
S: this,
|
|
2376
2390
|
A: [
|
|
2377
2391
|
"this._controller",
|
|
@@ -2382,7 +2396,7 @@ var MMSTTopology = class {
|
|
|
2382
2396
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2383
2397
|
log8("Running the algorithm.", void 0, {
|
|
2384
2398
|
F: __dxlog_file9,
|
|
2385
|
-
L:
|
|
2399
|
+
L: 60,
|
|
2386
2400
|
S: this,
|
|
2387
2401
|
C: (f, a) => f(...a)
|
|
2388
2402
|
});
|
|
@@ -2393,7 +2407,7 @@ var MMSTTopology = class {
|
|
|
2393
2407
|
async onOffer(peer) {
|
|
2394
2408
|
invariant8(this._controller, "Not initialized", {
|
|
2395
2409
|
F: __dxlog_file9,
|
|
2396
|
-
L:
|
|
2410
|
+
L: 67,
|
|
2397
2411
|
S: this,
|
|
2398
2412
|
A: [
|
|
2399
2413
|
"this._controller",
|
|
@@ -2404,7 +2418,7 @@ var MMSTTopology = class {
|
|
|
2404
2418
|
const accept = connected.length < this._maxPeers;
|
|
2405
2419
|
log8(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2406
2420
|
F: __dxlog_file9,
|
|
2407
|
-
L:
|
|
2421
|
+
L: 70,
|
|
2408
2422
|
S: this,
|
|
2409
2423
|
C: (f, a) => f(...a)
|
|
2410
2424
|
});
|
|
@@ -2415,7 +2429,7 @@ var MMSTTopology = class {
|
|
|
2415
2429
|
_runAlgorithm() {
|
|
2416
2430
|
invariant8(this._controller, "Not initialized", {
|
|
2417
2431
|
F: __dxlog_file9,
|
|
2418
|
-
L:
|
|
2432
|
+
L: 79,
|
|
2419
2433
|
S: this,
|
|
2420
2434
|
A: [
|
|
2421
2435
|
"this._controller",
|
|
@@ -2424,27 +2438,84 @@ var MMSTTopology = class {
|
|
|
2424
2438
|
});
|
|
2425
2439
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2426
2440
|
if (connected.length > this._maxPeers) {
|
|
2441
|
+
log8(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2442
|
+
F: __dxlog_file9,
|
|
2443
|
+
L: 85,
|
|
2444
|
+
S: this,
|
|
2445
|
+
C: (f, a) => f(...a)
|
|
2446
|
+
});
|
|
2427
2447
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2428
|
-
|
|
2429
|
-
|
|
2448
|
+
invariant8(sorted.length === 0, void 0, {
|
|
2449
|
+
F: __dxlog_file9,
|
|
2450
|
+
L: 89,
|
|
2451
|
+
S: this,
|
|
2452
|
+
A: [
|
|
2453
|
+
"sorted.length === 0",
|
|
2454
|
+
""
|
|
2455
|
+
]
|
|
2456
|
+
});
|
|
2457
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2458
|
+
log8(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2430
2459
|
F: __dxlog_file9,
|
|
2431
|
-
L:
|
|
2460
|
+
L: 92,
|
|
2461
|
+
S: this,
|
|
2462
|
+
C: (f, a) => f(...a)
|
|
2463
|
+
});
|
|
2464
|
+
}
|
|
2465
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2466
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2467
|
+
log8(`Disconnect ${peer}.`, void 0, {
|
|
2468
|
+
F: __dxlog_file9,
|
|
2469
|
+
L: 97,
|
|
2470
|
+
S: this,
|
|
2471
|
+
C: (f, a) => f(...a)
|
|
2472
|
+
});
|
|
2473
|
+
this._controller.disconnect(peer);
|
|
2474
|
+
}
|
|
2475
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2476
|
+
} else {
|
|
2477
|
+
log8("rate limited discconnect", void 0, {
|
|
2478
|
+
F: __dxlog_file9,
|
|
2479
|
+
L: 102,
|
|
2432
2480
|
S: this,
|
|
2433
2481
|
C: (f, a) => f(...a)
|
|
2434
2482
|
});
|
|
2435
|
-
this._controller.disconnect(peer);
|
|
2436
2483
|
}
|
|
2437
2484
|
} else if (connected.length < this._originateConnections) {
|
|
2485
|
+
log8(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2486
|
+
F: __dxlog_file9,
|
|
2487
|
+
L: 106,
|
|
2488
|
+
S: this,
|
|
2489
|
+
C: (f, a) => f(...a)
|
|
2490
|
+
});
|
|
2438
2491
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2439
2492
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2440
|
-
|
|
2441
|
-
log8(`
|
|
2493
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2494
|
+
log8(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2442
2495
|
F: __dxlog_file9,
|
|
2443
|
-
L:
|
|
2496
|
+
L: 111,
|
|
2497
|
+
S: this,
|
|
2498
|
+
C: (f, a) => f(...a)
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2502
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2503
|
+
log8(`Connect ${peer}.`, void 0, {
|
|
2504
|
+
F: __dxlog_file9,
|
|
2505
|
+
L: 115,
|
|
2506
|
+
S: this,
|
|
2507
|
+
C: (f, a) => f(...a)
|
|
2508
|
+
});
|
|
2509
|
+
this._controller.connect(peer);
|
|
2510
|
+
}
|
|
2511
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2512
|
+
} else {
|
|
2513
|
+
log8("rate limited connect", void 0, {
|
|
2514
|
+
F: __dxlog_file9,
|
|
2515
|
+
L: 120,
|
|
2444
2516
|
S: this,
|
|
2445
2517
|
C: (f, a) => f(...a)
|
|
2446
2518
|
});
|
|
2447
|
-
this._controller.connect(peer);
|
|
2448
2519
|
}
|
|
2449
2520
|
}
|
|
2450
2521
|
}
|
|
@@ -2944,8 +3015,8 @@ var SimplePeerTransport = class {
|
|
|
2944
3015
|
return {
|
|
2945
3016
|
bytesSent: stats.transport.bytesSent,
|
|
2946
3017
|
bytesReceived: stats.transport.bytesReceived,
|
|
2947
|
-
packetsSent: stats.transport.
|
|
2948
|
-
packetsReceived: stats.transport.
|
|
3018
|
+
packetsSent: stats.transport.packetsSent,
|
|
3019
|
+
packetsReceived: stats.transport.packetsReceived,
|
|
2949
3020
|
rawStats: stats.raw
|
|
2950
3021
|
};
|
|
2951
3022
|
}
|
|
@@ -2978,8 +3049,8 @@ var SimplePeerTransport = class {
|
|
|
2978
3049
|
if (!rc) {
|
|
2979
3050
|
return "unavailable";
|
|
2980
3051
|
}
|
|
2981
|
-
if (rc.relay) {
|
|
2982
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} relay for
|
|
3052
|
+
if (rc.candidateType === "relay") {
|
|
3053
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
2983
3054
|
}
|
|
2984
3055
|
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
2985
3056
|
}
|
|
@@ -2993,14 +3064,13 @@ var SimplePeerTransport = class {
|
|
|
2993
3064
|
if (this._closed) {
|
|
2994
3065
|
return;
|
|
2995
3066
|
}
|
|
2996
|
-
this._closed = true;
|
|
2997
3067
|
this._disconnectStreams();
|
|
2998
3068
|
this._peer.destroy();
|
|
2999
3069
|
this._closed = true;
|
|
3000
3070
|
this.closed.emit();
|
|
3001
3071
|
log11("closed", void 0, {
|
|
3002
3072
|
F: __dxlog_file12,
|
|
3003
|
-
L:
|
|
3073
|
+
L: 200,
|
|
3004
3074
|
S: this,
|
|
3005
3075
|
C: (f, a) => f(...a)
|
|
3006
3076
|
});
|
|
@@ -3448,17 +3518,24 @@ var LibDataChannelTransport = class {
|
|
|
3448
3518
|
this._readyForCandidates = new Trigger2();
|
|
3449
3519
|
this._writeCallback = null;
|
|
3450
3520
|
this._peer = (async () => {
|
|
3451
|
-
const { RTCPeerConnection
|
|
3521
|
+
const { RTCPeerConnection } = (await importESM("node-datachannel/polyfill")).default;
|
|
3452
3522
|
if (this._closed) {
|
|
3453
3523
|
this.errors.raise(new Error("connection already closed"));
|
|
3454
3524
|
}
|
|
3455
|
-
|
|
3525
|
+
if (params.webrtcConfig) {
|
|
3526
|
+
params.webrtcConfig.iceServers = params.webrtcConfig.iceServers ?? [];
|
|
3527
|
+
} else {
|
|
3528
|
+
params.webrtcConfig = {
|
|
3529
|
+
iceServers: []
|
|
3530
|
+
};
|
|
3531
|
+
}
|
|
3532
|
+
const peer = new RTCPeerConnection(params.webrtcConfig);
|
|
3456
3533
|
peer.onicecandidateerror = (event) => {
|
|
3457
3534
|
log14.error("peer.onicecandidateerror", {
|
|
3458
3535
|
event
|
|
3459
3536
|
}, {
|
|
3460
3537
|
F: __dxlog_file15,
|
|
3461
|
-
L:
|
|
3538
|
+
L: 61,
|
|
3462
3539
|
S: this,
|
|
3463
3540
|
C: (f, a) => f(...a)
|
|
3464
3541
|
});
|
|
@@ -3470,7 +3547,7 @@ var LibDataChannelTransport = class {
|
|
|
3470
3547
|
transportConnectionState: this._connected
|
|
3471
3548
|
}, {
|
|
3472
3549
|
F: __dxlog_file15,
|
|
3473
|
-
L:
|
|
3550
|
+
L: 65,
|
|
3474
3551
|
S: this,
|
|
3475
3552
|
C: (f, a) => f(...a)
|
|
3476
3553
|
});
|
|
@@ -3480,7 +3557,7 @@ var LibDataChannelTransport = class {
|
|
|
3480
3557
|
event
|
|
3481
3558
|
}, {
|
|
3482
3559
|
F: __dxlog_file15,
|
|
3483
|
-
L:
|
|
3560
|
+
L: 74,
|
|
3484
3561
|
S: this,
|
|
3485
3562
|
C: (f, a) => f(...a)
|
|
3486
3563
|
});
|
|
@@ -3504,7 +3581,7 @@ var LibDataChannelTransport = class {
|
|
|
3504
3581
|
err
|
|
3505
3582
|
}, {
|
|
3506
3583
|
F: __dxlog_file15,
|
|
3507
|
-
L:
|
|
3584
|
+
L: 91,
|
|
3508
3585
|
S: this,
|
|
3509
3586
|
C: (f, a) => f(...a)
|
|
3510
3587
|
});
|
|
@@ -3513,12 +3590,15 @@ var LibDataChannelTransport = class {
|
|
|
3513
3590
|
};
|
|
3514
3591
|
if (params.initiator) {
|
|
3515
3592
|
peer.createOffer().then(async (offer) => {
|
|
3593
|
+
if (this._closed) {
|
|
3594
|
+
return;
|
|
3595
|
+
}
|
|
3516
3596
|
if (peer.connectionState !== "connecting") {
|
|
3517
3597
|
log14.error("i am initiator but peer not in state connecting", {
|
|
3518
3598
|
peer
|
|
3519
3599
|
}, {
|
|
3520
3600
|
F: __dxlog_file15,
|
|
3521
|
-
L:
|
|
3601
|
+
L: 104,
|
|
3522
3602
|
S: this,
|
|
3523
3603
|
C: (f, a) => f(...a)
|
|
3524
3604
|
});
|
|
@@ -3528,7 +3608,7 @@ var LibDataChannelTransport = class {
|
|
|
3528
3608
|
offer
|
|
3529
3609
|
}, {
|
|
3530
3610
|
F: __dxlog_file15,
|
|
3531
|
-
L:
|
|
3611
|
+
L: 107,
|
|
3532
3612
|
S: this,
|
|
3533
3613
|
C: (f, a) => f(...a)
|
|
3534
3614
|
});
|
|
@@ -3548,7 +3628,7 @@ var LibDataChannelTransport = class {
|
|
|
3548
3628
|
this.handleChannel(peer.createDataChannel(DATACHANNEL_LABEL));
|
|
3549
3629
|
log14.debug("created data channel", void 0, {
|
|
3550
3630
|
F: __dxlog_file15,
|
|
3551
|
-
L:
|
|
3631
|
+
L: 116,
|
|
3552
3632
|
S: this,
|
|
3553
3633
|
C: (f, a) => f(...a)
|
|
3554
3634
|
});
|
|
@@ -3561,7 +3641,7 @@ var LibDataChannelTransport = class {
|
|
|
3561
3641
|
event
|
|
3562
3642
|
}, {
|
|
3563
3643
|
F: __dxlog_file15,
|
|
3564
|
-
L:
|
|
3644
|
+
L: 122,
|
|
3565
3645
|
S: this,
|
|
3566
3646
|
C: (f, a) => f(...a)
|
|
3567
3647
|
});
|
|
@@ -3579,7 +3659,7 @@ var LibDataChannelTransport = class {
|
|
|
3579
3659
|
this._channel.onopen = () => {
|
|
3580
3660
|
log14.debug("dataChannel.onopen", void 0, {
|
|
3581
3661
|
F: __dxlog_file15,
|
|
3582
|
-
L:
|
|
3662
|
+
L: 138,
|
|
3583
3663
|
S: this,
|
|
3584
3664
|
C: (f, a) => f(...a)
|
|
3585
3665
|
});
|
|
@@ -3600,7 +3680,7 @@ var LibDataChannelTransport = class {
|
|
|
3600
3680
|
if (this._writeCallback !== null) {
|
|
3601
3681
|
log14.error("consumer trying to write before we're ready for more data", void 0, {
|
|
3602
3682
|
F: __dxlog_file15,
|
|
3603
|
-
L:
|
|
3683
|
+
L: 155,
|
|
3604
3684
|
S: this,
|
|
3605
3685
|
C: (f, a) => f(...a)
|
|
3606
3686
|
});
|
|
@@ -3625,7 +3705,7 @@ var LibDataChannelTransport = class {
|
|
|
3625
3705
|
err
|
|
3626
3706
|
}, {
|
|
3627
3707
|
F: __dxlog_file15,
|
|
3628
|
-
L:
|
|
3708
|
+
L: 175,
|
|
3629
3709
|
S: this,
|
|
3630
3710
|
C: (f, a) => f(...a)
|
|
3631
3711
|
});
|
|
@@ -3634,7 +3714,7 @@ var LibDataChannelTransport = class {
|
|
|
3634
3714
|
this._channel.onmessage = (event) => {
|
|
3635
3715
|
let data = event.data;
|
|
3636
3716
|
if (data instanceof ArrayBuffer) {
|
|
3637
|
-
data =
|
|
3717
|
+
data = Buffer2.from(data);
|
|
3638
3718
|
}
|
|
3639
3719
|
this._stream.push(data);
|
|
3640
3720
|
};
|
|
@@ -3649,6 +3729,12 @@ var LibDataChannelTransport = class {
|
|
|
3649
3729
|
return;
|
|
3650
3730
|
}
|
|
3651
3731
|
await this._disconnectStreams();
|
|
3732
|
+
const peer = await this._peer;
|
|
3733
|
+
try {
|
|
3734
|
+
peer.close();
|
|
3735
|
+
} catch (err) {
|
|
3736
|
+
this.errors.raise(err);
|
|
3737
|
+
}
|
|
3652
3738
|
this._closed = true;
|
|
3653
3739
|
this.closed.emit();
|
|
3654
3740
|
}
|
|
@@ -3662,7 +3748,7 @@ var LibDataChannelTransport = class {
|
|
|
3662
3748
|
peer
|
|
3663
3749
|
}, {
|
|
3664
3750
|
F: __dxlog_file15,
|
|
3665
|
-
L:
|
|
3751
|
+
L: 216,
|
|
3666
3752
|
S: this,
|
|
3667
3753
|
C: (f, a) => f(...a)
|
|
3668
3754
|
});
|
|
@@ -3690,7 +3776,7 @@ var LibDataChannelTransport = class {
|
|
|
3690
3776
|
err
|
|
3691
3777
|
}, {
|
|
3692
3778
|
F: __dxlog_file15,
|
|
3693
|
-
L:
|
|
3779
|
+
L: 227,
|
|
3694
3780
|
S: this,
|
|
3695
3781
|
C: (f, a) => f(...a)
|
|
3696
3782
|
});
|
|
@@ -3710,7 +3796,7 @@ var LibDataChannelTransport = class {
|
|
|
3710
3796
|
err
|
|
3711
3797
|
}, {
|
|
3712
3798
|
F: __dxlog_file15,
|
|
3713
|
-
L:
|
|
3799
|
+
L: 238,
|
|
3714
3800
|
S: this,
|
|
3715
3801
|
C: (f, a) => f(...a)
|
|
3716
3802
|
});
|
|
@@ -3729,7 +3815,7 @@ var LibDataChannelTransport = class {
|
|
|
3729
3815
|
signal
|
|
3730
3816
|
}, {
|
|
3731
3817
|
F: __dxlog_file15,
|
|
3732
|
-
L:
|
|
3818
|
+
L: 249,
|
|
3733
3819
|
S: this,
|
|
3734
3820
|
C: (f, a) => f(...a)
|
|
3735
3821
|
});
|
|
@@ -3738,51 +3824,61 @@ var LibDataChannelTransport = class {
|
|
|
3738
3824
|
}).catch((err) => {
|
|
3739
3825
|
log14.catch(err, void 0, {
|
|
3740
3826
|
F: __dxlog_file15,
|
|
3741
|
-
L:
|
|
3827
|
+
L: 254,
|
|
3742
3828
|
S: this,
|
|
3743
3829
|
C: (f, a) => f(...a)
|
|
3744
3830
|
});
|
|
3745
3831
|
});
|
|
3746
3832
|
}
|
|
3747
3833
|
async getDetails() {
|
|
3834
|
+
const stats = await this._getStats();
|
|
3835
|
+
const rc = stats?.remoteCandidate;
|
|
3836
|
+
if (!rc) {
|
|
3837
|
+
return "unavailable";
|
|
3838
|
+
}
|
|
3839
|
+
if (rc.candidateType === "relay") {
|
|
3840
|
+
return `${rc.ip}:${rc.port} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3841
|
+
}
|
|
3842
|
+
return `${rc.ip}:${rc.port} ${rc.candidateType}`;
|
|
3843
|
+
}
|
|
3844
|
+
async _getStats() {
|
|
3748
3845
|
return this._peer.then(async (peer) => {
|
|
3749
|
-
const
|
|
3750
|
-
|
|
3751
|
-
|
|
3846
|
+
const stats = await peer.getStats();
|
|
3847
|
+
const statsEntries = Array.from(stats.entries());
|
|
3848
|
+
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
3849
|
+
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
3850
|
+
let selectedCandidatePair;
|
|
3851
|
+
let remoteCandidate;
|
|
3852
|
+
if (candidatePair.length > 0) {
|
|
3853
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
3854
|
+
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
3752
3855
|
}
|
|
3753
|
-
return
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
C: (f, a) => f(...a)
|
|
3760
|
-
});
|
|
3761
|
-
return "unavailable";
|
|
3856
|
+
return {
|
|
3857
|
+
transport,
|
|
3858
|
+
selectedCandidatePair,
|
|
3859
|
+
remoteCandidate,
|
|
3860
|
+
raw: Object.fromEntries(stats)
|
|
3861
|
+
};
|
|
3762
3862
|
});
|
|
3763
3863
|
}
|
|
3764
3864
|
async getStats() {
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
bytesSent: peer.bytesSent(),
|
|
3768
|
-
bytesReceived: peer.bytesReceived(),
|
|
3769
|
-
packetsSent: 0,
|
|
3770
|
-
packetsReceived: 0
|
|
3771
|
-
};
|
|
3772
|
-
}).catch((err) => {
|
|
3773
|
-
log14.catch(err, void 0, {
|
|
3774
|
-
F: __dxlog_file15,
|
|
3775
|
-
L: 266,
|
|
3776
|
-
S: this,
|
|
3777
|
-
C: (f, a) => f(...a)
|
|
3778
|
-
});
|
|
3865
|
+
const stats = await this._getStats();
|
|
3866
|
+
if (!stats) {
|
|
3779
3867
|
return {
|
|
3780
3868
|
bytesSent: 0,
|
|
3781
3869
|
bytesReceived: 0,
|
|
3782
3870
|
packetsSent: 0,
|
|
3783
|
-
packetsReceived: 0
|
|
3871
|
+
packetsReceived: 0,
|
|
3872
|
+
rawStats: {}
|
|
3784
3873
|
};
|
|
3785
|
-
}
|
|
3874
|
+
}
|
|
3875
|
+
return {
|
|
3876
|
+
bytesSent: stats.transport.bytesSent,
|
|
3877
|
+
bytesReceived: stats.transport.bytesReceived,
|
|
3878
|
+
packetsSent: 0,
|
|
3879
|
+
packetsReceived: 0,
|
|
3880
|
+
rawStats: stats.raw
|
|
3881
|
+
};
|
|
3786
3882
|
}
|
|
3787
3883
|
// TODO(nf): add classmethod to call node-datachannel.cleanup() when all instances have been destroyed?
|
|
3788
3884
|
async destroy() {
|
|
@@ -3801,6 +3897,7 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
|
|
|
3801
3897
|
webrtcConfig
|
|
3802
3898
|
})
|
|
3803
3899
|
});
|
|
3900
|
+
var importESM = Function("path", "return import(path)");
|
|
3804
3901
|
|
|
3805
3902
|
// packages/core/mesh/network-manager/src/transport/tcp-transport.browser.ts
|
|
3806
3903
|
import { Event as Event11 } from "@dxos/async";
|
|
@@ -3850,6 +3947,7 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
3850
3947
|
};
|
|
3851
3948
|
|
|
3852
3949
|
export {
|
|
3950
|
+
process,
|
|
3853
3951
|
ConnectionState,
|
|
3854
3952
|
Connection,
|
|
3855
3953
|
SwarmMessenger,
|
|
@@ -3877,4 +3975,4 @@ export {
|
|
|
3877
3975
|
TcpTransport,
|
|
3878
3976
|
createTeleportProtocolFactory
|
|
3879
3977
|
};
|
|
3880
|
-
//# sourceMappingURL=chunk-
|
|
3978
|
+
//# sourceMappingURL=chunk-6B4JGIV2.mjs.map
|