@dxos/network-manager 0.3.9-main.320ebac → 0.3.9-main.35264cb
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-S2JHWVGQ.mjs → chunk-XF474R3E.mjs} +183 -82
- package/dist/lib/browser/chunk-XF474R3E.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-3SCPMSHV.cjs → chunk-Y2B5BDRH.cjs} +179 -84
- 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 +3 -0
- 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.test.ts +0 -4
- package/src/transport/libdatachannel-transport.ts +76 -34
- package/src/transport/simplepeer-transport.ts +7 -5
- package/dist/lib/browser/chunk-S2JHWVGQ.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-3SCPMSHV.cjs.map +0 -7
- package/dist/lib/node/chunk-DMWORJG3.cjs +0 -471
- package/dist/lib/node/chunk-DMWORJG3.cjs.map +0 -7
- package/dist/lib/node/datachannel-ABYQKZRC.cjs +0 -35
- package/dist/lib/node/datachannel-ABYQKZRC.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 -359
- package/src/transport/datachannel/rtc-session-description.ts +0 -23
|
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_Y2B5BDRH_exports = {};
|
|
30
|
+
__export(chunk_Y2B5BDRH_exports, {
|
|
31
31
|
Connection: () => Connection,
|
|
32
32
|
ConnectionLimiter: () => ConnectionLimiter,
|
|
33
33
|
ConnectionLog: () => ConnectionLog,
|
|
@@ -55,8 +55,7 @@ __export(chunk_3SCPMSHV_exports, {
|
|
|
55
55
|
createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
|
|
56
56
|
createTeleportProtocolFactory: () => createTeleportProtocolFactory
|
|
57
57
|
});
|
|
58
|
-
module.exports = __toCommonJS(
|
|
59
|
-
var import_chunk_DMWORJG3 = require("./chunk-DMWORJG3.cjs");
|
|
58
|
+
module.exports = __toCommonJS(chunk_Y2B5BDRH_exports);
|
|
60
59
|
var import_async = require("@dxos/async");
|
|
61
60
|
var import_context = require("@dxos/context");
|
|
62
61
|
var import_debug = require("@dxos/debug");
|
|
@@ -153,6 +152,13 @@ var import_async12 = require("@dxos/async");
|
|
|
153
152
|
var import_debug8 = require("@dxos/debug");
|
|
154
153
|
var import_log15 = require("@dxos/log");
|
|
155
154
|
var import_teleport = require("@dxos/teleport");
|
|
155
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
156
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
157
|
+
}) : x)(function(x) {
|
|
158
|
+
if (typeof require !== "undefined")
|
|
159
|
+
return require.apply(this, arguments);
|
|
160
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
161
|
+
});
|
|
156
162
|
function _ts_decorate(decorators, target, key, desc) {
|
|
157
163
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
158
164
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -2415,9 +2421,12 @@ var FullyConnectedTopology = class {
|
|
|
2415
2421
|
}
|
|
2416
2422
|
};
|
|
2417
2423
|
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2424
|
+
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2425
|
+
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2418
2426
|
var MMSTTopology = class {
|
|
2419
2427
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2420
2428
|
this._sampleCollected = false;
|
|
2429
|
+
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2421
2430
|
this._originateConnections = originateConnections;
|
|
2422
2431
|
this._maxPeers = maxPeers;
|
|
2423
2432
|
this._sampleSize = sampleSize;
|
|
@@ -2425,7 +2434,7 @@ var MMSTTopology = class {
|
|
|
2425
2434
|
init(controller) {
|
|
2426
2435
|
(0, import_invariant8.invariant)(!this._controller, "Already initialized", {
|
|
2427
2436
|
F: __dxlog_file9,
|
|
2428
|
-
L:
|
|
2437
|
+
L: 51,
|
|
2429
2438
|
S: this,
|
|
2430
2439
|
A: [
|
|
2431
2440
|
"!this._controller",
|
|
@@ -2437,7 +2446,7 @@ var MMSTTopology = class {
|
|
|
2437
2446
|
update() {
|
|
2438
2447
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2439
2448
|
F: __dxlog_file9,
|
|
2440
|
-
L:
|
|
2449
|
+
L: 56,
|
|
2441
2450
|
S: this,
|
|
2442
2451
|
A: [
|
|
2443
2452
|
"this._controller",
|
|
@@ -2448,7 +2457,7 @@ var MMSTTopology = class {
|
|
|
2448
2457
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2449
2458
|
(0, import_log8.log)("Running the algorithm.", void 0, {
|
|
2450
2459
|
F: __dxlog_file9,
|
|
2451
|
-
L:
|
|
2460
|
+
L: 60,
|
|
2452
2461
|
S: this,
|
|
2453
2462
|
C: (f, a) => f(...a)
|
|
2454
2463
|
});
|
|
@@ -2459,7 +2468,7 @@ var MMSTTopology = class {
|
|
|
2459
2468
|
async onOffer(peer) {
|
|
2460
2469
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2461
2470
|
F: __dxlog_file9,
|
|
2462
|
-
L:
|
|
2471
|
+
L: 67,
|
|
2463
2472
|
S: this,
|
|
2464
2473
|
A: [
|
|
2465
2474
|
"this._controller",
|
|
@@ -2470,7 +2479,7 @@ var MMSTTopology = class {
|
|
|
2470
2479
|
const accept = connected.length < this._maxPeers;
|
|
2471
2480
|
(0, import_log8.log)(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2472
2481
|
F: __dxlog_file9,
|
|
2473
|
-
L:
|
|
2482
|
+
L: 70,
|
|
2474
2483
|
S: this,
|
|
2475
2484
|
C: (f, a) => f(...a)
|
|
2476
2485
|
});
|
|
@@ -2481,7 +2490,7 @@ var MMSTTopology = class {
|
|
|
2481
2490
|
_runAlgorithm() {
|
|
2482
2491
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2483
2492
|
F: __dxlog_file9,
|
|
2484
|
-
L:
|
|
2493
|
+
L: 79,
|
|
2485
2494
|
S: this,
|
|
2486
2495
|
A: [
|
|
2487
2496
|
"this._controller",
|
|
@@ -2490,27 +2499,84 @@ var MMSTTopology = class {
|
|
|
2490
2499
|
});
|
|
2491
2500
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2492
2501
|
if (connected.length > this._maxPeers) {
|
|
2502
|
+
(0, import_log8.log)(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2503
|
+
F: __dxlog_file9,
|
|
2504
|
+
L: 85,
|
|
2505
|
+
S: this,
|
|
2506
|
+
C: (f, a) => f(...a)
|
|
2507
|
+
});
|
|
2493
2508
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2494
|
-
|
|
2495
|
-
|
|
2509
|
+
(0, import_invariant8.invariant)(sorted.length === 0, void 0, {
|
|
2510
|
+
F: __dxlog_file9,
|
|
2511
|
+
L: 89,
|
|
2512
|
+
S: this,
|
|
2513
|
+
A: [
|
|
2514
|
+
"sorted.length === 0",
|
|
2515
|
+
""
|
|
2516
|
+
]
|
|
2517
|
+
});
|
|
2518
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2519
|
+
(0, import_log8.log)(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2520
|
+
F: __dxlog_file9,
|
|
2521
|
+
L: 92,
|
|
2522
|
+
S: this,
|
|
2523
|
+
C: (f, a) => f(...a)
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2527
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2528
|
+
(0, import_log8.log)(`Disconnect ${peer}.`, void 0, {
|
|
2529
|
+
F: __dxlog_file9,
|
|
2530
|
+
L: 97,
|
|
2531
|
+
S: this,
|
|
2532
|
+
C: (f, a) => f(...a)
|
|
2533
|
+
});
|
|
2534
|
+
this._controller.disconnect(peer);
|
|
2535
|
+
}
|
|
2536
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2537
|
+
} else {
|
|
2538
|
+
(0, import_log8.log)("rate limited discconnect", void 0, {
|
|
2496
2539
|
F: __dxlog_file9,
|
|
2497
|
-
L:
|
|
2540
|
+
L: 102,
|
|
2498
2541
|
S: this,
|
|
2499
2542
|
C: (f, a) => f(...a)
|
|
2500
2543
|
});
|
|
2501
|
-
this._controller.disconnect(peer);
|
|
2502
2544
|
}
|
|
2503
2545
|
} else if (connected.length < this._originateConnections) {
|
|
2546
|
+
(0, import_log8.log)(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2547
|
+
F: __dxlog_file9,
|
|
2548
|
+
L: 106,
|
|
2549
|
+
S: this,
|
|
2550
|
+
C: (f, a) => f(...a)
|
|
2551
|
+
});
|
|
2504
2552
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2505
2553
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2506
|
-
|
|
2507
|
-
(0, import_log8.log)(`
|
|
2554
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2555
|
+
(0, import_log8.log)(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2508
2556
|
F: __dxlog_file9,
|
|
2509
|
-
L:
|
|
2557
|
+
L: 111,
|
|
2558
|
+
S: this,
|
|
2559
|
+
C: (f, a) => f(...a)
|
|
2560
|
+
});
|
|
2561
|
+
}
|
|
2562
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2563
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2564
|
+
(0, import_log8.log)(`Connect ${peer}.`, void 0, {
|
|
2565
|
+
F: __dxlog_file9,
|
|
2566
|
+
L: 115,
|
|
2567
|
+
S: this,
|
|
2568
|
+
C: (f, a) => f(...a)
|
|
2569
|
+
});
|
|
2570
|
+
this._controller.connect(peer);
|
|
2571
|
+
}
|
|
2572
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2573
|
+
} else {
|
|
2574
|
+
(0, import_log8.log)("rate limited connect", void 0, {
|
|
2575
|
+
F: __dxlog_file9,
|
|
2576
|
+
L: 120,
|
|
2510
2577
|
S: this,
|
|
2511
2578
|
C: (f, a) => f(...a)
|
|
2512
2579
|
});
|
|
2513
|
-
this._controller.connect(peer);
|
|
2514
2580
|
}
|
|
2515
2581
|
}
|
|
2516
2582
|
}
|
|
@@ -2811,11 +2877,14 @@ var TransportKind;
|
|
|
2811
2877
|
})(TransportKind || (TransportKind = {}));
|
|
2812
2878
|
var wrtc = null;
|
|
2813
2879
|
try {
|
|
2814
|
-
wrtc =
|
|
2880
|
+
wrtc = __require("@koush/wrtc");
|
|
2815
2881
|
} catch {
|
|
2816
2882
|
}
|
|
2817
2883
|
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
|
|
2818
2884
|
var SimplePeerTransport = class {
|
|
2885
|
+
/**
|
|
2886
|
+
* @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
|
|
2887
|
+
*/
|
|
2819
2888
|
constructor(params) {
|
|
2820
2889
|
this.params = params;
|
|
2821
2890
|
this._closed = false;
|
|
@@ -2828,13 +2897,13 @@ var SimplePeerTransport = class {
|
|
|
2828
2897
|
id: this._instanceId
|
|
2829
2898
|
}), {
|
|
2830
2899
|
F: __dxlog_file12,
|
|
2831
|
-
L:
|
|
2900
|
+
L: 44,
|
|
2832
2901
|
S: this,
|
|
2833
2902
|
C: (f, a) => f(...a)
|
|
2834
2903
|
});
|
|
2835
2904
|
(0, import_log11.log)("created connection", params, {
|
|
2836
2905
|
F: __dxlog_file12,
|
|
2837
|
-
L:
|
|
2906
|
+
L: 45,
|
|
2838
2907
|
S: this,
|
|
2839
2908
|
C: (f, a) => f(...a)
|
|
2840
2909
|
});
|
|
@@ -2847,7 +2916,7 @@ var SimplePeerTransport = class {
|
|
|
2847
2916
|
this._peer.on("signal", async (data) => {
|
|
2848
2917
|
(0, import_log11.log)("signal", data, {
|
|
2849
2918
|
F: __dxlog_file12,
|
|
2850
|
-
L:
|
|
2919
|
+
L: 54,
|
|
2851
2920
|
S: this,
|
|
2852
2921
|
C: (f, a) => f(...a)
|
|
2853
2922
|
});
|
|
@@ -2860,7 +2929,7 @@ var SimplePeerTransport = class {
|
|
|
2860
2929
|
this._peer.on("connect", () => {
|
|
2861
2930
|
(0, import_log11.log)("connected", void 0, {
|
|
2862
2931
|
F: __dxlog_file12,
|
|
2863
|
-
L:
|
|
2932
|
+
L: 59,
|
|
2864
2933
|
S: this,
|
|
2865
2934
|
C: (f, a) => f(...a)
|
|
2866
2935
|
});
|
|
@@ -2871,7 +2940,7 @@ var SimplePeerTransport = class {
|
|
|
2871
2940
|
this._peer.on("close", async () => {
|
|
2872
2941
|
(0, import_log11.log)("closed", void 0, {
|
|
2873
2942
|
F: __dxlog_file12,
|
|
2874
|
-
L:
|
|
2943
|
+
L: 66,
|
|
2875
2944
|
S: this,
|
|
2876
2945
|
C: (f, a) => f(...a)
|
|
2877
2946
|
});
|
|
@@ -2886,7 +2955,7 @@ var SimplePeerTransport = class {
|
|
|
2886
2955
|
err
|
|
2887
2956
|
}, {
|
|
2888
2957
|
F: __dxlog_file12,
|
|
2889
|
-
L:
|
|
2958
|
+
L: 77,
|
|
2890
2959
|
S: this,
|
|
2891
2960
|
C: (f, a) => f(...a)
|
|
2892
2961
|
});
|
|
@@ -2895,7 +2964,7 @@ var SimplePeerTransport = class {
|
|
|
2895
2964
|
} else if ("code" in err) {
|
|
2896
2965
|
import_log11.log.info("simple-peer error", err, {
|
|
2897
2966
|
F: __dxlog_file12,
|
|
2898
|
-
L:
|
|
2967
|
+
L: 82,
|
|
2899
2968
|
S: this,
|
|
2900
2969
|
C: (f, a) => f(...a)
|
|
2901
2970
|
});
|
|
@@ -2925,7 +2994,7 @@ var SimplePeerTransport = class {
|
|
|
2925
2994
|
} else {
|
|
2926
2995
|
import_log11.log.info("unknown peer connection error", err, {
|
|
2927
2996
|
F: __dxlog_file12,
|
|
2928
|
-
L:
|
|
2997
|
+
L: 108,
|
|
2929
2998
|
S: this,
|
|
2930
2999
|
C: (f, a) => f(...a)
|
|
2931
3000
|
});
|
|
@@ -2939,7 +3008,7 @@ var SimplePeerTransport = class {
|
|
|
2939
3008
|
stats: Object.fromEntries(stats.entries())
|
|
2940
3009
|
}, {
|
|
2941
3010
|
F: __dxlog_file12,
|
|
2942
|
-
L:
|
|
3011
|
+
L: 116,
|
|
2943
3012
|
S: this,
|
|
2944
3013
|
C: (f, a) => f(...a)
|
|
2945
3014
|
});
|
|
@@ -2948,7 +3017,7 @@ var SimplePeerTransport = class {
|
|
|
2948
3017
|
} catch (err2) {
|
|
2949
3018
|
import_log11.log.catch(err2, void 0, {
|
|
2950
3019
|
F: __dxlog_file12,
|
|
2951
|
-
L:
|
|
3020
|
+
L: 123,
|
|
2952
3021
|
S: this,
|
|
2953
3022
|
C: (f, a) => f(...a)
|
|
2954
3023
|
});
|
|
@@ -2959,7 +3028,7 @@ var SimplePeerTransport = class {
|
|
|
2959
3028
|
id: this._instanceId
|
|
2960
3029
|
}), {
|
|
2961
3030
|
F: __dxlog_file12,
|
|
2962
|
-
L:
|
|
3031
|
+
L: 129,
|
|
2963
3032
|
S: this,
|
|
2964
3033
|
C: (f, a) => f(...a)
|
|
2965
3034
|
});
|
|
@@ -2978,8 +3047,8 @@ var SimplePeerTransport = class {
|
|
|
2978
3047
|
return {
|
|
2979
3048
|
bytesSent: stats.transport.bytesSent,
|
|
2980
3049
|
bytesReceived: stats.transport.bytesReceived,
|
|
2981
|
-
packetsSent: stats.transport.
|
|
2982
|
-
packetsReceived: stats.transport.
|
|
3050
|
+
packetsSent: stats.transport.packetsSent,
|
|
3051
|
+
packetsReceived: stats.transport.packetsReceived,
|
|
2983
3052
|
rawStats: stats.raw
|
|
2984
3053
|
};
|
|
2985
3054
|
}
|
|
@@ -3012,29 +3081,28 @@ var SimplePeerTransport = class {
|
|
|
3012
3081
|
if (!rc) {
|
|
3013
3082
|
return "unavailable";
|
|
3014
3083
|
}
|
|
3015
|
-
if (rc.relay) {
|
|
3016
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} relay for
|
|
3084
|
+
if (rc.candidateType === "relay") {
|
|
3085
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3017
3086
|
}
|
|
3018
3087
|
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3019
3088
|
}
|
|
3020
3089
|
async destroy() {
|
|
3021
3090
|
(0, import_log11.log)("closing...", void 0, {
|
|
3022
3091
|
F: __dxlog_file12,
|
|
3023
|
-
L:
|
|
3092
|
+
L: 192,
|
|
3024
3093
|
S: this,
|
|
3025
3094
|
C: (f, a) => f(...a)
|
|
3026
3095
|
});
|
|
3027
3096
|
if (this._closed) {
|
|
3028
3097
|
return;
|
|
3029
3098
|
}
|
|
3030
|
-
this._closed = true;
|
|
3031
3099
|
this._disconnectStreams();
|
|
3032
3100
|
this._peer.destroy();
|
|
3033
3101
|
this._closed = true;
|
|
3034
3102
|
this.closed.emit();
|
|
3035
3103
|
(0, import_log11.log)("closed", void 0, {
|
|
3036
3104
|
F: __dxlog_file12,
|
|
3037
|
-
L:
|
|
3105
|
+
L: 200,
|
|
3038
3106
|
S: this,
|
|
3039
3107
|
C: (f, a) => f(...a)
|
|
3040
3108
|
});
|
|
@@ -3455,17 +3523,24 @@ var LibDataChannelTransport = class {
|
|
|
3455
3523
|
this._readyForCandidates = new import_async11.Trigger();
|
|
3456
3524
|
this._writeCallback = null;
|
|
3457
3525
|
this._peer = (async () => {
|
|
3458
|
-
const { RTCPeerConnection
|
|
3526
|
+
const { RTCPeerConnection } = (await importESM("node-datachannel/polyfill")).default;
|
|
3459
3527
|
if (this._closed) {
|
|
3460
3528
|
this.errors.raise(new Error("connection already closed"));
|
|
3461
3529
|
}
|
|
3462
|
-
|
|
3530
|
+
if (params.webrtcConfig) {
|
|
3531
|
+
params.webrtcConfig.iceServers = params.webrtcConfig.iceServers ?? [];
|
|
3532
|
+
} else {
|
|
3533
|
+
params.webrtcConfig = {
|
|
3534
|
+
iceServers: []
|
|
3535
|
+
};
|
|
3536
|
+
}
|
|
3537
|
+
const peer = new RTCPeerConnection(params.webrtcConfig);
|
|
3463
3538
|
peer.onicecandidateerror = (event) => {
|
|
3464
3539
|
import_log14.log.error("peer.onicecandidateerror", {
|
|
3465
3540
|
event
|
|
3466
3541
|
}, {
|
|
3467
3542
|
F: __dxlog_file15,
|
|
3468
|
-
L:
|
|
3543
|
+
L: 61,
|
|
3469
3544
|
S: this,
|
|
3470
3545
|
C: (f, a) => f(...a)
|
|
3471
3546
|
});
|
|
@@ -3477,7 +3552,7 @@ var LibDataChannelTransport = class {
|
|
|
3477
3552
|
transportConnectionState: this._connected
|
|
3478
3553
|
}, {
|
|
3479
3554
|
F: __dxlog_file15,
|
|
3480
|
-
L:
|
|
3555
|
+
L: 65,
|
|
3481
3556
|
S: this,
|
|
3482
3557
|
C: (f, a) => f(...a)
|
|
3483
3558
|
});
|
|
@@ -3487,7 +3562,7 @@ var LibDataChannelTransport = class {
|
|
|
3487
3562
|
event
|
|
3488
3563
|
}, {
|
|
3489
3564
|
F: __dxlog_file15,
|
|
3490
|
-
L:
|
|
3565
|
+
L: 74,
|
|
3491
3566
|
S: this,
|
|
3492
3567
|
C: (f, a) => f(...a)
|
|
3493
3568
|
});
|
|
@@ -3511,7 +3586,7 @@ var LibDataChannelTransport = class {
|
|
|
3511
3586
|
err
|
|
3512
3587
|
}, {
|
|
3513
3588
|
F: __dxlog_file15,
|
|
3514
|
-
L:
|
|
3589
|
+
L: 91,
|
|
3515
3590
|
S: this,
|
|
3516
3591
|
C: (f, a) => f(...a)
|
|
3517
3592
|
});
|
|
@@ -3520,12 +3595,15 @@ var LibDataChannelTransport = class {
|
|
|
3520
3595
|
};
|
|
3521
3596
|
if (params.initiator) {
|
|
3522
3597
|
peer.createOffer().then(async (offer) => {
|
|
3598
|
+
if (this._closed) {
|
|
3599
|
+
return;
|
|
3600
|
+
}
|
|
3523
3601
|
if (peer.connectionState !== "connecting") {
|
|
3524
3602
|
import_log14.log.error("i am initiator but peer not in state connecting", {
|
|
3525
3603
|
peer
|
|
3526
3604
|
}, {
|
|
3527
3605
|
F: __dxlog_file15,
|
|
3528
|
-
L:
|
|
3606
|
+
L: 104,
|
|
3529
3607
|
S: this,
|
|
3530
3608
|
C: (f, a) => f(...a)
|
|
3531
3609
|
});
|
|
@@ -3535,7 +3613,7 @@ var LibDataChannelTransport = class {
|
|
|
3535
3613
|
offer
|
|
3536
3614
|
}, {
|
|
3537
3615
|
F: __dxlog_file15,
|
|
3538
|
-
L:
|
|
3616
|
+
L: 107,
|
|
3539
3617
|
S: this,
|
|
3540
3618
|
C: (f, a) => f(...a)
|
|
3541
3619
|
});
|
|
@@ -3555,7 +3633,7 @@ var LibDataChannelTransport = class {
|
|
|
3555
3633
|
this.handleChannel(peer.createDataChannel(DATACHANNEL_LABEL));
|
|
3556
3634
|
import_log14.log.debug("created data channel", void 0, {
|
|
3557
3635
|
F: __dxlog_file15,
|
|
3558
|
-
L:
|
|
3636
|
+
L: 116,
|
|
3559
3637
|
S: this,
|
|
3560
3638
|
C: (f, a) => f(...a)
|
|
3561
3639
|
});
|
|
@@ -3568,7 +3646,7 @@ var LibDataChannelTransport = class {
|
|
|
3568
3646
|
event
|
|
3569
3647
|
}, {
|
|
3570
3648
|
F: __dxlog_file15,
|
|
3571
|
-
L:
|
|
3649
|
+
L: 122,
|
|
3572
3650
|
S: this,
|
|
3573
3651
|
C: (f, a) => f(...a)
|
|
3574
3652
|
});
|
|
@@ -3586,7 +3664,7 @@ var LibDataChannelTransport = class {
|
|
|
3586
3664
|
this._channel.onopen = () => {
|
|
3587
3665
|
import_log14.log.debug("dataChannel.onopen", void 0, {
|
|
3588
3666
|
F: __dxlog_file15,
|
|
3589
|
-
L:
|
|
3667
|
+
L: 138,
|
|
3590
3668
|
S: this,
|
|
3591
3669
|
C: (f, a) => f(...a)
|
|
3592
3670
|
});
|
|
@@ -3607,7 +3685,7 @@ var LibDataChannelTransport = class {
|
|
|
3607
3685
|
if (this._writeCallback !== null) {
|
|
3608
3686
|
import_log14.log.error("consumer trying to write before we're ready for more data", void 0, {
|
|
3609
3687
|
F: __dxlog_file15,
|
|
3610
|
-
L:
|
|
3688
|
+
L: 155,
|
|
3611
3689
|
S: this,
|
|
3612
3690
|
C: (f, a) => f(...a)
|
|
3613
3691
|
});
|
|
@@ -3632,7 +3710,7 @@ var LibDataChannelTransport = class {
|
|
|
3632
3710
|
err
|
|
3633
3711
|
}, {
|
|
3634
3712
|
F: __dxlog_file15,
|
|
3635
|
-
L:
|
|
3713
|
+
L: 175,
|
|
3636
3714
|
S: this,
|
|
3637
3715
|
C: (f, a) => f(...a)
|
|
3638
3716
|
});
|
|
@@ -3656,6 +3734,12 @@ var LibDataChannelTransport = class {
|
|
|
3656
3734
|
return;
|
|
3657
3735
|
}
|
|
3658
3736
|
await this._disconnectStreams();
|
|
3737
|
+
const peer = await this._peer;
|
|
3738
|
+
try {
|
|
3739
|
+
peer.close();
|
|
3740
|
+
} catch (err) {
|
|
3741
|
+
this.errors.raise(err);
|
|
3742
|
+
}
|
|
3659
3743
|
this._closed = true;
|
|
3660
3744
|
this.closed.emit();
|
|
3661
3745
|
}
|
|
@@ -3669,7 +3753,7 @@ var LibDataChannelTransport = class {
|
|
|
3669
3753
|
peer
|
|
3670
3754
|
}, {
|
|
3671
3755
|
F: __dxlog_file15,
|
|
3672
|
-
L:
|
|
3756
|
+
L: 216,
|
|
3673
3757
|
S: this,
|
|
3674
3758
|
C: (f, a) => f(...a)
|
|
3675
3759
|
});
|
|
@@ -3697,7 +3781,7 @@ var LibDataChannelTransport = class {
|
|
|
3697
3781
|
err
|
|
3698
3782
|
}, {
|
|
3699
3783
|
F: __dxlog_file15,
|
|
3700
|
-
L:
|
|
3784
|
+
L: 227,
|
|
3701
3785
|
S: this,
|
|
3702
3786
|
C: (f, a) => f(...a)
|
|
3703
3787
|
});
|
|
@@ -3717,7 +3801,7 @@ var LibDataChannelTransport = class {
|
|
|
3717
3801
|
err
|
|
3718
3802
|
}, {
|
|
3719
3803
|
F: __dxlog_file15,
|
|
3720
|
-
L:
|
|
3804
|
+
L: 238,
|
|
3721
3805
|
S: this,
|
|
3722
3806
|
C: (f, a) => f(...a)
|
|
3723
3807
|
});
|
|
@@ -3736,7 +3820,7 @@ var LibDataChannelTransport = class {
|
|
|
3736
3820
|
signal
|
|
3737
3821
|
}, {
|
|
3738
3822
|
F: __dxlog_file15,
|
|
3739
|
-
L:
|
|
3823
|
+
L: 249,
|
|
3740
3824
|
S: this,
|
|
3741
3825
|
C: (f, a) => f(...a)
|
|
3742
3826
|
});
|
|
@@ -3745,51 +3829,61 @@ var LibDataChannelTransport = class {
|
|
|
3745
3829
|
}).catch((err) => {
|
|
3746
3830
|
import_log14.log.catch(err, void 0, {
|
|
3747
3831
|
F: __dxlog_file15,
|
|
3748
|
-
L:
|
|
3832
|
+
L: 254,
|
|
3749
3833
|
S: this,
|
|
3750
3834
|
C: (f, a) => f(...a)
|
|
3751
3835
|
});
|
|
3752
3836
|
});
|
|
3753
3837
|
}
|
|
3754
3838
|
async getDetails() {
|
|
3839
|
+
const stats = await this._getStats();
|
|
3840
|
+
const rc = stats?.remoteCandidate;
|
|
3841
|
+
if (!rc) {
|
|
3842
|
+
return "unavailable";
|
|
3843
|
+
}
|
|
3844
|
+
if (rc.candidateType === "relay") {
|
|
3845
|
+
return `${rc.ip}:${rc.port} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3846
|
+
}
|
|
3847
|
+
return `${rc.ip}:${rc.port} ${rc.candidateType}`;
|
|
3848
|
+
}
|
|
3849
|
+
async _getStats() {
|
|
3755
3850
|
return this._peer.then(async (peer) => {
|
|
3756
|
-
const
|
|
3757
|
-
|
|
3758
|
-
|
|
3851
|
+
const stats = await peer.getStats();
|
|
3852
|
+
const statsEntries = Array.from(stats.entries());
|
|
3853
|
+
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
3854
|
+
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
3855
|
+
let selectedCandidatePair;
|
|
3856
|
+
let remoteCandidate;
|
|
3857
|
+
if (candidatePair.length > 0) {
|
|
3858
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
3859
|
+
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
3759
3860
|
}
|
|
3760
|
-
return
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
C: (f, a) => f(...a)
|
|
3767
|
-
});
|
|
3768
|
-
return "unavailable";
|
|
3861
|
+
return {
|
|
3862
|
+
transport,
|
|
3863
|
+
selectedCandidatePair,
|
|
3864
|
+
remoteCandidate,
|
|
3865
|
+
raw: Object.fromEntries(stats)
|
|
3866
|
+
};
|
|
3769
3867
|
});
|
|
3770
3868
|
}
|
|
3771
3869
|
async getStats() {
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
bytesSent: peer.bytesSent(),
|
|
3775
|
-
bytesReceived: peer.bytesReceived(),
|
|
3776
|
-
packetsSent: 0,
|
|
3777
|
-
packetsReceived: 0
|
|
3778
|
-
};
|
|
3779
|
-
}).catch((err) => {
|
|
3780
|
-
import_log14.log.catch(err, void 0, {
|
|
3781
|
-
F: __dxlog_file15,
|
|
3782
|
-
L: 266,
|
|
3783
|
-
S: this,
|
|
3784
|
-
C: (f, a) => f(...a)
|
|
3785
|
-
});
|
|
3870
|
+
const stats = await this._getStats();
|
|
3871
|
+
if (!stats) {
|
|
3786
3872
|
return {
|
|
3787
3873
|
bytesSent: 0,
|
|
3788
3874
|
bytesReceived: 0,
|
|
3789
3875
|
packetsSent: 0,
|
|
3790
|
-
packetsReceived: 0
|
|
3876
|
+
packetsReceived: 0,
|
|
3877
|
+
rawStats: {}
|
|
3791
3878
|
};
|
|
3792
|
-
}
|
|
3879
|
+
}
|
|
3880
|
+
return {
|
|
3881
|
+
bytesSent: stats.transport.bytesSent,
|
|
3882
|
+
bytesReceived: stats.transport.bytesReceived,
|
|
3883
|
+
packetsSent: 0,
|
|
3884
|
+
packetsReceived: 0,
|
|
3885
|
+
rawStats: stats.raw
|
|
3886
|
+
};
|
|
3793
3887
|
}
|
|
3794
3888
|
// TODO(nf): add classmethod to call node-datachannel.cleanup() when all instances have been destroyed?
|
|
3795
3889
|
async destroy() {
|
|
@@ -3808,6 +3902,7 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
|
|
|
3808
3902
|
webrtcConfig
|
|
3809
3903
|
})
|
|
3810
3904
|
});
|
|
3905
|
+
var importESM = Function("path", "return import(path)");
|
|
3811
3906
|
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
|
|
3812
3907
|
var TcpTransportFactory = {
|
|
3813
3908
|
createTransport: (params) => new TcpTransport(params)
|
|
@@ -3995,4 +4090,4 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
3995
4090
|
createSimplePeerTransportFactory,
|
|
3996
4091
|
createTeleportProtocolFactory
|
|
3997
4092
|
});
|
|
3998
|
-
//# sourceMappingURL=chunk-
|
|
4093
|
+
//# sourceMappingURL=chunk-Y2B5BDRH.cjs.map
|