@dxos/network-manager 0.4.10-main.ef6fbc2 → 0.4.10-main.f635fb0
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-OIR45T43.mjs → chunk-OSMVZUEK.mjs} +464 -425
- package/dist/lib/browser/chunk-OSMVZUEK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-HUPX2JGP.cjs → chunk-M4CGCR2I.cjs} +480 -440
- package/dist/lib/node/chunk-M4CGCR2I.cjs.map +7 -0
- package/dist/lib/node/index.cjs +27 -27
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -18
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts +20 -19
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts +17 -10
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts +7 -9
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts +9 -11
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts +7 -2
- package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.d.ts +6 -4
- package/dist/types/src/transport/tcp-transport.d.ts.map +1 -1
- package/dist/types/src/transport/transport.d.ts +18 -12
- package/dist/types/src/transport/transport.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/swarm/connection.ts +7 -5
- package/src/swarm/peer.ts +0 -1
- package/src/transport/libdatachannel-transport.test.ts +14 -9
- package/src/transport/libdatachannel-transport.ts +226 -204
- package/src/transport/memory-transport.test.ts +10 -7
- package/src/transport/memory-transport.ts +49 -42
- package/src/transport/simplepeer-transport-proxy-test.ts +13 -8
- package/src/transport/simplepeer-transport-proxy.ts +48 -49
- package/src/transport/simplepeer-transport-service.ts +5 -2
- package/src/transport/simplepeer-transport.test.ts +9 -5
- package/src/transport/simplepeer-transport.ts +25 -25
- package/src/transport/tcp-transport.browser.ts +10 -5
- package/src/transport/tcp-transport.ts +31 -22
- package/src/transport/transport.ts +25 -14
- package/dist/lib/browser/chunk-OIR45T43.mjs.map +0 -7
- package/dist/lib/node/chunk-HUPX2JGP.cjs.map +0 -7
|
@@ -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_M4CGCR2I_exports = {};
|
|
30
|
+
__export(chunk_M4CGCR2I_exports, {
|
|
31
31
|
Connection: () => Connection,
|
|
32
32
|
ConnectionLimiter: () => ConnectionLimiter,
|
|
33
33
|
ConnectionLog: () => ConnectionLog,
|
|
@@ -55,7 +55,7 @@ __export(chunk_HUPX2JGP_exports, {
|
|
|
55
55
|
createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
|
|
56
56
|
createTeleportProtocolFactory: () => createTeleportProtocolFactory
|
|
57
57
|
});
|
|
58
|
-
module.exports = __toCommonJS(
|
|
58
|
+
module.exports = __toCommonJS(chunk_M4CGCR2I_exports);
|
|
59
59
|
var import_async = require("@dxos/async");
|
|
60
60
|
var import_context = require("@dxos/context");
|
|
61
61
|
var import_debug = require("@dxos/debug");
|
|
@@ -146,6 +146,7 @@ var import_util9 = require("@dxos/util");
|
|
|
146
146
|
var import_stream = require("stream");
|
|
147
147
|
var import_async11 = require("@dxos/async");
|
|
148
148
|
var import_debug7 = require("@dxos/debug");
|
|
149
|
+
var import_invariant13 = require("@dxos/invariant");
|
|
149
150
|
var import_log14 = require("@dxos/log");
|
|
150
151
|
var import_node_net = require("node:net");
|
|
151
152
|
var import_async12 = require("@dxos/async");
|
|
@@ -304,6 +305,7 @@ var Connection = class {
|
|
|
304
305
|
sendSignal: async (signal) => this._sendSignal(signal),
|
|
305
306
|
sessionId: this.sessionId
|
|
306
307
|
});
|
|
308
|
+
await this._transport.open();
|
|
307
309
|
this._transport.connected.once(async () => {
|
|
308
310
|
this._changeState("CONNECTED");
|
|
309
311
|
await this.connectedTimeoutContext.dispose();
|
|
@@ -314,7 +316,7 @@ var Connection = class {
|
|
|
314
316
|
this._transport = void 0;
|
|
315
317
|
(0, import_log.log)("abort triggered by transport close", void 0, {
|
|
316
318
|
F: __dxlog_file,
|
|
317
|
-
L:
|
|
319
|
+
L: 218,
|
|
318
320
|
S: this,
|
|
319
321
|
C: (f, a) => f(...a)
|
|
320
322
|
});
|
|
@@ -325,7 +327,7 @@ var Connection = class {
|
|
|
325
327
|
err
|
|
326
328
|
}, {
|
|
327
329
|
F: __dxlog_file,
|
|
328
|
-
L:
|
|
330
|
+
L: 223,
|
|
329
331
|
S: this,
|
|
330
332
|
C: (f, a) => f(...a)
|
|
331
333
|
});
|
|
@@ -335,7 +337,7 @@ var Connection = class {
|
|
|
335
337
|
if (err instanceof import_protocols.ConnectionResetError) {
|
|
336
338
|
import_log.log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
337
339
|
F: __dxlog_file,
|
|
338
|
-
L:
|
|
340
|
+
L: 230,
|
|
339
341
|
S: this,
|
|
340
342
|
C: (f, a) => f(...a)
|
|
341
343
|
});
|
|
@@ -343,7 +345,7 @@ var Connection = class {
|
|
|
343
345
|
} else if (err instanceof import_protocols.ConnectivityError) {
|
|
344
346
|
import_log.log.info("aborting due to transport ConnectivityError", void 0, {
|
|
345
347
|
F: __dxlog_file,
|
|
346
|
-
L:
|
|
348
|
+
L: 233,
|
|
347
349
|
S: this,
|
|
348
350
|
C: (f, a) => f(...a)
|
|
349
351
|
});
|
|
@@ -353,7 +355,7 @@ var Connection = class {
|
|
|
353
355
|
err
|
|
354
356
|
}, {
|
|
355
357
|
F: __dxlog_file,
|
|
356
|
-
L:
|
|
358
|
+
L: 236,
|
|
357
359
|
S: this,
|
|
358
360
|
C: (f, a) => f(...a)
|
|
359
361
|
});
|
|
@@ -364,14 +366,14 @@ var Connection = class {
|
|
|
364
366
|
}
|
|
365
367
|
});
|
|
366
368
|
for (const signal of this._incomingSignalBuffer) {
|
|
367
|
-
void this._transport.
|
|
369
|
+
void this._transport.onSignal(signal);
|
|
368
370
|
}
|
|
369
371
|
this._incomingSignalBuffer = [];
|
|
370
372
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.end({
|
|
371
373
|
id: this._instanceId
|
|
372
374
|
}), {
|
|
373
375
|
F: __dxlog_file,
|
|
374
|
-
L:
|
|
376
|
+
L: 252,
|
|
375
377
|
S: this,
|
|
376
378
|
C: (f, a) => f(...a)
|
|
377
379
|
});
|
|
@@ -381,14 +383,14 @@ var Connection = class {
|
|
|
381
383
|
err
|
|
382
384
|
}, {
|
|
383
385
|
F: __dxlog_file,
|
|
384
|
-
L:
|
|
386
|
+
L: 259,
|
|
385
387
|
S: this,
|
|
386
388
|
C: (f, a) => f(...a)
|
|
387
389
|
});
|
|
388
390
|
if (this._state === "CLOSED" || this._state === "ABORTED") {
|
|
389
391
|
(0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
390
392
|
F: __dxlog_file,
|
|
391
|
-
L:
|
|
393
|
+
L: 261,
|
|
392
394
|
S: this,
|
|
393
395
|
C: (f, a) => f(...a)
|
|
394
396
|
});
|
|
@@ -403,7 +405,7 @@ var Connection = class {
|
|
|
403
405
|
try {
|
|
404
406
|
(0, import_log.log)("aborting protocol... ", void 0, {
|
|
405
407
|
F: __dxlog_file,
|
|
406
|
-
L:
|
|
408
|
+
L: 275,
|
|
407
409
|
S: this,
|
|
408
410
|
C: (f, a) => f(...a)
|
|
409
411
|
});
|
|
@@ -411,17 +413,17 @@ var Connection = class {
|
|
|
411
413
|
} catch (err2) {
|
|
412
414
|
import_log.log.catch(err2, void 0, {
|
|
413
415
|
F: __dxlog_file,
|
|
414
|
-
L:
|
|
416
|
+
L: 278,
|
|
415
417
|
S: this,
|
|
416
418
|
C: (f, a) => f(...a)
|
|
417
419
|
});
|
|
418
420
|
}
|
|
419
421
|
try {
|
|
420
|
-
await this._transport?.
|
|
422
|
+
await this._transport?.close();
|
|
421
423
|
} catch (err2) {
|
|
422
424
|
import_log.log.catch(err2, void 0, {
|
|
423
425
|
F: __dxlog_file,
|
|
424
|
-
L:
|
|
426
|
+
L: 285,
|
|
425
427
|
S: this,
|
|
426
428
|
C: (f, a) => f(...a)
|
|
427
429
|
});
|
|
@@ -431,7 +433,7 @@ var Connection = class {
|
|
|
431
433
|
} catch (err2) {
|
|
432
434
|
import_log.log.catch(err2, void 0, {
|
|
433
435
|
F: __dxlog_file,
|
|
434
|
-
L:
|
|
436
|
+
L: 291,
|
|
435
437
|
S: this,
|
|
436
438
|
C: (f, a) => f(...a)
|
|
437
439
|
});
|
|
@@ -455,7 +457,7 @@ var Connection = class {
|
|
|
455
457
|
peerId: this.ownId
|
|
456
458
|
}, {
|
|
457
459
|
F: __dxlog_file,
|
|
458
|
-
L:
|
|
460
|
+
L: 316,
|
|
459
461
|
S: this,
|
|
460
462
|
C: (f, a) => f(...a)
|
|
461
463
|
});
|
|
@@ -465,17 +467,17 @@ var Connection = class {
|
|
|
465
467
|
} catch (err2) {
|
|
466
468
|
import_log.log.catch(err2, void 0, {
|
|
467
469
|
F: __dxlog_file,
|
|
468
|
-
L:
|
|
470
|
+
L: 323,
|
|
469
471
|
S: this,
|
|
470
472
|
C: (f, a) => f(...a)
|
|
471
473
|
});
|
|
472
474
|
}
|
|
473
475
|
try {
|
|
474
|
-
await this._transport?.
|
|
476
|
+
await this._transport?.close();
|
|
475
477
|
} catch (err2) {
|
|
476
478
|
import_log.log.catch(err2, void 0, {
|
|
477
479
|
F: __dxlog_file,
|
|
478
|
-
L:
|
|
480
|
+
L: 330,
|
|
479
481
|
S: this,
|
|
480
482
|
C: (f, a) => f(...a)
|
|
481
483
|
});
|
|
@@ -483,7 +485,7 @@ var Connection = class {
|
|
|
483
485
|
} else {
|
|
484
486
|
import_log.log.info(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
485
487
|
F: __dxlog_file,
|
|
486
|
-
L:
|
|
488
|
+
L: 333,
|
|
487
489
|
S: this,
|
|
488
490
|
C: (f, a) => f(...a)
|
|
489
491
|
});
|
|
@@ -492,17 +494,17 @@ var Connection = class {
|
|
|
492
494
|
} catch (err2) {
|
|
493
495
|
import_log.log.catch(err2, void 0, {
|
|
494
496
|
F: __dxlog_file,
|
|
495
|
-
L:
|
|
497
|
+
L: 337,
|
|
496
498
|
S: this,
|
|
497
499
|
C: (f, a) => f(...a)
|
|
498
500
|
});
|
|
499
501
|
}
|
|
500
502
|
try {
|
|
501
|
-
await this._transport?.
|
|
503
|
+
await this._transport?.close();
|
|
502
504
|
} catch (err2) {
|
|
503
505
|
import_log.log.catch(err2, void 0, {
|
|
504
506
|
F: __dxlog_file,
|
|
505
|
-
L:
|
|
507
|
+
L: 342,
|
|
506
508
|
S: this,
|
|
507
509
|
C: (f, a) => f(...a)
|
|
508
510
|
});
|
|
@@ -512,7 +514,7 @@ var Connection = class {
|
|
|
512
514
|
peerId: this.ownId
|
|
513
515
|
}, {
|
|
514
516
|
F: __dxlog_file,
|
|
515
|
-
L:
|
|
517
|
+
L: 346,
|
|
516
518
|
S: this,
|
|
517
519
|
C: (f, a) => f(...a)
|
|
518
520
|
});
|
|
@@ -555,7 +557,7 @@ var Connection = class {
|
|
|
555
557
|
err
|
|
556
558
|
}, {
|
|
557
559
|
F: __dxlog_file,
|
|
558
|
-
L:
|
|
560
|
+
L: 384,
|
|
559
561
|
S: this,
|
|
560
562
|
C: (f, a) => f(...a)
|
|
561
563
|
});
|
|
@@ -568,7 +570,7 @@ var Connection = class {
|
|
|
568
570
|
async signal(msg) {
|
|
569
571
|
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
570
572
|
F: __dxlog_file,
|
|
571
|
-
L:
|
|
573
|
+
L: 393,
|
|
572
574
|
S: this,
|
|
573
575
|
A: [
|
|
574
576
|
"msg.sessionId",
|
|
@@ -578,7 +580,7 @@ var Connection = class {
|
|
|
578
580
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
579
581
|
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
580
582
|
F: __dxlog_file,
|
|
581
|
-
L:
|
|
583
|
+
L: 395,
|
|
582
584
|
S: this,
|
|
583
585
|
C: (f, a) => f(...a)
|
|
584
586
|
});
|
|
@@ -586,7 +588,7 @@ var Connection = class {
|
|
|
586
588
|
}
|
|
587
589
|
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
588
590
|
F: __dxlog_file,
|
|
589
|
-
L:
|
|
591
|
+
L: 398,
|
|
590
592
|
S: this,
|
|
591
593
|
A: [
|
|
592
594
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -595,7 +597,7 @@ var Connection = class {
|
|
|
595
597
|
});
|
|
596
598
|
(0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
|
|
597
599
|
F: __dxlog_file,
|
|
598
|
-
L:
|
|
600
|
+
L: 399,
|
|
599
601
|
S: this,
|
|
600
602
|
A: [
|
|
601
603
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -604,7 +606,7 @@ var Connection = class {
|
|
|
604
606
|
});
|
|
605
607
|
(0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
|
|
606
608
|
F: __dxlog_file,
|
|
607
|
-
L:
|
|
609
|
+
L: 400,
|
|
608
610
|
S: this,
|
|
609
611
|
A: [
|
|
610
612
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -628,7 +630,7 @@ var Connection = class {
|
|
|
628
630
|
msg: msg.data
|
|
629
631
|
}, {
|
|
630
632
|
F: __dxlog_file,
|
|
631
|
-
L:
|
|
633
|
+
L: 409,
|
|
632
634
|
S: this,
|
|
633
635
|
C: (f, a) => f(...a)
|
|
634
636
|
});
|
|
@@ -636,7 +638,7 @@ var Connection = class {
|
|
|
636
638
|
} else {
|
|
637
639
|
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
638
640
|
F: __dxlog_file,
|
|
639
|
-
L:
|
|
641
|
+
L: 412,
|
|
640
642
|
S: this,
|
|
641
643
|
A: [
|
|
642
644
|
"this._transport",
|
|
@@ -649,11 +651,11 @@ var Connection = class {
|
|
|
649
651
|
msg: msg.data
|
|
650
652
|
}, {
|
|
651
653
|
F: __dxlog_file,
|
|
652
|
-
L:
|
|
654
|
+
L: 413,
|
|
653
655
|
S: this,
|
|
654
656
|
C: (f, a) => f(...a)
|
|
655
657
|
});
|
|
656
|
-
await this._transport.
|
|
658
|
+
await this._transport.onSignal(signal);
|
|
657
659
|
}
|
|
658
660
|
}
|
|
659
661
|
}
|
|
@@ -667,13 +669,13 @@ var Connection = class {
|
|
|
667
669
|
peerId: this.ownId
|
|
668
670
|
}, {
|
|
669
671
|
F: __dxlog_file,
|
|
670
|
-
L:
|
|
672
|
+
L: 424,
|
|
671
673
|
S: this,
|
|
672
674
|
C: (f, a) => f(...a)
|
|
673
675
|
});
|
|
674
676
|
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
675
677
|
F: __dxlog_file,
|
|
676
|
-
L:
|
|
678
|
+
L: 425,
|
|
677
679
|
S: this,
|
|
678
680
|
A: [
|
|
679
681
|
"state !== this._state",
|
|
@@ -952,7 +954,6 @@ var ConnectionDisplacedError = class extends import_protocols4.SystemError {
|
|
|
952
954
|
};
|
|
953
955
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
954
956
|
var Peer = class {
|
|
955
|
-
// TODO(burdon): Convert to map?
|
|
956
957
|
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
957
958
|
this.id = id;
|
|
958
959
|
this.topic = topic;
|
|
@@ -981,7 +982,7 @@ var Peer = class {
|
|
|
981
982
|
].includes(this.connection.state)) {
|
|
982
983
|
import_log4.log.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
983
984
|
F: __dxlog_file3,
|
|
984
|
-
L:
|
|
985
|
+
L: 114,
|
|
985
986
|
S: this,
|
|
986
987
|
C: (f, a) => f(...a)
|
|
987
988
|
});
|
|
@@ -998,7 +999,7 @@ var Peer = class {
|
|
|
998
999
|
sessionId: this.connection?.sessionId
|
|
999
1000
|
}, {
|
|
1000
1001
|
F: __dxlog_file3,
|
|
1001
|
-
L:
|
|
1002
|
+
L: 123,
|
|
1002
1003
|
S: this,
|
|
1003
1004
|
C: (f, a) => f(...a)
|
|
1004
1005
|
});
|
|
@@ -1015,7 +1016,7 @@ var Peer = class {
|
|
|
1015
1016
|
if (!this.connection) {
|
|
1016
1017
|
(0, import_invariant4.invariant)(message.sessionId, void 0, {
|
|
1017
1018
|
F: __dxlog_file3,
|
|
1018
|
-
L:
|
|
1019
|
+
L: 143,
|
|
1019
1020
|
S: this,
|
|
1020
1021
|
A: [
|
|
1021
1022
|
"message.sessionId",
|
|
@@ -1036,7 +1037,7 @@ var Peer = class {
|
|
|
1036
1037
|
err
|
|
1037
1038
|
}, {
|
|
1038
1039
|
F: __dxlog_file3,
|
|
1039
|
-
L:
|
|
1040
|
+
L: 153,
|
|
1040
1041
|
S: this,
|
|
1041
1042
|
C: (f, a) => f(...a)
|
|
1042
1043
|
});
|
|
@@ -1058,7 +1059,7 @@ var Peer = class {
|
|
|
1058
1059
|
async initiateConnection() {
|
|
1059
1060
|
(0, import_invariant4.invariant)(!this.initiating, "Initiation in progress.", {
|
|
1060
1061
|
F: __dxlog_file3,
|
|
1061
|
-
L:
|
|
1062
|
+
L: 170,
|
|
1062
1063
|
S: this,
|
|
1063
1064
|
A: [
|
|
1064
1065
|
"!this.initiating",
|
|
@@ -1067,7 +1068,7 @@ var Peer = class {
|
|
|
1067
1068
|
});
|
|
1068
1069
|
(0, import_invariant4.invariant)(!this.connection, "Already connected.", {
|
|
1069
1070
|
F: __dxlog_file3,
|
|
1070
|
-
L:
|
|
1071
|
+
L: 171,
|
|
1071
1072
|
S: this,
|
|
1072
1073
|
A: [
|
|
1073
1074
|
"!this.connection",
|
|
@@ -1082,7 +1083,7 @@ var Peer = class {
|
|
|
1082
1083
|
sessionId
|
|
1083
1084
|
}, {
|
|
1084
1085
|
F: __dxlog_file3,
|
|
1085
|
-
L:
|
|
1086
|
+
L: 173,
|
|
1086
1087
|
S: this,
|
|
1087
1088
|
C: (f, a) => f(...a)
|
|
1088
1089
|
});
|
|
@@ -1108,14 +1109,14 @@ var Peer = class {
|
|
|
1108
1109
|
remoteId: this.id
|
|
1109
1110
|
}, {
|
|
1110
1111
|
F: __dxlog_file3,
|
|
1111
|
-
L:
|
|
1112
|
+
L: 190,
|
|
1112
1113
|
S: this,
|
|
1113
1114
|
C: (f, a) => f(...a)
|
|
1114
1115
|
});
|
|
1115
1116
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1116
1117
|
(0, import_log4.log)("ignoring response", void 0, {
|
|
1117
1118
|
F: __dxlog_file3,
|
|
1118
|
-
L:
|
|
1119
|
+
L: 192,
|
|
1119
1120
|
S: this,
|
|
1120
1121
|
C: (f, a) => f(...a)
|
|
1121
1122
|
});
|
|
@@ -1129,7 +1130,7 @@ var Peer = class {
|
|
|
1129
1130
|
remoteId: this.id
|
|
1130
1131
|
}, {
|
|
1131
1132
|
F: __dxlog_file3,
|
|
1132
|
-
L:
|
|
1133
|
+
L: 196,
|
|
1133
1134
|
S: this,
|
|
1134
1135
|
C: (f, a) => f(...a)
|
|
1135
1136
|
});
|
|
@@ -1151,7 +1152,7 @@ var Peer = class {
|
|
|
1151
1152
|
remoteId: this.id
|
|
1152
1153
|
}, {
|
|
1153
1154
|
F: __dxlog_file3,
|
|
1154
|
-
L:
|
|
1155
|
+
L: 209,
|
|
1155
1156
|
S: this,
|
|
1156
1157
|
C: (f, a) => f(...a)
|
|
1157
1158
|
});
|
|
@@ -1163,7 +1164,7 @@ var Peer = class {
|
|
|
1163
1164
|
try {
|
|
1164
1165
|
(0, import_log4.log)("opening connection as initiator", void 0, {
|
|
1165
1166
|
F: __dxlog_file3,
|
|
1166
|
-
L:
|
|
1167
|
+
L: 222,
|
|
1167
1168
|
S: this,
|
|
1168
1169
|
C: (f, a) => f(...a)
|
|
1169
1170
|
});
|
|
@@ -1177,7 +1178,7 @@ var Peer = class {
|
|
|
1177
1178
|
remoteId: this.id
|
|
1178
1179
|
}, {
|
|
1179
1180
|
F: __dxlog_file3,
|
|
1180
|
-
L:
|
|
1181
|
+
L: 226,
|
|
1181
1182
|
S: this,
|
|
1182
1183
|
C: (f, a) => f(...a)
|
|
1183
1184
|
});
|
|
@@ -1185,7 +1186,7 @@ var Peer = class {
|
|
|
1185
1186
|
err
|
|
1186
1187
|
}, {
|
|
1187
1188
|
F: __dxlog_file3,
|
|
1188
|
-
L:
|
|
1189
|
+
L: 233,
|
|
1189
1190
|
S: this,
|
|
1190
1191
|
C: (f, a) => f(...a)
|
|
1191
1192
|
});
|
|
@@ -1208,13 +1209,13 @@ var Peer = class {
|
|
|
1208
1209
|
sessionId
|
|
1209
1210
|
}, {
|
|
1210
1211
|
F: __dxlog_file3,
|
|
1211
|
-
L:
|
|
1212
|
+
L: 247,
|
|
1212
1213
|
S: this,
|
|
1213
1214
|
C: (f, a) => f(...a)
|
|
1214
1215
|
});
|
|
1215
1216
|
(0, import_invariant4.invariant)(!this.connection, "Already connected.", {
|
|
1216
1217
|
F: __dxlog_file3,
|
|
1217
|
-
L:
|
|
1218
|
+
L: 254,
|
|
1218
1219
|
S: this,
|
|
1219
1220
|
A: [
|
|
1220
1221
|
"!this.connection",
|
|
@@ -1250,7 +1251,7 @@ var Peer = class {
|
|
|
1250
1251
|
initiator
|
|
1251
1252
|
}, {
|
|
1252
1253
|
F: __dxlog_file3,
|
|
1253
|
-
L:
|
|
1254
|
+
L: 273,
|
|
1254
1255
|
S: this,
|
|
1255
1256
|
C: (f, a) => f(...a)
|
|
1256
1257
|
});
|
|
@@ -1263,14 +1264,14 @@ var Peer = class {
|
|
|
1263
1264
|
initiator
|
|
1264
1265
|
}, {
|
|
1265
1266
|
F: __dxlog_file3,
|
|
1266
|
-
L:
|
|
1267
|
+
L: 282,
|
|
1267
1268
|
S: this,
|
|
1268
1269
|
C: (f, a) => f(...a)
|
|
1269
1270
|
});
|
|
1270
1271
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1271
1272
|
(0, import_invariant4.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1272
1273
|
F: __dxlog_file3,
|
|
1273
|
-
L:
|
|
1274
|
+
L: 287,
|
|
1274
1275
|
S: this,
|
|
1275
1276
|
A: [
|
|
1276
1277
|
"this.connection === connection",
|
|
@@ -1285,7 +1286,7 @@ var Peer = class {
|
|
|
1285
1286
|
initiator
|
|
1286
1287
|
}, {
|
|
1287
1288
|
F: __dxlog_file3,
|
|
1288
|
-
L:
|
|
1289
|
+
L: 289,
|
|
1289
1290
|
S: this,
|
|
1290
1291
|
C: (f, a) => f(...a)
|
|
1291
1292
|
});
|
|
@@ -1320,7 +1321,7 @@ var Peer = class {
|
|
|
1320
1321
|
err
|
|
1321
1322
|
}, {
|
|
1322
1323
|
F: __dxlog_file3,
|
|
1323
|
-
L:
|
|
1324
|
+
L: 329,
|
|
1324
1325
|
S: this,
|
|
1325
1326
|
C: (f, a) => f(...a)
|
|
1326
1327
|
});
|
|
@@ -1333,7 +1334,7 @@ var Peer = class {
|
|
|
1333
1334
|
err
|
|
1334
1335
|
}, {
|
|
1335
1336
|
F: __dxlog_file3,
|
|
1336
|
-
L:
|
|
1337
|
+
L: 336,
|
|
1337
1338
|
S: this,
|
|
1338
1339
|
C: (f, a) => f(...a)
|
|
1339
1340
|
});
|
|
@@ -1352,7 +1353,7 @@ var Peer = class {
|
|
|
1352
1353
|
sessionId: connection.sessionId
|
|
1353
1354
|
}, {
|
|
1354
1355
|
F: __dxlog_file3,
|
|
1355
|
-
L:
|
|
1356
|
+
L: 361,
|
|
1356
1357
|
S: this,
|
|
1357
1358
|
C: (f, a) => f(...a)
|
|
1358
1359
|
});
|
|
@@ -1362,7 +1363,7 @@ var Peer = class {
|
|
|
1362
1363
|
sessionId: connection.sessionId
|
|
1363
1364
|
}, {
|
|
1364
1365
|
F: __dxlog_file3,
|
|
1365
|
-
L:
|
|
1366
|
+
L: 367,
|
|
1366
1367
|
S: this,
|
|
1367
1368
|
C: (f, a) => f(...a)
|
|
1368
1369
|
});
|
|
@@ -1373,7 +1374,7 @@ var Peer = class {
|
|
|
1373
1374
|
message
|
|
1374
1375
|
}, {
|
|
1375
1376
|
F: __dxlog_file3,
|
|
1376
|
-
L:
|
|
1377
|
+
L: 372,
|
|
1377
1378
|
S: this,
|
|
1378
1379
|
C: (f, a) => f(...a)
|
|
1379
1380
|
});
|
|
@@ -1388,7 +1389,7 @@ var Peer = class {
|
|
|
1388
1389
|
topic: this.topic
|
|
1389
1390
|
}, {
|
|
1390
1391
|
F: __dxlog_file3,
|
|
1391
|
-
L:
|
|
1392
|
+
L: 382,
|
|
1392
1393
|
S: this,
|
|
1393
1394
|
C: (f, a) => f(...a)
|
|
1394
1395
|
});
|
|
@@ -2667,31 +2668,25 @@ var createStreamDelay = (delay) => {
|
|
|
2667
2668
|
});
|
|
2668
2669
|
};
|
|
2669
2670
|
var MemoryTransportFactory = {
|
|
2670
|
-
createTransport: (
|
|
2671
|
+
createTransport: (options) => new MemoryTransport(options)
|
|
2671
2672
|
};
|
|
2672
2673
|
var MemoryTransport = class _MemoryTransport {
|
|
2673
2674
|
static {
|
|
2674
2675
|
this._connections = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
|
|
2675
2676
|
}
|
|
2676
|
-
constructor(
|
|
2677
|
-
this.
|
|
2678
|
-
this.closed = new import_async8.Event();
|
|
2679
|
-
this.connected = new import_async8.Event();
|
|
2680
|
-
this.errors = new import_debug4.ErrorStream();
|
|
2677
|
+
constructor(_options) {
|
|
2678
|
+
this._options = _options;
|
|
2681
2679
|
this._instanceId = import_keys9.PublicKey.random();
|
|
2682
2680
|
this._remote = new import_async8.Trigger();
|
|
2683
2681
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2684
2682
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2685
|
-
this.
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
S: this,
|
|
2690
|
-
C: (f, a) => f(...a)
|
|
2691
|
-
});
|
|
2683
|
+
this._closed = false;
|
|
2684
|
+
this.closed = new import_async8.Event();
|
|
2685
|
+
this.connected = new import_async8.Event();
|
|
2686
|
+
this.errors = new import_debug4.ErrorStream();
|
|
2692
2687
|
(0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2693
2688
|
F: __dxlog_file11,
|
|
2694
|
-
L:
|
|
2689
|
+
L: 64,
|
|
2695
2690
|
S: this,
|
|
2696
2691
|
A: [
|
|
2697
2692
|
"!MemoryTransport._connections.has(this._instanceId)",
|
|
@@ -2699,41 +2694,52 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2699
2694
|
]
|
|
2700
2695
|
});
|
|
2701
2696
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2697
|
+
}
|
|
2698
|
+
get isOpen() {
|
|
2699
|
+
return !this._closed;
|
|
2700
|
+
}
|
|
2701
|
+
async open() {
|
|
2702
|
+
(0, import_log10.log)("opening...", void 0, {
|
|
2703
|
+
F: __dxlog_file11,
|
|
2704
|
+
L: 74,
|
|
2705
|
+
S: this,
|
|
2706
|
+
C: (f, a) => f(...a)
|
|
2707
|
+
});
|
|
2708
|
+
if (this._options.initiator) {
|
|
2709
|
+
(0, import_log10.log)("sending signal", void 0, {
|
|
2710
|
+
F: __dxlog_file11,
|
|
2711
|
+
L: 78,
|
|
2712
|
+
S: this,
|
|
2713
|
+
C: (f, a) => f(...a)
|
|
2714
|
+
});
|
|
2715
|
+
try {
|
|
2716
|
+
await this._options.sendSignal({
|
|
2711
2717
|
payload: {
|
|
2712
2718
|
transportId: this._instanceId.toHex()
|
|
2713
2719
|
}
|
|
2714
|
-
}).catch((err) => {
|
|
2715
|
-
if (!this._destroyed) {
|
|
2716
|
-
this.errors.raise(err);
|
|
2717
|
-
}
|
|
2718
2720
|
});
|
|
2719
|
-
})
|
|
2721
|
+
} catch (err) {
|
|
2722
|
+
if (!this._closed) {
|
|
2723
|
+
this.errors.raise(toError(err));
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2720
2726
|
} else {
|
|
2721
2727
|
this._remote.wait({
|
|
2722
|
-
timeout: this.
|
|
2728
|
+
timeout: this._options.timeout ?? 1e3
|
|
2723
2729
|
}).then((remoteId) => {
|
|
2724
|
-
if (this.
|
|
2730
|
+
if (this._closed) {
|
|
2725
2731
|
return;
|
|
2726
2732
|
}
|
|
2727
2733
|
this._remoteInstanceId = remoteId;
|
|
2728
2734
|
this._remoteConnection = _MemoryTransport._connections.get(this._remoteInstanceId);
|
|
2729
2735
|
if (!this._remoteConnection) {
|
|
2730
|
-
this.
|
|
2736
|
+
this._closed = true;
|
|
2731
2737
|
this.closed.emit();
|
|
2732
2738
|
return;
|
|
2733
2739
|
}
|
|
2734
2740
|
(0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2735
2741
|
F: __dxlog_file11,
|
|
2736
|
-
L:
|
|
2742
|
+
L: 104,
|
|
2737
2743
|
S: this,
|
|
2738
2744
|
A: [
|
|
2739
2745
|
"!this._remoteConnection._remoteConnection",
|
|
@@ -2744,68 +2750,56 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2744
2750
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
2745
2751
|
(0, import_log10.log)("connected", void 0, {
|
|
2746
2752
|
F: __dxlog_file11,
|
|
2747
|
-
L:
|
|
2753
|
+
L: 108,
|
|
2748
2754
|
S: this,
|
|
2749
2755
|
C: (f, a) => f(...a)
|
|
2750
2756
|
});
|
|
2751
|
-
this.
|
|
2757
|
+
this._options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection._options.stream).pipe(this._incomingDelay).pipe(this._options.stream);
|
|
2752
2758
|
this.connected.emit();
|
|
2753
2759
|
this._remoteConnection.connected.emit();
|
|
2754
2760
|
}).catch((err) => {
|
|
2755
|
-
if (this.
|
|
2761
|
+
if (this._closed) {
|
|
2756
2762
|
return;
|
|
2757
2763
|
}
|
|
2758
2764
|
this.errors.raise(err);
|
|
2759
2765
|
});
|
|
2760
2766
|
}
|
|
2761
2767
|
}
|
|
2762
|
-
async
|
|
2763
|
-
(0, import_log10.log)("closing", void 0, {
|
|
2768
|
+
async close() {
|
|
2769
|
+
(0, import_log10.log)("closing...", void 0, {
|
|
2764
2770
|
F: __dxlog_file11,
|
|
2765
|
-
L:
|
|
2771
|
+
L: 129,
|
|
2766
2772
|
S: this,
|
|
2767
2773
|
C: (f, a) => f(...a)
|
|
2768
2774
|
});
|
|
2769
|
-
this.
|
|
2775
|
+
this._closed = true;
|
|
2770
2776
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
2771
2777
|
if (this._remoteConnection) {
|
|
2772
|
-
|
|
2773
|
-
F: __dxlog_file11,
|
|
2774
|
-
L: 129,
|
|
2775
|
-
S: this,
|
|
2776
|
-
C: (f, a) => f(...a)
|
|
2777
|
-
});
|
|
2778
|
-
this._remoteConnection._destroyed = true;
|
|
2778
|
+
this._remoteConnection._closed = true;
|
|
2779
2779
|
_MemoryTransport._connections.delete(this._remoteInstanceId);
|
|
2780
|
-
this.
|
|
2781
|
-
this._incomingDelay.unpipe(this._remoteConnection.
|
|
2782
|
-
this._remoteConnection.
|
|
2783
|
-
this._outgoingDelay.unpipe(this.
|
|
2784
|
-
this.
|
|
2780
|
+
this._options.stream.unpipe(this._incomingDelay);
|
|
2781
|
+
this._incomingDelay.unpipe(this._remoteConnection._options.stream);
|
|
2782
|
+
this._remoteConnection._options.stream.unpipe(this._outgoingDelay);
|
|
2783
|
+
this._outgoingDelay.unpipe(this._options.stream);
|
|
2784
|
+
this._options.stream.unpipe(this._outgoingDelay);
|
|
2785
2785
|
this._remoteConnection.closed.emit();
|
|
2786
2786
|
this._remoteConnection._remoteConnection = void 0;
|
|
2787
2787
|
this._remoteConnection = void 0;
|
|
2788
|
-
(0, import_log10.log)("closed", void 0, {
|
|
2789
|
-
F: __dxlog_file11,
|
|
2790
|
-
L: 150,
|
|
2791
|
-
S: this,
|
|
2792
|
-
C: (f, a) => f(...a)
|
|
2793
|
-
});
|
|
2794
2788
|
}
|
|
2795
2789
|
this.closed.emit();
|
|
2796
2790
|
(0, import_log10.log)("closed", void 0, {
|
|
2797
2791
|
F: __dxlog_file11,
|
|
2798
|
-
L:
|
|
2792
|
+
L: 157,
|
|
2799
2793
|
S: this,
|
|
2800
2794
|
C: (f, a) => f(...a)
|
|
2801
2795
|
});
|
|
2802
2796
|
}
|
|
2803
|
-
|
|
2797
|
+
async onSignal({ payload }) {
|
|
2804
2798
|
(0, import_log10.log)("received signal", {
|
|
2805
2799
|
payload
|
|
2806
2800
|
}, {
|
|
2807
2801
|
F: __dxlog_file11,
|
|
2808
|
-
L:
|
|
2802
|
+
L: 161,
|
|
2809
2803
|
S: this,
|
|
2810
2804
|
C: (f, a) => f(...a)
|
|
2811
2805
|
});
|
|
@@ -2836,11 +2830,12 @@ _ts_decorate4([
|
|
|
2836
2830
|
_ts_decorate4([
|
|
2837
2831
|
import_log10.logInfo
|
|
2838
2832
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
2833
|
+
var toError = (err) => err instanceof Error ? err : new Error(String(err));
|
|
2839
2834
|
var TransportKind;
|
|
2840
2835
|
(function(TransportKind2) {
|
|
2841
2836
|
TransportKind2["SIMPLE_PEER"] = "SIMPLE_PEER";
|
|
2842
|
-
TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
|
|
2843
2837
|
TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
|
|
2838
|
+
TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
|
|
2844
2839
|
TransportKind2["MEMORY"] = "MEMORY";
|
|
2845
2840
|
TransportKind2["TCP"] = "TCP";
|
|
2846
2841
|
})(TransportKind || (TransportKind = {}));
|
|
@@ -2850,12 +2845,21 @@ try {
|
|
|
2850
2845
|
} catch {
|
|
2851
2846
|
}
|
|
2852
2847
|
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
|
|
2848
|
+
var createSimplePeerTransportFactory = (webrtcConfig) => ({
|
|
2849
|
+
createTransport: (options) => new SimplePeerTransport({
|
|
2850
|
+
...options,
|
|
2851
|
+
webrtcConfig
|
|
2852
|
+
})
|
|
2853
|
+
});
|
|
2853
2854
|
var SimplePeerTransport = class {
|
|
2855
|
+
get isOpen() {
|
|
2856
|
+
return this._piped && !this._closed;
|
|
2857
|
+
}
|
|
2854
2858
|
/**
|
|
2855
2859
|
* @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
|
|
2856
2860
|
*/
|
|
2857
|
-
constructor(
|
|
2858
|
-
this.
|
|
2861
|
+
constructor(_params) {
|
|
2862
|
+
this._params = _params;
|
|
2859
2863
|
this._closed = false;
|
|
2860
2864
|
this._piped = false;
|
|
2861
2865
|
this.closed = new import_async9.Event();
|
|
@@ -2866,30 +2870,30 @@ var SimplePeerTransport = class {
|
|
|
2866
2870
|
id: this._instanceId
|
|
2867
2871
|
}), {
|
|
2868
2872
|
F: __dxlog_file12,
|
|
2869
|
-
L:
|
|
2873
|
+
L: 50,
|
|
2870
2874
|
S: this,
|
|
2871
2875
|
C: (f, a) => f(...a)
|
|
2872
2876
|
});
|
|
2873
|
-
(0, import_log11.log)("created connection",
|
|
2877
|
+
(0, import_log11.log)("created connection", _params, {
|
|
2874
2878
|
F: __dxlog_file12,
|
|
2875
|
-
L:
|
|
2879
|
+
L: 51,
|
|
2876
2880
|
S: this,
|
|
2877
2881
|
C: (f, a) => f(...a)
|
|
2878
2882
|
});
|
|
2879
2883
|
this._peer = new import_simple_peer.default({
|
|
2880
2884
|
channelName: "dxos.mesh.transport",
|
|
2881
|
-
initiator: this.
|
|
2885
|
+
initiator: this._params.initiator,
|
|
2882
2886
|
wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : wrtc ?? (0, import_debug5.raise)(new Error("wrtc not available")),
|
|
2883
|
-
config: this.
|
|
2887
|
+
config: this._params.webrtcConfig
|
|
2884
2888
|
});
|
|
2885
2889
|
this._peer.on("signal", async (data) => {
|
|
2886
2890
|
(0, import_log11.log)("signal", data, {
|
|
2887
2891
|
F: __dxlog_file12,
|
|
2888
|
-
L:
|
|
2892
|
+
L: 60,
|
|
2889
2893
|
S: this,
|
|
2890
2894
|
C: (f, a) => f(...a)
|
|
2891
2895
|
});
|
|
2892
|
-
await this.
|
|
2896
|
+
await this._params.sendSignal({
|
|
2893
2897
|
payload: {
|
|
2894
2898
|
data
|
|
2895
2899
|
}
|
|
@@ -2898,22 +2902,22 @@ var SimplePeerTransport = class {
|
|
|
2898
2902
|
this._peer.on("connect", () => {
|
|
2899
2903
|
(0, import_log11.log)("connected", void 0, {
|
|
2900
2904
|
F: __dxlog_file12,
|
|
2901
|
-
L:
|
|
2905
|
+
L: 65,
|
|
2902
2906
|
S: this,
|
|
2903
2907
|
C: (f, a) => f(...a)
|
|
2904
2908
|
});
|
|
2905
|
-
this.
|
|
2909
|
+
this._params.stream.pipe(this._peer).pipe(this._params.stream);
|
|
2906
2910
|
this._piped = true;
|
|
2907
2911
|
this.connected.emit();
|
|
2908
2912
|
});
|
|
2909
2913
|
this._peer.on("close", async () => {
|
|
2910
2914
|
(0, import_log11.log)("closed", void 0, {
|
|
2911
2915
|
F: __dxlog_file12,
|
|
2912
|
-
L:
|
|
2916
|
+
L: 72,
|
|
2913
2917
|
S: this,
|
|
2914
2918
|
C: (f, a) => f(...a)
|
|
2915
2919
|
});
|
|
2916
|
-
await this.
|
|
2920
|
+
await this.close();
|
|
2917
2921
|
});
|
|
2918
2922
|
this._peer.on("error", async (err) => {
|
|
2919
2923
|
if (typeof RTCError !== "undefined" && err instanceof RTCError) {
|
|
@@ -2924,7 +2928,7 @@ var SimplePeerTransport = class {
|
|
|
2924
2928
|
err
|
|
2925
2929
|
}, {
|
|
2926
2930
|
F: __dxlog_file12,
|
|
2927
|
-
L:
|
|
2931
|
+
L: 83,
|
|
2928
2932
|
S: this,
|
|
2929
2933
|
C: (f, a) => f(...a)
|
|
2930
2934
|
});
|
|
@@ -2933,7 +2937,7 @@ var SimplePeerTransport = class {
|
|
|
2933
2937
|
} else if ("code" in err) {
|
|
2934
2938
|
import_log11.log.info("simple-peer error", err, {
|
|
2935
2939
|
F: __dxlog_file12,
|
|
2936
|
-
L:
|
|
2940
|
+
L: 88,
|
|
2937
2941
|
S: this,
|
|
2938
2942
|
C: (f, a) => f(...a)
|
|
2939
2943
|
});
|
|
@@ -2963,7 +2967,7 @@ var SimplePeerTransport = class {
|
|
|
2963
2967
|
} else {
|
|
2964
2968
|
import_log11.log.info("unknown peer connection error", err, {
|
|
2965
2969
|
F: __dxlog_file12,
|
|
2966
|
-
L:
|
|
2970
|
+
L: 114,
|
|
2967
2971
|
S: this,
|
|
2968
2972
|
C: (f, a) => f(...a)
|
|
2969
2973
|
});
|
|
@@ -2973,11 +2977,11 @@ var SimplePeerTransport = class {
|
|
|
2973
2977
|
if (typeof this._peer?._pc?.getStats === "function") {
|
|
2974
2978
|
this._peer._pc.getStats().then((stats) => {
|
|
2975
2979
|
import_log11.log.info("report after webrtc error", {
|
|
2976
|
-
config: this.
|
|
2980
|
+
config: this._params.webrtcConfig,
|
|
2977
2981
|
stats: Object.fromEntries(stats.entries())
|
|
2978
2982
|
}, {
|
|
2979
2983
|
F: __dxlog_file12,
|
|
2980
|
-
L:
|
|
2984
|
+
L: 122,
|
|
2981
2985
|
S: this,
|
|
2982
2986
|
C: (f, a) => f(...a)
|
|
2983
2987
|
});
|
|
@@ -2986,18 +2990,18 @@ var SimplePeerTransport = class {
|
|
|
2986
2990
|
} catch (err2) {
|
|
2987
2991
|
import_log11.log.catch(err2, void 0, {
|
|
2988
2992
|
F: __dxlog_file12,
|
|
2989
|
-
L:
|
|
2993
|
+
L: 129,
|
|
2990
2994
|
S: this,
|
|
2991
2995
|
C: (f, a) => f(...a)
|
|
2992
2996
|
});
|
|
2993
2997
|
}
|
|
2994
|
-
await this.
|
|
2998
|
+
await this.close();
|
|
2995
2999
|
});
|
|
2996
3000
|
import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.end({
|
|
2997
3001
|
id: this._instanceId
|
|
2998
3002
|
}), {
|
|
2999
3003
|
F: __dxlog_file12,
|
|
3000
|
-
L:
|
|
3004
|
+
L: 135,
|
|
3001
3005
|
S: this,
|
|
3002
3006
|
C: (f, a) => f(...a)
|
|
3003
3007
|
});
|
|
@@ -3055,10 +3059,12 @@ var SimplePeerTransport = class {
|
|
|
3055
3059
|
}
|
|
3056
3060
|
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3057
3061
|
}
|
|
3058
|
-
async
|
|
3062
|
+
async open() {
|
|
3063
|
+
}
|
|
3064
|
+
async close() {
|
|
3059
3065
|
(0, import_log11.log)("closing...", void 0, {
|
|
3060
3066
|
F: __dxlog_file12,
|
|
3061
|
-
L:
|
|
3067
|
+
L: 200,
|
|
3062
3068
|
S: this,
|
|
3063
3069
|
C: (f, a) => f(...a)
|
|
3064
3070
|
});
|
|
@@ -3071,12 +3077,12 @@ var SimplePeerTransport = class {
|
|
|
3071
3077
|
this.closed.emit();
|
|
3072
3078
|
(0, import_log11.log)("closed", void 0, {
|
|
3073
3079
|
F: __dxlog_file12,
|
|
3074
|
-
L:
|
|
3080
|
+
L: 208,
|
|
3075
3081
|
S: this,
|
|
3076
3082
|
C: (f, a) => f(...a)
|
|
3077
3083
|
});
|
|
3078
3084
|
}
|
|
3079
|
-
|
|
3085
|
+
async onSignal(signal) {
|
|
3080
3086
|
if (this._closed) {
|
|
3081
3087
|
return;
|
|
3082
3088
|
}
|
|
@@ -3085,16 +3091,10 @@ var SimplePeerTransport = class {
|
|
|
3085
3091
|
}
|
|
3086
3092
|
_disconnectStreams() {
|
|
3087
3093
|
if (this._piped) {
|
|
3088
|
-
this.
|
|
3094
|
+
this._params.stream.unpipe?.(this._peer)?.unpipe?.(this._params.stream);
|
|
3089
3095
|
}
|
|
3090
3096
|
}
|
|
3091
3097
|
};
|
|
3092
|
-
var createSimplePeerTransportFactory = (webrtcConfig) => ({
|
|
3093
|
-
createTransport: (params) => new SimplePeerTransport({
|
|
3094
|
-
...params,
|
|
3095
|
-
webrtcConfig
|
|
3096
|
-
})
|
|
3097
|
-
});
|
|
3098
3098
|
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
|
|
3099
3099
|
var SimplePeerTransportService = class {
|
|
3100
3100
|
constructor(_webrtcConfig) {
|
|
@@ -3134,6 +3134,7 @@ var SimplePeerTransportService = class {
|
|
|
3134
3134
|
});
|
|
3135
3135
|
}
|
|
3136
3136
|
});
|
|
3137
|
+
void transport.open();
|
|
3137
3138
|
next({
|
|
3138
3139
|
connection: {
|
|
3139
3140
|
state: import_bridge.ConnectionState.CONNECTING
|
|
@@ -3177,19 +3178,19 @@ var SimplePeerTransportService = class {
|
|
|
3177
3178
|
async sendSignal({ proxyId, signal }) {
|
|
3178
3179
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3179
3180
|
F: __dxlog_file13,
|
|
3180
|
-
L:
|
|
3181
|
+
L: 119,
|
|
3181
3182
|
S: this,
|
|
3182
3183
|
A: [
|
|
3183
3184
|
"this.transports.has(proxyId)",
|
|
3184
3185
|
""
|
|
3185
3186
|
]
|
|
3186
3187
|
});
|
|
3187
|
-
await this.transports.get(proxyId).transport.
|
|
3188
|
+
await this.transports.get(proxyId).transport.onSignal(signal);
|
|
3188
3189
|
}
|
|
3189
3190
|
async getDetails({ proxyId }) {
|
|
3190
3191
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3191
3192
|
F: __dxlog_file13,
|
|
3192
|
-
L:
|
|
3193
|
+
L: 124,
|
|
3193
3194
|
S: this,
|
|
3194
3195
|
A: [
|
|
3195
3196
|
"this.transports.has(proxyId)",
|
|
@@ -3203,7 +3204,7 @@ var SimplePeerTransportService = class {
|
|
|
3203
3204
|
async getStats({ proxyId }) {
|
|
3204
3205
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3205
3206
|
F: __dxlog_file13,
|
|
3206
|
-
L:
|
|
3207
|
+
L: 129,
|
|
3207
3208
|
S: this,
|
|
3208
3209
|
A: [
|
|
3209
3210
|
"this.transports.has(proxyId)",
|
|
@@ -3218,14 +3219,14 @@ var SimplePeerTransportService = class {
|
|
|
3218
3219
|
if (this.transports.get(proxyId)?.state !== "OPEN") {
|
|
3219
3220
|
import_log12.log.debug("transport is closed", void 0, {
|
|
3220
3221
|
F: __dxlog_file13,
|
|
3221
|
-
L:
|
|
3222
|
+
L: 135,
|
|
3222
3223
|
S: this,
|
|
3223
3224
|
C: (f, a) => f(...a)
|
|
3224
3225
|
});
|
|
3225
3226
|
}
|
|
3226
3227
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3227
3228
|
F: __dxlog_file13,
|
|
3228
|
-
L:
|
|
3229
|
+
L: 137,
|
|
3229
3230
|
S: this,
|
|
3230
3231
|
A: [
|
|
3231
3232
|
"this.transports.has(proxyId)",
|
|
@@ -3241,14 +3242,14 @@ var SimplePeerTransportService = class {
|
|
|
3241
3242
|
}
|
|
3242
3243
|
}
|
|
3243
3244
|
async close({ proxyId }) {
|
|
3244
|
-
await this.transports.get(proxyId)?.transport.
|
|
3245
|
+
await this.transports.get(proxyId)?.transport.close();
|
|
3245
3246
|
await this.transports.get(proxyId)?.stream.end();
|
|
3246
3247
|
if (this.transports.get(proxyId)) {
|
|
3247
3248
|
this.transports.get(proxyId).state = "CLOSED";
|
|
3248
3249
|
}
|
|
3249
3250
|
(0, import_log12.log)("Closed.", void 0, {
|
|
3250
3251
|
F: __dxlog_file13,
|
|
3251
|
-
L:
|
|
3252
|
+
L: 153,
|
|
3252
3253
|
S: this,
|
|
3253
3254
|
C: (f, a) => f(...a)
|
|
3254
3255
|
});
|
|
@@ -3259,8 +3260,8 @@ var RPC_TIMEOUT = 1e4;
|
|
|
3259
3260
|
var RESP_MIN_THRESHOLD = 500;
|
|
3260
3261
|
var TIMEOUT_THRESHOLD = 10;
|
|
3261
3262
|
var SimplePeerTransportProxy = class {
|
|
3262
|
-
constructor(
|
|
3263
|
-
this.
|
|
3263
|
+
constructor(_options) {
|
|
3264
|
+
this._options = _options;
|
|
3264
3265
|
this._proxyId = import_keys12.PublicKey.random();
|
|
3265
3266
|
this._ctx = new import_context6.Context();
|
|
3266
3267
|
this._timeoutCount = 0;
|
|
@@ -3268,9 +3269,14 @@ var SimplePeerTransportProxy = class {
|
|
|
3268
3269
|
this.connected = new import_async10.Event();
|
|
3269
3270
|
this.errors = new import_debug6.ErrorStream();
|
|
3270
3271
|
this._closed = false;
|
|
3271
|
-
|
|
3272
|
+
}
|
|
3273
|
+
get isOpen() {
|
|
3274
|
+
return !this._closed;
|
|
3275
|
+
}
|
|
3276
|
+
async open() {
|
|
3277
|
+
this._serviceStream = this._options.bridgeService.open({
|
|
3272
3278
|
proxyId: this._proxyId,
|
|
3273
|
-
initiator: this.
|
|
3279
|
+
initiator: this._options.initiator
|
|
3274
3280
|
}, {
|
|
3275
3281
|
timeout: RPC_TIMEOUT
|
|
3276
3282
|
});
|
|
@@ -3278,7 +3284,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3278
3284
|
this._serviceStream.subscribe(async (event) => {
|
|
3279
3285
|
(0, import_log13.log)("SimplePeerTransportProxy: event", event, {
|
|
3280
3286
|
F: __dxlog_file14,
|
|
3281
|
-
L:
|
|
3287
|
+
L: 66,
|
|
3282
3288
|
S: this,
|
|
3283
3289
|
C: (f, a) => f(...a)
|
|
3284
3290
|
});
|
|
@@ -3293,7 +3299,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3293
3299
|
const proxyStream = new import_node_stream3.Writable({
|
|
3294
3300
|
write: (chunk, _, callback) => {
|
|
3295
3301
|
const then = performance.now();
|
|
3296
|
-
this.
|
|
3302
|
+
this._options.bridgeService.sendData({
|
|
3297
3303
|
proxyId: this._proxyId,
|
|
3298
3304
|
payload: chunk
|
|
3299
3305
|
}, {
|
|
@@ -3302,7 +3308,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3302
3308
|
if (performance.now() - then > RESP_MIN_THRESHOLD) {
|
|
3303
3309
|
(0, import_log13.log)("slow response, delaying callback", void 0, {
|
|
3304
3310
|
F: __dxlog_file14,
|
|
3305
|
-
L:
|
|
3311
|
+
L: 90,
|
|
3306
3312
|
S: this,
|
|
3307
3313
|
C: (f, a) => f(...a)
|
|
3308
3314
|
});
|
|
@@ -3318,7 +3324,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3318
3324
|
} else {
|
|
3319
3325
|
(0, import_log13.log)("timeout error, but still invoking callback", void 0, {
|
|
3320
3326
|
F: __dxlog_file14,
|
|
3321
|
-
L:
|
|
3327
|
+
L: 102,
|
|
3322
3328
|
S: this,
|
|
3323
3329
|
C: (f, a) => f(...a)
|
|
3324
3330
|
});
|
|
@@ -3327,7 +3333,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3327
3333
|
} else {
|
|
3328
3334
|
import_log13.log.catch(err, void 0, {
|
|
3329
3335
|
F: __dxlog_file14,
|
|
3330
|
-
L:
|
|
3336
|
+
L: 106,
|
|
3331
3337
|
S: this,
|
|
3332
3338
|
C: (f, a) => f(...a)
|
|
3333
3339
|
});
|
|
@@ -3340,19 +3346,50 @@ var SimplePeerTransportProxy = class {
|
|
|
3340
3346
|
err
|
|
3341
3347
|
}, {
|
|
3342
3348
|
F: __dxlog_file14,
|
|
3343
|
-
L:
|
|
3349
|
+
L: 114,
|
|
3344
3350
|
S: this,
|
|
3345
3351
|
C: (f, a) => f(...a)
|
|
3346
3352
|
});
|
|
3347
3353
|
});
|
|
3348
|
-
this.
|
|
3354
|
+
this._options.stream.pipe(proxyStream);
|
|
3349
3355
|
}, (error) => import_log13.log.catch(error, void 0, {
|
|
3350
3356
|
F: __dxlog_file14,
|
|
3351
|
-
L:
|
|
3357
|
+
L: 119,
|
|
3352
3358
|
S: this,
|
|
3353
3359
|
C: (f, a) => f(...a)
|
|
3354
3360
|
}));
|
|
3355
3361
|
}
|
|
3362
|
+
async close() {
|
|
3363
|
+
await this._ctx.dispose();
|
|
3364
|
+
if (this._closed) {
|
|
3365
|
+
return;
|
|
3366
|
+
}
|
|
3367
|
+
await this._serviceStream.close();
|
|
3368
|
+
try {
|
|
3369
|
+
await this._options.bridgeService.close({
|
|
3370
|
+
proxyId: this._proxyId
|
|
3371
|
+
}, {
|
|
3372
|
+
timeout: RPC_TIMEOUT
|
|
3373
|
+
});
|
|
3374
|
+
} catch (err) {
|
|
3375
|
+
import_log13.log.catch(err, void 0, {
|
|
3376
|
+
F: __dxlog_file14,
|
|
3377
|
+
L: 134,
|
|
3378
|
+
S: this,
|
|
3379
|
+
C: (f, a) => f(...a)
|
|
3380
|
+
});
|
|
3381
|
+
}
|
|
3382
|
+
this.closed.emit();
|
|
3383
|
+
this._closed = true;
|
|
3384
|
+
}
|
|
3385
|
+
async onSignal(signal) {
|
|
3386
|
+
this._options.bridgeService.sendSignal({
|
|
3387
|
+
proxyId: this._proxyId,
|
|
3388
|
+
signal
|
|
3389
|
+
}, {
|
|
3390
|
+
timeout: RPC_TIMEOUT
|
|
3391
|
+
}).catch((err) => this.errors.raise(decodeError(err)));
|
|
3392
|
+
}
|
|
3356
3393
|
async _handleConnection(connectionEvent) {
|
|
3357
3394
|
if (connectionEvent.error) {
|
|
3358
3395
|
this.errors.raise(decodeError(connectionEvent.error));
|
|
@@ -3363,63 +3400,31 @@ var SimplePeerTransportProxy = class {
|
|
|
3363
3400
|
break;
|
|
3364
3401
|
}
|
|
3365
3402
|
case import_bridge2.ConnectionState.CLOSED: {
|
|
3366
|
-
await this.
|
|
3403
|
+
await this.close();
|
|
3367
3404
|
break;
|
|
3368
3405
|
}
|
|
3369
3406
|
}
|
|
3370
3407
|
}
|
|
3371
3408
|
_handleData(dataEvent) {
|
|
3372
|
-
this.
|
|
3409
|
+
this._options.stream.write((0, import_util9.arrayToBuffer)(dataEvent.payload));
|
|
3373
3410
|
}
|
|
3374
3411
|
async _handleSignal(signalEvent) {
|
|
3375
|
-
await this.
|
|
3376
|
-
}
|
|
3377
|
-
signal(signal) {
|
|
3378
|
-
this._params.bridgeService.sendSignal({
|
|
3379
|
-
proxyId: this._proxyId,
|
|
3380
|
-
signal
|
|
3381
|
-
}, {
|
|
3382
|
-
timeout: RPC_TIMEOUT
|
|
3383
|
-
}).catch((err) => this.errors.raise(decodeError(err)));
|
|
3412
|
+
await this._options.sendSignal(signalEvent.payload);
|
|
3384
3413
|
}
|
|
3385
3414
|
async getDetails() {
|
|
3386
|
-
return (await this.
|
|
3415
|
+
return (await this._options.bridgeService.getDetails({
|
|
3387
3416
|
proxyId: this._proxyId
|
|
3388
3417
|
}, {
|
|
3389
3418
|
timeout: RPC_TIMEOUT
|
|
3390
3419
|
})).details;
|
|
3391
3420
|
}
|
|
3392
3421
|
async getStats() {
|
|
3393
|
-
return (await this.
|
|
3422
|
+
return (await this._options.bridgeService.getStats({
|
|
3394
3423
|
proxyId: this._proxyId
|
|
3395
3424
|
}, {
|
|
3396
3425
|
timeout: RPC_TIMEOUT
|
|
3397
3426
|
})).stats;
|
|
3398
3427
|
}
|
|
3399
|
-
// TODO(burdon): Move open from constructor.
|
|
3400
|
-
async destroy() {
|
|
3401
|
-
await this._ctx.dispose();
|
|
3402
|
-
if (this._closed) {
|
|
3403
|
-
return;
|
|
3404
|
-
}
|
|
3405
|
-
await this._serviceStream.close();
|
|
3406
|
-
try {
|
|
3407
|
-
await this._params.bridgeService.close({
|
|
3408
|
-
proxyId: this._proxyId
|
|
3409
|
-
}, {
|
|
3410
|
-
timeout: RPC_TIMEOUT
|
|
3411
|
-
});
|
|
3412
|
-
} catch (err) {
|
|
3413
|
-
import_log13.log.catch(err, void 0, {
|
|
3414
|
-
F: __dxlog_file14,
|
|
3415
|
-
L: 179,
|
|
3416
|
-
S: this,
|
|
3417
|
-
C: (f, a) => f(...a)
|
|
3418
|
-
});
|
|
3419
|
-
}
|
|
3420
|
-
this.closed.emit();
|
|
3421
|
-
this._closed = true;
|
|
3422
|
-
}
|
|
3423
3428
|
/**
|
|
3424
3429
|
* Called when underlying proxy service becomes unavailable.
|
|
3425
3430
|
*/
|
|
@@ -3448,7 +3453,7 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3448
3453
|
createTransport(options) {
|
|
3449
3454
|
(0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
|
|
3450
3455
|
F: __dxlog_file14,
|
|
3451
|
-
L:
|
|
3456
|
+
L: 218,
|
|
3452
3457
|
S: this,
|
|
3453
3458
|
A: [
|
|
3454
3459
|
"this._bridgeService",
|
|
@@ -3494,163 +3499,203 @@ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-man
|
|
|
3494
3499
|
var DATACHANNEL_LABEL = "dxos.mesh.transport";
|
|
3495
3500
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3496
3501
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3502
|
+
var createLibDataChannelTransportFactory = (webrtcConfig) => ({
|
|
3503
|
+
createTransport: (options) => new LibDataChannelTransport({
|
|
3504
|
+
...options,
|
|
3505
|
+
webrtcConfig
|
|
3506
|
+
})
|
|
3507
|
+
});
|
|
3497
3508
|
var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
3498
3509
|
static {
|
|
3499
3510
|
this._instanceCount = 0;
|
|
3500
3511
|
}
|
|
3501
|
-
constructor(
|
|
3502
|
-
this.
|
|
3512
|
+
constructor(_options) {
|
|
3513
|
+
this._options = _options;
|
|
3503
3514
|
this._closed = false;
|
|
3504
|
-
this.closed = new import_async11.Event();
|
|
3505
3515
|
this._connected = false;
|
|
3516
|
+
this._writeCallback = null;
|
|
3517
|
+
this._readyForCandidates = new import_async11.Trigger();
|
|
3518
|
+
this.closed = new import_async11.Event();
|
|
3506
3519
|
this.connected = new import_async11.Event();
|
|
3507
3520
|
this.errors = new import_debug7.ErrorStream();
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
this._peer
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
+
}
|
|
3522
|
+
get isOpen() {
|
|
3523
|
+
return !!this._peer && !this._closed;
|
|
3524
|
+
}
|
|
3525
|
+
async open() {
|
|
3526
|
+
if (this._closed) {
|
|
3527
|
+
this.errors.raise(new Error("connection already closed"));
|
|
3528
|
+
}
|
|
3529
|
+
const { RTCPeerConnection } = (await importESM("node-datachannel/polyfill")).default;
|
|
3530
|
+
if (this._options.webrtcConfig) {
|
|
3531
|
+
this._options.webrtcConfig.iceServers = this._options.webrtcConfig.iceServers ?? [];
|
|
3532
|
+
} else {
|
|
3533
|
+
this._options.webrtcConfig = {
|
|
3534
|
+
iceServers: []
|
|
3535
|
+
};
|
|
3536
|
+
}
|
|
3537
|
+
this._peer = new RTCPeerConnection(this._options.webrtcConfig);
|
|
3538
|
+
this._peer.onicecandidateerror = (event) => {
|
|
3539
|
+
import_log14.log.error("peer.onicecandidateerror", {
|
|
3540
|
+
event
|
|
3541
|
+
}, {
|
|
3542
|
+
F: __dxlog_file15,
|
|
3543
|
+
L: 77,
|
|
3544
|
+
S: this,
|
|
3545
|
+
C: (f, a) => f(...a)
|
|
3546
|
+
});
|
|
3547
|
+
};
|
|
3548
|
+
this._peer.onconnectionstatechange = (event) => {
|
|
3549
|
+
import_log14.log.debug("peer.onconnectionstatechange", {
|
|
3550
|
+
event,
|
|
3551
|
+
peerConnectionState: this._peer?.connectionState,
|
|
3552
|
+
transportConnectionState: this._connected
|
|
3553
|
+
}, {
|
|
3554
|
+
F: __dxlog_file15,
|
|
3555
|
+
L: 81,
|
|
3556
|
+
S: this,
|
|
3557
|
+
C: (f, a) => f(...a)
|
|
3558
|
+
});
|
|
3559
|
+
};
|
|
3560
|
+
this._peer.onicecandidate = async (event) => {
|
|
3561
|
+
import_log14.log.debug("peer.onicecandidate", {
|
|
3562
|
+
event
|
|
3563
|
+
}, {
|
|
3564
|
+
F: __dxlog_file15,
|
|
3565
|
+
L: 91,
|
|
3566
|
+
S: this,
|
|
3567
|
+
C: (f, a) => f(...a)
|
|
3568
|
+
});
|
|
3569
|
+
if (event.candidate) {
|
|
3570
|
+
try {
|
|
3571
|
+
await this._options.sendSignal({
|
|
3572
|
+
payload: {
|
|
3573
|
+
data: {
|
|
3574
|
+
type: "candidate",
|
|
3575
|
+
candidate: {
|
|
3576
|
+
candidate: event.candidate.candidate,
|
|
3577
|
+
// These fields never seem to be not null, but connecting to Chrome doesn't work if they are.
|
|
3578
|
+
sdpMLineIndex: event.candidate.sdpMLineIndex ?? 0,
|
|
3579
|
+
sdpMid: event.candidate.sdpMid ?? 0
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
});
|
|
3584
|
+
} catch (err) {
|
|
3585
|
+
import_log14.log.info("signaling error", {
|
|
3586
|
+
err
|
|
3587
|
+
}, {
|
|
3588
|
+
F: __dxlog_file15,
|
|
3589
|
+
L: 108,
|
|
3590
|
+
S: this,
|
|
3591
|
+
C: (f, a) => f(...a)
|
|
3592
|
+
});
|
|
3593
|
+
}
|
|
3521
3594
|
}
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3595
|
+
};
|
|
3596
|
+
if (this._options.initiator) {
|
|
3597
|
+
(0, import_invariant13.invariant)(this._peer, "not open", {
|
|
3598
|
+
F: __dxlog_file15,
|
|
3599
|
+
L: 114,
|
|
3600
|
+
S: this,
|
|
3601
|
+
A: [
|
|
3602
|
+
"this._peer",
|
|
3603
|
+
"'not open'"
|
|
3604
|
+
]
|
|
3605
|
+
});
|
|
3606
|
+
this._peer.createOffer().then(async (offer) => {
|
|
3607
|
+
if (this._closed) {
|
|
3608
|
+
return;
|
|
3609
|
+
}
|
|
3610
|
+
if (this._peer?.connectionState !== "connecting") {
|
|
3611
|
+
import_log14.log.error("peer not connecting", {
|
|
3612
|
+
peer: this._peer
|
|
3613
|
+
}, {
|
|
3614
|
+
F: __dxlog_file15,
|
|
3615
|
+
L: 125,
|
|
3616
|
+
S: this,
|
|
3617
|
+
C: (f, a) => f(...a)
|
|
3618
|
+
});
|
|
3619
|
+
this.errors.raise(new Error("invalid state: peer is initiator, but other peer not in state connecting"));
|
|
3620
|
+
}
|
|
3621
|
+
import_log14.log.debug("creating offer", {
|
|
3622
|
+
peer: this._peer,
|
|
3623
|
+
offer
|
|
3527
3624
|
}, {
|
|
3528
3625
|
F: __dxlog_file15,
|
|
3529
|
-
L:
|
|
3626
|
+
L: 129,
|
|
3530
3627
|
S: this,
|
|
3531
3628
|
C: (f, a) => f(...a)
|
|
3532
3629
|
});
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
L: 67,
|
|
3542
|
-
S: this,
|
|
3543
|
-
C: (f, a) => f(...a)
|
|
3630
|
+
await this._peer.setLocalDescription(offer);
|
|
3631
|
+
await this._options.sendSignal({
|
|
3632
|
+
payload: {
|
|
3633
|
+
data: {
|
|
3634
|
+
type: offer.type,
|
|
3635
|
+
sdp: offer.sdp
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3544
3638
|
});
|
|
3639
|
+
}).catch((err) => {
|
|
3640
|
+
this.errors.raise(err);
|
|
3641
|
+
});
|
|
3642
|
+
this._handleChannel(this._peer.createDataChannel(DATACHANNEL_LABEL));
|
|
3643
|
+
import_log14.log.debug("created data channel", void 0, {
|
|
3644
|
+
F: __dxlog_file15,
|
|
3645
|
+
L: 139,
|
|
3646
|
+
S: this,
|
|
3647
|
+
C: (f, a) => f(...a)
|
|
3648
|
+
});
|
|
3649
|
+
this._peer.ondatachannel = () => {
|
|
3650
|
+
this.errors.raise(new Error("unexpected ondatachannel event for initiator"));
|
|
3545
3651
|
};
|
|
3546
|
-
|
|
3547
|
-
|
|
3652
|
+
} else {
|
|
3653
|
+
this._peer.ondatachannel = (event) => {
|
|
3654
|
+
import_log14.log.debug("peer.ondatachannel (non-initiator)", {
|
|
3548
3655
|
event
|
|
3549
3656
|
}, {
|
|
3550
3657
|
F: __dxlog_file15,
|
|
3551
|
-
L:
|
|
3658
|
+
L: 145,
|
|
3552
3659
|
S: this,
|
|
3553
3660
|
C: (f, a) => f(...a)
|
|
3554
3661
|
});
|
|
3555
|
-
if (event.
|
|
3556
|
-
|
|
3557
|
-
await params.sendSignal({
|
|
3558
|
-
payload: {
|
|
3559
|
-
data: {
|
|
3560
|
-
type: "candidate",
|
|
3561
|
-
candidate: {
|
|
3562
|
-
candidate: event.candidate.candidate,
|
|
3563
|
-
// these fields never seem to be not null, but connecting to Chrome doesn't work if they are
|
|
3564
|
-
sdpMLineIndex: event.candidate.sdpMLineIndex ?? 0,
|
|
3565
|
-
sdpMid: event.candidate.sdpMid ?? 0
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
});
|
|
3570
|
-
} catch (err) {
|
|
3571
|
-
import_log14.log.info("signaling errror", {
|
|
3572
|
-
err
|
|
3573
|
-
}, {
|
|
3574
|
-
F: __dxlog_file15,
|
|
3575
|
-
L: 93,
|
|
3576
|
-
S: this,
|
|
3577
|
-
C: (f, a) => f(...a)
|
|
3578
|
-
});
|
|
3579
|
-
}
|
|
3662
|
+
if (event.channel.label !== DATACHANNEL_LABEL) {
|
|
3663
|
+
this.errors.raise(new Error(`unexpected channel label ${event.channel.label}`));
|
|
3580
3664
|
}
|
|
3665
|
+
this._handleChannel(event.channel);
|
|
3581
3666
|
};
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
C: (f, a) => f(...a)
|
|
3605
|
-
});
|
|
3606
|
-
await peer.setLocalDescription(offer);
|
|
3607
|
-
await params.sendSignal({
|
|
3608
|
-
payload: {
|
|
3609
|
-
data: {
|
|
3610
|
-
type: offer.type,
|
|
3611
|
-
sdp: offer.sdp
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
});
|
|
3615
|
-
return offer;
|
|
3616
|
-
}).catch((err) => {
|
|
3617
|
-
this.errors.raise(err);
|
|
3618
|
-
});
|
|
3619
|
-
this.handleChannel(peer.createDataChannel(DATACHANNEL_LABEL));
|
|
3620
|
-
import_log14.log.debug("created data channel", void 0, {
|
|
3621
|
-
F: __dxlog_file15,
|
|
3622
|
-
L: 118,
|
|
3623
|
-
S: this,
|
|
3624
|
-
C: (f, a) => f(...a)
|
|
3625
|
-
});
|
|
3626
|
-
peer.ondatachannel = (event) => {
|
|
3627
|
-
this.errors.raise(new Error("got ondatachannel when i am the initiator?"));
|
|
3628
|
-
};
|
|
3629
|
-
} else {
|
|
3630
|
-
peer.ondatachannel = (event) => {
|
|
3631
|
-
import_log14.log.debug("peer.ondatachannel (non-initiator)", {
|
|
3632
|
-
event
|
|
3633
|
-
}, {
|
|
3634
|
-
F: __dxlog_file15,
|
|
3635
|
-
L: 124,
|
|
3636
|
-
S: this,
|
|
3637
|
-
C: (f, a) => f(...a)
|
|
3638
|
-
});
|
|
3639
|
-
if (event.channel.label !== DATACHANNEL_LABEL) {
|
|
3640
|
-
this.errors.raise(new Error(`unexpected channel label ${event.channel.label}`));
|
|
3641
|
-
}
|
|
3642
|
-
this.handleChannel(event.channel);
|
|
3643
|
-
};
|
|
3644
|
-
}
|
|
3645
|
-
return peer;
|
|
3646
|
-
})();
|
|
3667
|
+
}
|
|
3668
|
+
_LibDataChannelTransport._instanceCount++;
|
|
3669
|
+
}
|
|
3670
|
+
async close() {
|
|
3671
|
+
await this._close();
|
|
3672
|
+
if (--_LibDataChannelTransport._instanceCount === 0) {
|
|
3673
|
+
(await importESM("node-datachannel")).cleanup();
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
async _close() {
|
|
3677
|
+
if (this._closed) {
|
|
3678
|
+
return;
|
|
3679
|
+
}
|
|
3680
|
+
await this._disconnectStreams();
|
|
3681
|
+
try {
|
|
3682
|
+
this._peer?.close();
|
|
3683
|
+
} catch (err) {
|
|
3684
|
+
this.errors.raise(err);
|
|
3685
|
+
}
|
|
3686
|
+
this._peer = void 0;
|
|
3687
|
+
this._closed = true;
|
|
3688
|
+
this.closed.emit();
|
|
3647
3689
|
}
|
|
3648
|
-
|
|
3690
|
+
/**
|
|
3691
|
+
* Handle data channel events.
|
|
3692
|
+
*/
|
|
3693
|
+
_handleChannel(dataChannel) {
|
|
3649
3694
|
this._channel = dataChannel;
|
|
3650
3695
|
this._channel.onopen = () => {
|
|
3651
|
-
import_log14.log.debug("
|
|
3696
|
+
import_log14.log.debug("channel.onopen", void 0, {
|
|
3652
3697
|
F: __dxlog_file15,
|
|
3653
|
-
L:
|
|
3698
|
+
L: 190,
|
|
3654
3699
|
S: this,
|
|
3655
3700
|
C: (f, a) => f(...a)
|
|
3656
3701
|
});
|
|
@@ -3669,9 +3714,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3669
3714
|
}
|
|
3670
3715
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3671
3716
|
if (this._writeCallback !== null) {
|
|
3672
|
-
import_log14.log.error("consumer trying to write before we
|
|
3717
|
+
import_log14.log.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3673
3718
|
F: __dxlog_file15,
|
|
3674
|
-
L:
|
|
3719
|
+
L: 207,
|
|
3675
3720
|
S: this,
|
|
3676
3721
|
C: (f, a) => f(...a)
|
|
3677
3722
|
});
|
|
@@ -3682,26 +3727,31 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3682
3727
|
}
|
|
3683
3728
|
}
|
|
3684
3729
|
});
|
|
3685
|
-
duplex.pipe(this.
|
|
3730
|
+
duplex.pipe(this._options.stream).pipe(duplex);
|
|
3686
3731
|
this._stream = duplex;
|
|
3687
3732
|
this._connected = true;
|
|
3688
3733
|
this.connected.emit();
|
|
3689
3734
|
};
|
|
3690
|
-
this._channel.onerror = async (err) => {
|
|
3691
|
-
this.errors.raise(new Error("channel error: " + err.toString()));
|
|
3692
|
-
await this._close();
|
|
3693
|
-
};
|
|
3694
3735
|
this._channel.onclose = async (err) => {
|
|
3695
|
-
import_log14.log.info("channel
|
|
3736
|
+
import_log14.log.info("channel.onclose", {
|
|
3696
3737
|
err
|
|
3697
3738
|
}, {
|
|
3698
3739
|
F: __dxlog_file15,
|
|
3699
|
-
L:
|
|
3740
|
+
L: 223,
|
|
3700
3741
|
S: this,
|
|
3701
3742
|
C: (f, a) => f(...a)
|
|
3702
3743
|
});
|
|
3703
3744
|
await this._close();
|
|
3704
3745
|
};
|
|
3746
|
+
this._channel.onerror = async (err) => {
|
|
3747
|
+
this.errors.raise(new Error("channel error: " + err.toString()));
|
|
3748
|
+
await this._close();
|
|
3749
|
+
};
|
|
3750
|
+
this._channel.onbufferedamountlow = () => {
|
|
3751
|
+
const cb = this._writeCallback;
|
|
3752
|
+
this._writeCallback = null;
|
|
3753
|
+
cb?.();
|
|
3754
|
+
};
|
|
3705
3755
|
this._channel.onmessage = (event) => {
|
|
3706
3756
|
let data = event.data;
|
|
3707
3757
|
if (data instanceof ArrayBuffer) {
|
|
@@ -3709,37 +3759,27 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3709
3759
|
}
|
|
3710
3760
|
this._stream.push(data);
|
|
3711
3761
|
};
|
|
3712
|
-
this._channel.onbufferedamountlow = () => {
|
|
3713
|
-
const cb = this._writeCallback;
|
|
3714
|
-
this._writeCallback = null;
|
|
3715
|
-
cb?.();
|
|
3716
|
-
};
|
|
3717
3762
|
}
|
|
3718
|
-
async
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3763
|
+
async onSignal(signal) {
|
|
3764
|
+
(0, import_invariant13.invariant)(this._peer, "not open", {
|
|
3765
|
+
F: __dxlog_file15,
|
|
3766
|
+
L: 249,
|
|
3767
|
+
S: this,
|
|
3768
|
+
A: [
|
|
3769
|
+
"this._peer",
|
|
3770
|
+
"'not open'"
|
|
3771
|
+
]
|
|
3772
|
+
});
|
|
3724
3773
|
try {
|
|
3725
|
-
peer.close();
|
|
3726
|
-
} catch (err) {
|
|
3727
|
-
this.errors.raise(err);
|
|
3728
|
-
}
|
|
3729
|
-
this._closed = true;
|
|
3730
|
-
this.closed.emit();
|
|
3731
|
-
}
|
|
3732
|
-
signal(signal) {
|
|
3733
|
-
this._peer.then(async (peer) => {
|
|
3734
3774
|
const data = signal.payload.data;
|
|
3735
3775
|
switch (data.type) {
|
|
3736
3776
|
case "offer": {
|
|
3737
|
-
if (
|
|
3777
|
+
if (this._peer.connectionState !== "new") {
|
|
3738
3778
|
import_log14.log.error("received offer but peer not in state new", {
|
|
3739
|
-
peer
|
|
3779
|
+
peer: this._peer
|
|
3740
3780
|
}, {
|
|
3741
3781
|
F: __dxlog_file15,
|
|
3742
|
-
L:
|
|
3782
|
+
L: 256,
|
|
3743
3783
|
S: this,
|
|
3744
3784
|
C: (f, a) => f(...a)
|
|
3745
3785
|
});
|
|
@@ -3747,13 +3787,13 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3747
3787
|
break;
|
|
3748
3788
|
}
|
|
3749
3789
|
try {
|
|
3750
|
-
await
|
|
3790
|
+
await this._peer.setRemoteDescription({
|
|
3751
3791
|
type: data.type,
|
|
3752
3792
|
sdp: data.sdp
|
|
3753
3793
|
});
|
|
3754
|
-
const answer = await
|
|
3755
|
-
await
|
|
3756
|
-
await this.
|
|
3794
|
+
const answer = await this._peer.createAnswer();
|
|
3795
|
+
await this._peer.setLocalDescription(answer);
|
|
3796
|
+
await this._options.sendSignal({
|
|
3757
3797
|
payload: {
|
|
3758
3798
|
data: {
|
|
3759
3799
|
type: answer.type,
|
|
@@ -3763,11 +3803,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3763
3803
|
});
|
|
3764
3804
|
this._readyForCandidates.wake();
|
|
3765
3805
|
} catch (err) {
|
|
3766
|
-
import_log14.log.error("
|
|
3806
|
+
import_log14.log.error("cannot handle offer from signalling server", {
|
|
3767
3807
|
err
|
|
3768
3808
|
}, {
|
|
3769
3809
|
F: __dxlog_file15,
|
|
3770
|
-
L:
|
|
3810
|
+
L: 268,
|
|
3771
3811
|
S: this,
|
|
3772
3812
|
C: (f, a) => f(...a)
|
|
3773
3813
|
});
|
|
@@ -3777,17 +3817,17 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3777
3817
|
}
|
|
3778
3818
|
case "answer":
|
|
3779
3819
|
try {
|
|
3780
|
-
await
|
|
3820
|
+
await this._peer.setRemoteDescription({
|
|
3781
3821
|
type: data.type,
|
|
3782
3822
|
sdp: data.sdp
|
|
3783
3823
|
});
|
|
3784
3824
|
this._readyForCandidates.wake();
|
|
3785
3825
|
} catch (err) {
|
|
3786
|
-
import_log14.log.error("
|
|
3826
|
+
import_log14.log.error("cannot handle answer from signalling server", {
|
|
3787
3827
|
err
|
|
3788
3828
|
}, {
|
|
3789
3829
|
F: __dxlog_file15,
|
|
3790
|
-
L:
|
|
3830
|
+
L: 279,
|
|
3791
3831
|
S: this,
|
|
3792
3832
|
C: (f, a) => f(...a)
|
|
3793
3833
|
});
|
|
@@ -3796,7 +3836,7 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3796
3836
|
break;
|
|
3797
3837
|
case "candidate":
|
|
3798
3838
|
await this._readyForCandidates.wait();
|
|
3799
|
-
await
|
|
3839
|
+
await this._peer.addIceCandidate({
|
|
3800
3840
|
candidate: data.candidate.candidate
|
|
3801
3841
|
});
|
|
3802
3842
|
break;
|
|
@@ -3806,20 +3846,20 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3806
3846
|
signal
|
|
3807
3847
|
}, {
|
|
3808
3848
|
F: __dxlog_file15,
|
|
3809
|
-
L:
|
|
3849
|
+
L: 290,
|
|
3810
3850
|
S: this,
|
|
3811
3851
|
C: (f, a) => f(...a)
|
|
3812
3852
|
});
|
|
3813
3853
|
this.errors.raise(new Error(`unhandled signal type ${data.type}`));
|
|
3814
3854
|
}
|
|
3815
|
-
}
|
|
3855
|
+
} catch (err) {
|
|
3816
3856
|
import_log14.log.catch(err, void 0, {
|
|
3817
3857
|
F: __dxlog_file15,
|
|
3818
|
-
L:
|
|
3858
|
+
L: 294,
|
|
3819
3859
|
S: this,
|
|
3820
3860
|
C: (f, a) => f(...a)
|
|
3821
3861
|
});
|
|
3822
|
-
}
|
|
3862
|
+
}
|
|
3823
3863
|
}
|
|
3824
3864
|
async getDetails() {
|
|
3825
3865
|
const stats = await this._getStats();
|
|
@@ -3832,26 +3872,6 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3832
3872
|
}
|
|
3833
3873
|
return `${rc.ip}:${rc.port} ${rc.candidateType}`;
|
|
3834
3874
|
}
|
|
3835
|
-
async _getStats() {
|
|
3836
|
-
return this._peer.then(async (peer) => {
|
|
3837
|
-
const stats = await peer.getStats();
|
|
3838
|
-
const statsEntries = Array.from(stats.entries());
|
|
3839
|
-
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
3840
|
-
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
3841
|
-
let selectedCandidatePair;
|
|
3842
|
-
let remoteCandidate;
|
|
3843
|
-
if (candidatePair.length > 0) {
|
|
3844
|
-
selectedCandidatePair = candidatePair[0][1];
|
|
3845
|
-
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
3846
|
-
}
|
|
3847
|
-
return {
|
|
3848
|
-
transport,
|
|
3849
|
-
selectedCandidatePair,
|
|
3850
|
-
remoteCandidate,
|
|
3851
|
-
raw: Object.fromEntries(stats)
|
|
3852
|
-
};
|
|
3853
|
-
});
|
|
3854
|
-
}
|
|
3855
3875
|
async getStats() {
|
|
3856
3876
|
const stats = await this._getStats();
|
|
3857
3877
|
if (!stats) {
|
|
@@ -3871,43 +3891,63 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3871
3891
|
rawStats: stats.raw
|
|
3872
3892
|
};
|
|
3873
3893
|
}
|
|
3874
|
-
async
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3894
|
+
async _getStats() {
|
|
3895
|
+
(0, import_invariant13.invariant)(this._peer, "not open", {
|
|
3896
|
+
F: __dxlog_file15,
|
|
3897
|
+
L: 334,
|
|
3898
|
+
S: this,
|
|
3899
|
+
A: [
|
|
3900
|
+
"this._peer",
|
|
3901
|
+
"'not open'"
|
|
3902
|
+
]
|
|
3903
|
+
});
|
|
3904
|
+
const stats = await this._peer.getStats();
|
|
3905
|
+
const statsEntries = Array.from(stats.entries());
|
|
3906
|
+
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
3907
|
+
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
3908
|
+
let selectedCandidatePair;
|
|
3909
|
+
let remoteCandidate;
|
|
3910
|
+
if (candidatePair.length > 0) {
|
|
3911
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
3912
|
+
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
3878
3913
|
}
|
|
3914
|
+
return {
|
|
3915
|
+
transport,
|
|
3916
|
+
selectedCandidatePair,
|
|
3917
|
+
remoteCandidate,
|
|
3918
|
+
raw: Object.fromEntries(stats)
|
|
3919
|
+
};
|
|
3879
3920
|
}
|
|
3880
3921
|
async _disconnectStreams() {
|
|
3881
|
-
this.
|
|
3922
|
+
this._options.stream.unpipe?.(this._stream)?.unpipe?.(this._options.stream);
|
|
3882
3923
|
}
|
|
3883
3924
|
};
|
|
3884
3925
|
_ts_decorate5([
|
|
3885
3926
|
import_async11.synchronized
|
|
3886
3927
|
], LibDataChannelTransport.prototype, "_close", null);
|
|
3887
|
-
var createLibDataChannelTransportFactory = (webrtcConfig) => ({
|
|
3888
|
-
createTransport: (params) => new LibDataChannelTransport({
|
|
3889
|
-
...params,
|
|
3890
|
-
webrtcConfig
|
|
3891
|
-
})
|
|
3892
|
-
});
|
|
3893
3928
|
var importESM = Function("path", "return import(path)");
|
|
3894
3929
|
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
|
|
3895
3930
|
var TcpTransportFactory = {
|
|
3896
|
-
createTransport: (
|
|
3931
|
+
createTransport: (options) => new TcpTransport(options)
|
|
3897
3932
|
};
|
|
3898
3933
|
var TcpTransport = class {
|
|
3899
3934
|
constructor(options) {
|
|
3900
3935
|
this.options = options;
|
|
3901
3936
|
this._server = void 0;
|
|
3902
3937
|
this._socket = void 0;
|
|
3938
|
+
this._connected = false;
|
|
3939
|
+
this._closed = false;
|
|
3903
3940
|
this.closed = new import_async12.Event();
|
|
3904
3941
|
this.connected = new import_async12.Event();
|
|
3905
3942
|
this.errors = new import_debug8.ErrorStream();
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3943
|
+
}
|
|
3944
|
+
get isOpen() {
|
|
3945
|
+
return this._connected && !this._closed;
|
|
3946
|
+
}
|
|
3947
|
+
async open() {
|
|
3948
|
+
(0, import_log15.log)("opening", void 0, {
|
|
3909
3949
|
F: __dxlog_file16,
|
|
3910
|
-
L:
|
|
3950
|
+
L: 39,
|
|
3911
3951
|
S: this,
|
|
3912
3952
|
C: (f, a) => f(...a)
|
|
3913
3953
|
});
|
|
@@ -3917,7 +3957,7 @@ var TcpTransport = class {
|
|
|
3917
3957
|
this._server = new Server((socket) => {
|
|
3918
3958
|
(0, import_log15.log)("new connection", void 0, {
|
|
3919
3959
|
F: __dxlog_file16,
|
|
3920
|
-
L:
|
|
3960
|
+
L: 47,
|
|
3921
3961
|
S: this,
|
|
3922
3962
|
C: (f, a) => f(...a)
|
|
3923
3963
|
});
|
|
@@ -3932,7 +3972,7 @@ var TcpTransport = class {
|
|
|
3932
3972
|
port
|
|
3933
3973
|
}, {
|
|
3934
3974
|
F: __dxlog_file16,
|
|
3935
|
-
L:
|
|
3975
|
+
L: 56,
|
|
3936
3976
|
S: this,
|
|
3937
3977
|
C: (f, a) => f(...a)
|
|
3938
3978
|
});
|
|
@@ -3941,7 +3981,7 @@ var TcpTransport = class {
|
|
|
3941
3981
|
port
|
|
3942
3982
|
}
|
|
3943
3983
|
}).catch((err) => {
|
|
3944
|
-
if (!this.
|
|
3984
|
+
if (!this._closed) {
|
|
3945
3985
|
this.errors.raise(err);
|
|
3946
3986
|
}
|
|
3947
3987
|
});
|
|
@@ -3953,23 +3993,23 @@ var TcpTransport = class {
|
|
|
3953
3993
|
});
|
|
3954
3994
|
}
|
|
3955
3995
|
}
|
|
3956
|
-
async
|
|
3996
|
+
async close() {
|
|
3957
3997
|
(0, import_log15.log)("closing", void 0, {
|
|
3958
3998
|
F: __dxlog_file16,
|
|
3959
|
-
L:
|
|
3999
|
+
L: 78,
|
|
3960
4000
|
S: this,
|
|
3961
4001
|
C: (f, a) => f(...a)
|
|
3962
4002
|
});
|
|
3963
4003
|
this._socket?.destroy();
|
|
3964
4004
|
this._server?.close();
|
|
3965
|
-
this.
|
|
4005
|
+
this._closed = true;
|
|
3966
4006
|
}
|
|
3967
|
-
|
|
4007
|
+
async onSignal({ payload }) {
|
|
3968
4008
|
(0, import_log15.log)("received signal", {
|
|
3969
4009
|
payload
|
|
3970
4010
|
}, {
|
|
3971
4011
|
F: __dxlog_file16,
|
|
3972
|
-
L:
|
|
4012
|
+
L: 85,
|
|
3973
4013
|
S: this,
|
|
3974
4014
|
C: (f, a) => f(...a)
|
|
3975
4015
|
});
|
|
@@ -4005,19 +4045,17 @@ var TcpTransport = class {
|
|
|
4005
4045
|
localPort: socket.localPort
|
|
4006
4046
|
}, {
|
|
4007
4047
|
F: __dxlog_file16,
|
|
4008
|
-
L:
|
|
4048
|
+
L: 115,
|
|
4009
4049
|
S: this,
|
|
4010
4050
|
C: (f, a) => f(...a)
|
|
4011
4051
|
});
|
|
4012
4052
|
this._socket = socket;
|
|
4013
|
-
this.connected.emit();
|
|
4014
|
-
this.options.stream.pipe(this._socket).pipe(this.options.stream);
|
|
4015
4053
|
this._socket.on("connect", () => {
|
|
4016
4054
|
(0, import_log15.log)("connected to", {
|
|
4017
4055
|
port: this._socket?.remotePort
|
|
4018
4056
|
}, {
|
|
4019
4057
|
F: __dxlog_file16,
|
|
4020
|
-
L:
|
|
4058
|
+
L: 119,
|
|
4021
4059
|
S: this,
|
|
4022
4060
|
C: (f, a) => f(...a)
|
|
4023
4061
|
});
|
|
@@ -4029,6 +4067,8 @@ var TcpTransport = class {
|
|
|
4029
4067
|
this._socket.on("close", () => {
|
|
4030
4068
|
this.closed.emit();
|
|
4031
4069
|
});
|
|
4070
|
+
this.connected.emit();
|
|
4071
|
+
this.options.stream.pipe(this._socket).pipe(this.options.stream);
|
|
4032
4072
|
}
|
|
4033
4073
|
};
|
|
4034
4074
|
var createTeleportProtocolFactory = (onConnection) => {
|
|
@@ -4078,4 +4118,4 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
4078
4118
|
createSimplePeerTransportFactory,
|
|
4079
4119
|
createTeleportProtocolFactory
|
|
4080
4120
|
});
|
|
4081
|
-
//# sourceMappingURL=chunk-
|
|
4121
|
+
//# sourceMappingURL=chunk-M4CGCR2I.cjs.map
|