@dxos/network-manager 0.3.9-main.3a0f16f → 0.3.9-main.3ced312

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.
Files changed (55) hide show
  1. package/dist/lib/browser/{chunk-4HITD6WI.mjs → chunk-HJ6JLRZM.mjs} +250 -72
  2. package/dist/lib/browser/chunk-HJ6JLRZM.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +1 -1
  6. package/dist/lib/node/{chunk-XE5JOIGD.cjs → chunk-JDKM4UPJ.cjs} +21 -13
  7. package/dist/lib/node/chunk-JDKM4UPJ.cjs.map +7 -0
  8. package/dist/lib/node/{chunk-6AD7QA4X.cjs → chunk-XZF4MAFB.cjs} +259 -71
  9. package/dist/lib/node/chunk-XZF4MAFB.cjs.map +7 -0
  10. package/dist/lib/node/{datachannel-53JZPGFA.cjs → datachannel-3VTTIMR5.cjs} +9 -9
  11. package/dist/lib/node/{datachannel-53JZPGFA.cjs.map → datachannel-3VTTIMR5.cjs.map} +2 -2
  12. package/dist/lib/node/index.cjs +32 -32
  13. package/dist/lib/node/index.cjs.map +1 -1
  14. package/dist/lib/node/meta.json +1 -1
  15. package/dist/lib/node/testing/index.cjs +19 -19
  16. package/dist/types/src/connection-log.d.ts.map +1 -1
  17. package/dist/types/src/swarm/connection.d.ts +4 -1
  18. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  19. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts +7 -0
  20. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +1 -1
  21. package/dist/types/src/transport/libdatachannel-transport.d.ts +3 -1
  22. package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
  23. package/dist/types/src/transport/memory-transport.d.ts +3 -1
  24. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  25. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts +3 -1
  26. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  27. package/dist/types/src/transport/simplepeer-transport-service.d.ts +3 -1
  28. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
  29. package/dist/types/src/transport/simplepeer-transport.d.ts +7 -1
  30. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  31. package/dist/types/src/transport/tcp-transport.browser.d.ts +3 -1
  32. package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -1
  33. package/dist/types/src/transport/tcp-transport.d.ts +3 -1
  34. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -1
  35. package/dist/types/src/transport/transport.d.ts +17 -0
  36. package/dist/types/src/transport/transport.d.ts.map +1 -1
  37. package/dist/types/src/wire-protocol.d.ts +1 -1
  38. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  39. package/package.json +17 -17
  40. package/src/connection-log.ts +14 -1
  41. package/src/swarm/connection.ts +23 -4
  42. package/src/transport/datachannel/rtc-peer-connection.ts +20 -12
  43. package/src/transport/libdatachannel-transport.test.ts +0 -4
  44. package/src/transport/libdatachannel-transport.ts +37 -1
  45. package/src/transport/memory-transport.ts +14 -1
  46. package/src/transport/simplepeer-transport-proxy.ts +9 -1
  47. package/src/transport/simplepeer-transport-service.ts +14 -0
  48. package/src/transport/simplepeer-transport.ts +66 -2
  49. package/src/transport/tcp-transport.browser.ts +9 -1
  50. package/src/transport/tcp-transport.ts +19 -1
  51. package/src/transport/transport.ts +19 -0
  52. package/src/wire-protocol.ts +3 -3
  53. package/dist/lib/browser/chunk-4HITD6WI.mjs.map +0 -7
  54. package/dist/lib/node/chunk-6AD7QA4X.cjs.map +0 -7
  55. package/dist/lib/node/chunk-XE5JOIGD.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 chunk_6AD7QA4X_exports = {};
30
- __export(chunk_6AD7QA4X_exports, {
29
+ var chunk_XZF4MAFB_exports = {};
30
+ __export(chunk_XZF4MAFB_exports, {
31
31
  Connection: () => Connection,
32
32
  ConnectionLimiter: () => ConnectionLimiter,
33
33
  ConnectionLog: () => ConnectionLog,
@@ -55,8 +55,8 @@ __export(chunk_6AD7QA4X_exports, {
55
55
  createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
56
56
  createTeleportProtocolFactory: () => createTeleportProtocolFactory
57
57
  });
58
- module.exports = __toCommonJS(chunk_6AD7QA4X_exports);
59
- var import_chunk_XE5JOIGD = require("./chunk-XE5JOIGD.cjs");
58
+ module.exports = __toCommonJS(chunk_XZF4MAFB_exports);
59
+ var import_chunk_JDKM4UPJ = require("./chunk-JDKM4UPJ.cjs");
60
60
  var import_async = require("@dxos/async");
61
61
  var import_context = require("@dxos/context");
62
62
  var import_debug = require("@dxos/debug");
@@ -166,6 +166,7 @@ function _ts_decorate(decorators, target, key, desc) {
166
166
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
167
167
  var STARTING_SIGNALLING_DELAY = 10;
168
168
  var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
169
+ var TRANSPORT_STATS_INTERVAL = 5e3;
169
170
  var MAX_SIGNALLING_DELAY = 300;
170
171
  var ConnectionState;
171
172
  (function(ConnectionState5) {
@@ -228,6 +229,7 @@ var Connection = class {
228
229
  this.stateChanged = new import_async.Event();
229
230
  this.errors = new import_debug.ErrorStream();
230
231
  this._instanceId = import_keys.PublicKey.random().toHex();
232
+ this.transportStats = new import_async.Event();
231
233
  this._signalSendTask = new import_async.DeferredTask(this._ctx, async () => {
232
234
  await this._flushSignalBuffer();
233
235
  });
@@ -240,11 +242,14 @@ var Connection = class {
240
242
  initiator: this.initiator
241
243
  }, {
242
244
  F: __dxlog_file,
243
- L: 130,
245
+ L: 134,
244
246
  S: this,
245
247
  C: (f, a) => f(...a)
246
248
  });
247
249
  }
250
+ get sessionIdString() {
251
+ return this.sessionId.truncate();
252
+ }
248
253
  get state() {
249
254
  return this._state;
250
255
  }
@@ -260,7 +265,7 @@ var Connection = class {
260
265
  async openConnection() {
261
266
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
262
267
  F: __dxlog_file,
263
- L: 155,
268
+ L: 164,
264
269
  S: this,
265
270
  A: [
266
271
  "this._state === ConnectionState.INITIAL",
@@ -271,7 +276,7 @@ var Connection = class {
271
276
  id: this._instanceId
272
277
  }), {
273
278
  F: __dxlog_file,
274
- L: 156,
279
+ L: 165,
275
280
  S: this,
276
281
  C: (f, a) => f(...a)
277
282
  });
@@ -283,18 +288,18 @@ var Connection = class {
283
288
  initiator: this.initiator
284
289
  }, {
285
290
  F: __dxlog_file,
286
- L: 157,
291
+ L: 166,
287
292
  S: this,
288
293
  C: (f, a) => f(...a)
289
294
  });
290
295
  this._changeState(ConnectionState.CONNECTING);
291
- this._protocol.open().catch((err) => {
296
+ this._protocol.open(this.sessionId).catch((err) => {
292
297
  this.errors.raise(err);
293
298
  });
294
299
  this._protocol.stream.on("close", () => {
295
300
  (0, import_log.log)("protocol stream closed", void 0, {
296
301
  F: __dxlog_file,
297
- L: 174,
302
+ L: 183,
298
303
  S: this,
299
304
  C: (f, a) => f(...a)
300
305
  });
@@ -303,7 +308,7 @@ var Connection = class {
303
308
  (0, import_async.scheduleTask)(this.connectedTimeoutContext, async () => {
304
309
  import_log.log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
305
310
  F: __dxlog_file,
306
- L: 181,
311
+ L: 190,
307
312
  S: this,
308
313
  C: (f, a) => f(...a)
309
314
  });
@@ -311,7 +316,7 @@ var Connection = class {
311
316
  }, TRANSPORT_CONNECTION_TIMEOUT);
312
317
  (0, import_invariant.invariant)(!this._transport, void 0, {
313
318
  F: __dxlog_file,
314
- L: 189,
319
+ L: 198,
315
320
  S: this,
316
321
  A: [
317
322
  "!this._transport",
@@ -321,18 +326,20 @@ var Connection = class {
321
326
  this._transport = this._transportFactory.createTransport({
322
327
  initiator: this.initiator,
323
328
  stream: this._protocol.stream,
324
- sendSignal: async (signal) => this._sendSignal(signal)
329
+ sendSignal: async (signal) => this._sendSignal(signal),
330
+ sessionId: this.sessionId
325
331
  });
326
332
  this._transport.connected.once(async () => {
327
333
  this._changeState(ConnectionState.CONNECTED);
328
334
  await this.connectedTimeoutContext.dispose();
329
335
  this._callbacks?.onConnected?.();
336
+ (0, import_async.scheduleTaskInterval)(this._ctx, async () => this._emitTransportStats(), TRANSPORT_STATS_INTERVAL);
330
337
  });
331
338
  this._transport.closed.once(() => {
332
339
  this._transport = void 0;
333
340
  (0, import_log.log)("abort triggered by transport close", void 0, {
334
341
  F: __dxlog_file,
335
- L: 204,
342
+ L: 216,
336
343
  S: this,
337
344
  C: (f, a) => f(...a)
338
345
  });
@@ -343,7 +350,7 @@ var Connection = class {
343
350
  err
344
351
  }, {
345
352
  F: __dxlog_file,
346
- L: 209,
353
+ L: 221,
347
354
  S: this,
348
355
  C: (f, a) => f(...a)
349
356
  });
@@ -353,7 +360,7 @@ var Connection = class {
353
360
  if (err instanceof import_protocols.ConnectionResetError) {
354
361
  import_log.log.info("aborting due to transport ConnectionResetError", void 0, {
355
362
  F: __dxlog_file,
356
- L: 216,
363
+ L: 228,
357
364
  S: this,
358
365
  C: (f, a) => f(...a)
359
366
  });
@@ -361,7 +368,7 @@ var Connection = class {
361
368
  } else if (err instanceof import_protocols.ConnectivityError) {
362
369
  import_log.log.info("aborting due to transport ConnectivityError", void 0, {
363
370
  F: __dxlog_file,
364
- L: 219,
371
+ L: 231,
365
372
  S: this,
366
373
  C: (f, a) => f(...a)
367
374
  });
@@ -371,7 +378,7 @@ var Connection = class {
371
378
  err
372
379
  }, {
373
380
  F: __dxlog_file,
374
- L: 222,
381
+ L: 234,
375
382
  S: this,
376
383
  C: (f, a) => f(...a)
377
384
  });
@@ -389,7 +396,7 @@ var Connection = class {
389
396
  id: this._instanceId
390
397
  }), {
391
398
  F: __dxlog_file,
392
- L: 238,
399
+ L: 250,
393
400
  S: this,
394
401
  C: (f, a) => f(...a)
395
402
  });
@@ -399,14 +406,14 @@ var Connection = class {
399
406
  err
400
407
  }, {
401
408
  F: __dxlog_file,
402
- L: 245,
409
+ L: 257,
403
410
  S: this,
404
411
  C: (f, a) => f(...a)
405
412
  });
406
413
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
407
414
  (0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
408
415
  F: __dxlog_file,
409
- L: 247,
416
+ L: 259,
410
417
  S: this,
411
418
  C: (f, a) => f(...a)
412
419
  });
@@ -421,7 +428,7 @@ var Connection = class {
421
428
  try {
422
429
  (0, import_log.log)("aborting protocol... ", void 0, {
423
430
  F: __dxlog_file,
424
- L: 261,
431
+ L: 273,
425
432
  S: this,
426
433
  C: (f, a) => f(...a)
427
434
  });
@@ -429,7 +436,7 @@ var Connection = class {
429
436
  } catch (err2) {
430
437
  import_log.log.catch(err2, void 0, {
431
438
  F: __dxlog_file,
432
- L: 264,
439
+ L: 276,
433
440
  S: this,
434
441
  C: (f, a) => f(...a)
435
442
  });
@@ -439,7 +446,7 @@ var Connection = class {
439
446
  } catch (err2) {
440
447
  import_log.log.catch(err2, void 0, {
441
448
  F: __dxlog_file,
442
- L: 271,
449
+ L: 283,
443
450
  S: this,
444
451
  C: (f, a) => f(...a)
445
452
  });
@@ -449,7 +456,7 @@ var Connection = class {
449
456
  } catch (err2) {
450
457
  import_log.log.catch(err2, void 0, {
451
458
  F: __dxlog_file,
452
- L: 277,
459
+ L: 289,
453
460
  S: this,
454
461
  C: (f, a) => f(...a)
455
462
  });
@@ -473,7 +480,7 @@ var Connection = class {
473
480
  peerId: this.ownId
474
481
  }, {
475
482
  F: __dxlog_file,
476
- L: 302,
483
+ L: 314,
477
484
  S: this,
478
485
  C: (f, a) => f(...a)
479
486
  });
@@ -483,7 +490,7 @@ var Connection = class {
483
490
  } catch (err2) {
484
491
  import_log.log.catch(err2, void 0, {
485
492
  F: __dxlog_file,
486
- L: 309,
493
+ L: 321,
487
494
  S: this,
488
495
  C: (f, a) => f(...a)
489
496
  });
@@ -493,7 +500,7 @@ var Connection = class {
493
500
  } catch (err2) {
494
501
  import_log.log.catch(err2, void 0, {
495
502
  F: __dxlog_file,
496
- L: 316,
503
+ L: 328,
497
504
  S: this,
498
505
  C: (f, a) => f(...a)
499
506
  });
@@ -501,7 +508,7 @@ var Connection = class {
501
508
  } else {
502
509
  import_log.log.info(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
503
510
  F: __dxlog_file,
504
- L: 319,
511
+ L: 331,
505
512
  S: this,
506
513
  C: (f, a) => f(...a)
507
514
  });
@@ -510,7 +517,7 @@ var Connection = class {
510
517
  } catch (err2) {
511
518
  import_log.log.catch(err2, void 0, {
512
519
  F: __dxlog_file,
513
- L: 323,
520
+ L: 335,
514
521
  S: this,
515
522
  C: (f, a) => f(...a)
516
523
  });
@@ -520,7 +527,7 @@ var Connection = class {
520
527
  } catch (err2) {
521
528
  import_log.log.catch(err2, void 0, {
522
529
  F: __dxlog_file,
523
- L: 328,
530
+ L: 340,
524
531
  S: this,
525
532
  C: (f, a) => f(...a)
526
533
  });
@@ -530,7 +537,7 @@ var Connection = class {
530
537
  peerId: this.ownId
531
538
  }, {
532
539
  F: __dxlog_file,
533
- L: 332,
540
+ L: 344,
534
541
  S: this,
535
542
  C: (f, a) => f(...a)
536
543
  });
@@ -573,7 +580,7 @@ var Connection = class {
573
580
  err
574
581
  }, {
575
582
  F: __dxlog_file,
576
- L: 370,
583
+ L: 382,
577
584
  S: this,
578
585
  C: (f, a) => f(...a)
579
586
  });
@@ -586,7 +593,7 @@ var Connection = class {
586
593
  async signal(msg) {
587
594
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
588
595
  F: __dxlog_file,
589
- L: 379,
596
+ L: 391,
590
597
  S: this,
591
598
  A: [
592
599
  "msg.sessionId",
@@ -596,7 +603,7 @@ var Connection = class {
596
603
  if (!msg.sessionId.equals(this.sessionId)) {
597
604
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
598
605
  F: __dxlog_file,
599
- L: 381,
606
+ L: 393,
600
607
  S: this,
601
608
  C: (f, a) => f(...a)
602
609
  });
@@ -604,7 +611,7 @@ var Connection = class {
604
611
  }
605
612
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
606
613
  F: __dxlog_file,
607
- L: 384,
614
+ L: 396,
608
615
  S: this,
609
616
  A: [
610
617
  "msg.data.signal || msg.data.signalBatch",
@@ -613,7 +620,7 @@ var Connection = class {
613
620
  });
614
621
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
615
622
  F: __dxlog_file,
616
- L: 385,
623
+ L: 397,
617
624
  S: this,
618
625
  A: [
619
626
  "msg.author?.equals(this.remoteId)",
@@ -622,7 +629,7 @@ var Connection = class {
622
629
  });
623
630
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
624
631
  F: __dxlog_file,
625
- L: 386,
632
+ L: 398,
626
633
  S: this,
627
634
  A: [
628
635
  "msg.recipient?.equals(this.ownId)",
@@ -646,7 +653,7 @@ var Connection = class {
646
653
  msg: msg.data
647
654
  }, {
648
655
  F: __dxlog_file,
649
- L: 395,
656
+ L: 407,
650
657
  S: this,
651
658
  C: (f, a) => f(...a)
652
659
  });
@@ -654,7 +661,7 @@ var Connection = class {
654
661
  } else {
655
662
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
656
663
  F: __dxlog_file,
657
- L: 398,
664
+ L: 410,
658
665
  S: this,
659
666
  A: [
660
667
  "this._transport",
@@ -667,7 +674,7 @@ var Connection = class {
667
674
  msg: msg.data
668
675
  }, {
669
676
  F: __dxlog_file,
670
- L: 399,
677
+ L: 411,
671
678
  S: this,
672
679
  C: (f, a) => f(...a)
673
680
  });
@@ -685,13 +692,13 @@ var Connection = class {
685
692
  peerId: this.ownId
686
693
  }, {
687
694
  F: __dxlog_file,
688
- L: 410,
695
+ L: 422,
689
696
  S: this,
690
697
  C: (f, a) => f(...a)
691
698
  });
692
699
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
693
700
  F: __dxlog_file,
694
- L: 411,
701
+ L: 423,
695
702
  S: this,
696
703
  A: [
697
704
  "state !== this._state",
@@ -701,7 +708,16 @@ var Connection = class {
701
708
  this._state = state;
702
709
  this.stateChanged.emit(state);
703
710
  }
711
+ async _emitTransportStats() {
712
+ const stats = await this.transport?.getStats();
713
+ if (stats) {
714
+ this.transportStats.emit(stats);
715
+ }
716
+ }
704
717
  };
718
+ _ts_decorate([
719
+ import_log.logInfo
720
+ ], Connection.prototype, "sessionIdString", null);
705
721
  _ts_decorate([
706
722
  import_async.synchronized
707
723
  ], Connection.prototype, "abort", null);
@@ -2090,7 +2106,7 @@ var ConnectionLog = class {
2090
2106
  };
2091
2107
  info.connections.push(connectionInfo);
2092
2108
  this.update.emit();
2093
- connection.stateChanged.on((state) => {
2109
+ connection.stateChanged.on(async (state) => {
2094
2110
  connectionInfo.state = state;
2095
2111
  connectionInfo.closeReason = connection.closeReason;
2096
2112
  connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
@@ -2098,6 +2114,10 @@ var ConnectionLog = class {
2098
2114
  type: EventType.CONNECTION_STATE_CHANGED,
2099
2115
  newState: state
2100
2116
  });
2117
+ if (state === ConnectionState.CONNECTED) {
2118
+ const details = await connection.transport?.getDetails();
2119
+ connectionInfo.transportDetails = details;
2120
+ }
2101
2121
  this.update.emit();
2102
2122
  });
2103
2123
  connection.protocol?.stats?.on((stats) => {
@@ -2107,6 +2127,12 @@ var ConnectionLog = class {
2107
2127
  connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
2108
2128
  this.update.emit();
2109
2129
  });
2130
+ connection.transportStats?.on((stats) => {
2131
+ connectionInfo.transportBytesSent = stats.bytesSent;
2132
+ connectionInfo.transportBytesReceived = stats.bytesReceived;
2133
+ connectionInfo.transportPacketsSent = stats.packetsSent;
2134
+ connectionInfo.transportPacketsReceived = stats.packetsReceived;
2135
+ });
2110
2136
  gcSwarm(info);
2111
2137
  });
2112
2138
  }
@@ -2757,6 +2783,17 @@ var MemoryTransport = class _MemoryTransport {
2757
2783
  this._remote.wake(remoteId);
2758
2784
  }
2759
2785
  }
2786
+ async getDetails() {
2787
+ return this._instanceId.toHex();
2788
+ }
2789
+ async getStats() {
2790
+ return {
2791
+ bytesSent: 0,
2792
+ bytesReceived: 0,
2793
+ packetsSent: 0,
2794
+ packetsReceived: 0
2795
+ };
2796
+ }
2760
2797
  };
2761
2798
  _ts_decorate4([
2762
2799
  import_log10.logInfo
@@ -2774,11 +2811,14 @@ var TransportKind;
2774
2811
  })(TransportKind || (TransportKind = {}));
2775
2812
  var wrtc = null;
2776
2813
  try {
2777
- wrtc = (0, import_chunk_XE5JOIGD.__require)("@koush/wrtc");
2814
+ wrtc = (0, import_chunk_JDKM4UPJ.__require)("@koush/wrtc");
2778
2815
  } catch {
2779
2816
  }
2780
2817
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2781
2818
  var SimplePeerTransport = class {
2819
+ /**
2820
+ * @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
2821
+ */
2782
2822
  constructor(params) {
2783
2823
  this.params = params;
2784
2824
  this._closed = false;
@@ -2791,13 +2831,13 @@ var SimplePeerTransport = class {
2791
2831
  id: this._instanceId
2792
2832
  }), {
2793
2833
  F: __dxlog_file12,
2794
- L: 41,
2834
+ L: 44,
2795
2835
  S: this,
2796
2836
  C: (f, a) => f(...a)
2797
2837
  });
2798
2838
  (0, import_log11.log)("created connection", params, {
2799
2839
  F: __dxlog_file12,
2800
- L: 42,
2840
+ L: 45,
2801
2841
  S: this,
2802
2842
  C: (f, a) => f(...a)
2803
2843
  });
@@ -2810,7 +2850,7 @@ var SimplePeerTransport = class {
2810
2850
  this._peer.on("signal", async (data) => {
2811
2851
  (0, import_log11.log)("signal", data, {
2812
2852
  F: __dxlog_file12,
2813
- L: 51,
2853
+ L: 54,
2814
2854
  S: this,
2815
2855
  C: (f, a) => f(...a)
2816
2856
  });
@@ -2823,7 +2863,7 @@ var SimplePeerTransport = class {
2823
2863
  this._peer.on("connect", () => {
2824
2864
  (0, import_log11.log)("connected", void 0, {
2825
2865
  F: __dxlog_file12,
2826
- L: 56,
2866
+ L: 59,
2827
2867
  S: this,
2828
2868
  C: (f, a) => f(...a)
2829
2869
  });
@@ -2834,7 +2874,7 @@ var SimplePeerTransport = class {
2834
2874
  this._peer.on("close", async () => {
2835
2875
  (0, import_log11.log)("closed", void 0, {
2836
2876
  F: __dxlog_file12,
2837
- L: 63,
2877
+ L: 66,
2838
2878
  S: this,
2839
2879
  C: (f, a) => f(...a)
2840
2880
  });
@@ -2849,7 +2889,7 @@ var SimplePeerTransport = class {
2849
2889
  err
2850
2890
  }, {
2851
2891
  F: __dxlog_file12,
2852
- L: 74,
2892
+ L: 77,
2853
2893
  S: this,
2854
2894
  C: (f, a) => f(...a)
2855
2895
  });
@@ -2858,7 +2898,7 @@ var SimplePeerTransport = class {
2858
2898
  } else if ("code" in err) {
2859
2899
  import_log11.log.info("simple-peer error", err, {
2860
2900
  F: __dxlog_file12,
2861
- L: 79,
2901
+ L: 82,
2862
2902
  S: this,
2863
2903
  C: (f, a) => f(...a)
2864
2904
  });
@@ -2888,7 +2928,7 @@ var SimplePeerTransport = class {
2888
2928
  } else {
2889
2929
  import_log11.log.info("unknown peer connection error", err, {
2890
2930
  F: __dxlog_file12,
2891
- L: 105,
2931
+ L: 108,
2892
2932
  S: this,
2893
2933
  C: (f, a) => f(...a)
2894
2934
  });
@@ -2899,10 +2939,10 @@ var SimplePeerTransport = class {
2899
2939
  this._peer._pc.getStats().then((stats) => {
2900
2940
  import_log11.log.info("report after webrtc error", {
2901
2941
  config: this.params.webrtcConfig,
2902
- stats
2942
+ stats: Object.fromEntries(stats.entries())
2903
2943
  }, {
2904
2944
  F: __dxlog_file12,
2905
- L: 113,
2945
+ L: 116,
2906
2946
  S: this,
2907
2947
  C: (f, a) => f(...a)
2908
2948
  });
@@ -2911,7 +2951,7 @@ var SimplePeerTransport = class {
2911
2951
  } catch (err2) {
2912
2952
  import_log11.log.catch(err2, void 0, {
2913
2953
  F: __dxlog_file12,
2914
- L: 120,
2954
+ L: 123,
2915
2955
  S: this,
2916
2956
  C: (f, a) => f(...a)
2917
2957
  });
@@ -2922,15 +2962,68 @@ var SimplePeerTransport = class {
2922
2962
  id: this._instanceId
2923
2963
  }), {
2924
2964
  F: __dxlog_file12,
2925
- L: 125,
2965
+ L: 129,
2926
2966
  S: this,
2927
2967
  C: (f, a) => f(...a)
2928
2968
  });
2929
2969
  }
2970
+ async getStats() {
2971
+ const stats = await this._getStats();
2972
+ if (!stats) {
2973
+ return {
2974
+ bytesSent: 0,
2975
+ bytesReceived: 0,
2976
+ packetsSent: 0,
2977
+ packetsReceived: 0,
2978
+ rawStats: {}
2979
+ };
2980
+ }
2981
+ return {
2982
+ bytesSent: stats.transport.bytesSent,
2983
+ bytesReceived: stats.transport.bytesReceived,
2984
+ packetsSent: stats.transport.messagesSent,
2985
+ packetsReceived: stats.transport.messagesReceived,
2986
+ rawStats: stats.raw
2987
+ };
2988
+ }
2989
+ async _getStats() {
2990
+ if (typeof this._peer?._pc?.getStats !== "function") {
2991
+ return null;
2992
+ }
2993
+ return await this._peer._pc.getStats().then((stats) => {
2994
+ const statsEntries = Array.from(stats.entries());
2995
+ const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
2996
+ const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
2997
+ let selectedCandidatePair;
2998
+ let remoteCandidate;
2999
+ if (candidatePair.length > 0) {
3000
+ selectedCandidatePair = candidatePair[0][1];
3001
+ remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
3002
+ }
3003
+ return {
3004
+ datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
3005
+ transport,
3006
+ selectedCandidatePair,
3007
+ remoteCandidate,
3008
+ raw: Object.fromEntries(stats.entries())
3009
+ };
3010
+ });
3011
+ }
3012
+ async getDetails() {
3013
+ const stats = await this._getStats();
3014
+ const rc = stats?.remoteCandidate;
3015
+ if (!rc) {
3016
+ return "unavailable";
3017
+ }
3018
+ if (rc.relay) {
3019
+ return `${rc.ip}:${rc.port}/${rc.protocol} relay for XXX ${rc.candidateType}`;
3020
+ }
3021
+ return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
3022
+ }
2930
3023
  async destroy() {
2931
3024
  (0, import_log11.log)("closing...", void 0, {
2932
3025
  F: __dxlog_file12,
2933
- L: 129,
3026
+ L: 192,
2934
3027
  S: this,
2935
3028
  C: (f, a) => f(...a)
2936
3029
  });
@@ -2940,10 +3033,11 @@ var SimplePeerTransport = class {
2940
3033
  this._closed = true;
2941
3034
  this._disconnectStreams();
2942
3035
  this._peer.destroy();
3036
+ this._closed = true;
2943
3037
  this.closed.emit();
2944
3038
  (0, import_log11.log)("closed", void 0, {
2945
3039
  F: __dxlog_file12,
2946
- L: 137,
3040
+ L: 201,
2947
3041
  S: this,
2948
3042
  C: (f, a) => f(...a)
2949
3043
  });
@@ -3049,7 +3143,7 @@ var SimplePeerTransportService = class {
3049
3143
  async sendSignal({ proxyId, signal }) {
3050
3144
  (0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
3051
3145
  F: __dxlog_file13,
3052
- L: 112,
3146
+ L: 116,
3053
3147
  S: this,
3054
3148
  A: [
3055
3149
  "this.transports.has(proxyId)",
@@ -3058,18 +3152,46 @@ var SimplePeerTransportService = class {
3058
3152
  });
3059
3153
  await this.transports.get(proxyId).transport.signal(signal);
3060
3154
  }
3155
+ async getDetails({ proxyId }) {
3156
+ (0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
3157
+ F: __dxlog_file13,
3158
+ L: 121,
3159
+ S: this,
3160
+ A: [
3161
+ "this.transports.has(proxyId)",
3162
+ ""
3163
+ ]
3164
+ });
3165
+ return {
3166
+ details: await this.transports.get(proxyId).transport.getDetails()
3167
+ };
3168
+ }
3169
+ async getStats({ proxyId }) {
3170
+ (0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
3171
+ F: __dxlog_file13,
3172
+ L: 126,
3173
+ S: this,
3174
+ A: [
3175
+ "this.transports.has(proxyId)",
3176
+ ""
3177
+ ]
3178
+ });
3179
+ return {
3180
+ stats: await this.transports.get(proxyId).transport.getStats()
3181
+ };
3182
+ }
3061
3183
  async sendData({ proxyId, payload }) {
3062
3184
  if (this.transports.get(proxyId)?.state !== "OPEN") {
3063
3185
  import_log12.log.debug("transport is closed", void 0, {
3064
3186
  F: __dxlog_file13,
3065
- L: 118,
3187
+ L: 132,
3066
3188
  S: this,
3067
3189
  C: (f, a) => f(...a)
3068
3190
  });
3069
3191
  }
3070
3192
  (0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
3071
3193
  F: __dxlog_file13,
3072
- L: 120,
3194
+ L: 134,
3073
3195
  S: this,
3074
3196
  A: [
3075
3197
  "this.transports.has(proxyId)",
@@ -3092,7 +3214,7 @@ var SimplePeerTransportService = class {
3092
3214
  }
3093
3215
  (0, import_log12.log)("Closed.", void 0, {
3094
3216
  F: __dxlog_file13,
3095
- L: 136,
3217
+ L: 150,
3096
3218
  S: this,
3097
3219
  C: (f, a) => f(...a)
3098
3220
  });
@@ -3219,6 +3341,16 @@ var SimplePeerTransportProxy = class {
3219
3341
  signal
3220
3342
  }).catch((err) => this.errors.raise(decodeError(err)));
3221
3343
  }
3344
+ async getDetails() {
3345
+ return (await this._params.bridgeService.getDetails({
3346
+ proxyId: this._proxyId
3347
+ })).details;
3348
+ }
3349
+ async getStats() {
3350
+ return (await this._params.bridgeService.getStats({
3351
+ proxyId: this._proxyId
3352
+ })).stats;
3353
+ }
3222
3354
  // TODO(burdon): Move open from constructor.
3223
3355
  async destroy() {
3224
3356
  await this._ctx.dispose();
@@ -3233,7 +3365,7 @@ var SimplePeerTransportProxy = class {
3233
3365
  } catch (err) {
3234
3366
  import_log13.log.catch(err, void 0, {
3235
3367
  F: __dxlog_file14,
3236
- L: 160,
3368
+ L: 168,
3237
3369
  S: this,
3238
3370
  C: (f, a) => f(...a)
3239
3371
  });
@@ -3269,7 +3401,7 @@ var SimplePeerTransportProxyFactory = class {
3269
3401
  createTransport(options) {
3270
3402
  (0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3271
3403
  F: __dxlog_file14,
3272
- L: 197,
3404
+ L: 205,
3273
3405
  S: this,
3274
3406
  A: [
3275
3407
  "this._bridgeService",
@@ -3326,7 +3458,7 @@ var LibDataChannelTransport = class {
3326
3458
  this._readyForCandidates = new import_async11.Trigger();
3327
3459
  this._writeCallback = null;
3328
3460
  this._peer = (async () => {
3329
- const { RTCPeerConnection: PeerConnection } = await import("./datachannel-53JZPGFA.cjs");
3461
+ const { RTCPeerConnection: PeerConnection } = await import("./datachannel-3VTTIMR5.cjs");
3330
3462
  if (this._closed) {
3331
3463
  this.errors.raise(new Error("connection already closed"));
3332
3464
  }
@@ -3622,6 +3754,46 @@ var LibDataChannelTransport = class {
3622
3754
  });
3623
3755
  });
3624
3756
  }
3757
+ async getDetails() {
3758
+ return this._peer.then(async (peer) => {
3759
+ const cp = await peer.getSelectedCandidatePair();
3760
+ if (!cp) {
3761
+ return "unavailable";
3762
+ }
3763
+ return `${cp.remote.address}:${cp.remote.port}/${cp.remote.transportType} ${cp.remote.type}`;
3764
+ }).catch((err) => {
3765
+ import_log14.log.catch(err, void 0, {
3766
+ F: __dxlog_file15,
3767
+ L: 250,
3768
+ S: this,
3769
+ C: (f, a) => f(...a)
3770
+ });
3771
+ return "unavailable";
3772
+ });
3773
+ }
3774
+ async getStats() {
3775
+ return this._peer.then((peer) => {
3776
+ return {
3777
+ bytesSent: peer.bytesSent(),
3778
+ bytesReceived: peer.bytesReceived(),
3779
+ packetsSent: 0,
3780
+ packetsReceived: 0
3781
+ };
3782
+ }).catch((err) => {
3783
+ import_log14.log.catch(err, void 0, {
3784
+ F: __dxlog_file15,
3785
+ L: 266,
3786
+ S: this,
3787
+ C: (f, a) => f(...a)
3788
+ });
3789
+ return {
3790
+ bytesSent: 0,
3791
+ bytesReceived: 0,
3792
+ packetsSent: 0,
3793
+ packetsReceived: 0
3794
+ };
3795
+ });
3796
+ }
3625
3797
  // TODO(nf): add classmethod to call node-datachannel.cleanup() when all instances have been destroyed?
3626
3798
  async destroy() {
3627
3799
  await this._close();
@@ -3731,13 +3903,29 @@ var TcpTransport = class {
3731
3903
  host: "localhost"
3732
3904
  });
3733
3905
  }
3906
+ async getDetails() {
3907
+ if (this.options.initiator) {
3908
+ const { port: port2, address: address2 } = this._server?.address();
3909
+ return `LISTEN ${address2}:${port2}`;
3910
+ }
3911
+ const { port, address } = this._socket?.address();
3912
+ return `ACCEPT ${address}:${port}`;
3913
+ }
3914
+ async getStats() {
3915
+ return {
3916
+ bytesSent: 0,
3917
+ bytesReceived: 0,
3918
+ packetsSent: 0,
3919
+ packetsReceived: 0
3920
+ };
3921
+ }
3734
3922
  _handleSocket(socket) {
3735
3923
  (0, import_log15.log)("handling socket", {
3736
3924
  remotePort: socket.remotePort,
3737
3925
  localPort: socket.localPort
3738
3926
  }, {
3739
3927
  F: __dxlog_file16,
3740
- L: 91,
3928
+ L: 109,
3741
3929
  S: this,
3742
3930
  C: (f, a) => f(...a)
3743
3931
  });
@@ -3749,7 +3937,7 @@ var TcpTransport = class {
3749
3937
  port: this._socket?.remotePort
3750
3938
  }, {
3751
3939
  F: __dxlog_file16,
3752
- L: 97,
3940
+ L: 115,
3753
3941
  S: this,
3754
3942
  C: (f, a) => f(...a)
3755
3943
  });
@@ -3768,8 +3956,8 @@ var createTeleportProtocolFactory = (onConnection) => {
3768
3956
  const teleport = new import_teleport.Teleport(params);
3769
3957
  return {
3770
3958
  stream: teleport.stream,
3771
- open: async () => {
3772
- await teleport.open();
3959
+ open: async (sessionId) => {
3960
+ await teleport.open(sessionId);
3773
3961
  await onConnection(teleport);
3774
3962
  },
3775
3963
  close: async () => {
@@ -3810,4 +3998,4 @@ var createTeleportProtocolFactory = (onConnection) => {
3810
3998
  createSimplePeerTransportFactory,
3811
3999
  createTeleportProtocolFactory
3812
4000
  });
3813
- //# sourceMappingURL=chunk-6AD7QA4X.cjs.map
4001
+ //# sourceMappingURL=chunk-XZF4MAFB.cjs.map