@dxos/network-manager 0.3.9-main.b7e6a67 → 0.3.9-main.cab5453

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.
@@ -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_QWUG7JSH_exports = {};
30
- __export(chunk_QWUG7JSH_exports, {
29
+ var chunk_6AD7QA4X_exports = {};
30
+ __export(chunk_6AD7QA4X_exports, {
31
31
  Connection: () => Connection,
32
32
  ConnectionLimiter: () => ConnectionLimiter,
33
33
  ConnectionLog: () => ConnectionLog,
@@ -55,7 +55,7 @@ __export(chunk_QWUG7JSH_exports, {
55
55
  createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
56
56
  createTeleportProtocolFactory: () => createTeleportProtocolFactory
57
57
  });
58
- module.exports = __toCommonJS(chunk_QWUG7JSH_exports);
58
+ module.exports = __toCommonJS(chunk_6AD7QA4X_exports);
59
59
  var import_chunk_XE5JOIGD = require("./chunk-XE5JOIGD.cjs");
60
60
  var import_async = require("@dxos/async");
61
61
  var import_context = require("@dxos/context");
@@ -240,7 +240,7 @@ var Connection = class {
240
240
  initiator: this.initiator
241
241
  }, {
242
242
  F: __dxlog_file,
243
- L: 129,
243
+ L: 130,
244
244
  S: this,
245
245
  C: (f, a) => f(...a)
246
246
  });
@@ -260,7 +260,7 @@ var Connection = class {
260
260
  async openConnection() {
261
261
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
262
262
  F: __dxlog_file,
263
- L: 154,
263
+ L: 155,
264
264
  S: this,
265
265
  A: [
266
266
  "this._state === ConnectionState.INITIAL",
@@ -271,7 +271,7 @@ var Connection = class {
271
271
  id: this._instanceId
272
272
  }), {
273
273
  F: __dxlog_file,
274
- L: 155,
274
+ L: 156,
275
275
  S: this,
276
276
  C: (f, a) => f(...a)
277
277
  });
@@ -283,7 +283,7 @@ var Connection = class {
283
283
  initiator: this.initiator
284
284
  }, {
285
285
  F: __dxlog_file,
286
- L: 156,
286
+ L: 157,
287
287
  S: this,
288
288
  C: (f, a) => f(...a)
289
289
  });
@@ -294,24 +294,24 @@ var Connection = class {
294
294
  this._protocol.stream.on("close", () => {
295
295
  (0, import_log.log)("protocol stream closed", void 0, {
296
296
  F: __dxlog_file,
297
- L: 173,
297
+ L: 174,
298
298
  S: this,
299
299
  C: (f, a) => f(...a)
300
300
  });
301
301
  this.close(new import_protocols.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
302
302
  });
303
303
  (0, import_async.scheduleTask)(this.connectedTimeoutContext, async () => {
304
- import_log.log.info("timeout waiting for transport to connect, aborting", void 0, {
304
+ import_log.log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
305
305
  F: __dxlog_file,
306
- L: 180,
306
+ L: 181,
307
307
  S: this,
308
308
  C: (f, a) => f(...a)
309
309
  });
310
- await this.abort().catch((err) => this.errors.raise(err));
310
+ await this.abort(new import_protocols.TimeoutError(`${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`)).catch((err) => this.errors.raise(err));
311
311
  }, TRANSPORT_CONNECTION_TIMEOUT);
312
312
  (0, import_invariant.invariant)(!this._transport, void 0, {
313
313
  F: __dxlog_file,
314
- L: 186,
314
+ L: 189,
315
315
  S: this,
316
316
  A: [
317
317
  "!this._transport",
@@ -332,7 +332,7 @@ var Connection = class {
332
332
  this._transport = void 0;
333
333
  (0, import_log.log)("abort triggered by transport close", void 0, {
334
334
  F: __dxlog_file,
335
- L: 201,
335
+ L: 204,
336
336
  S: this,
337
337
  C: (f, a) => f(...a)
338
338
  });
@@ -343,7 +343,7 @@ var Connection = class {
343
343
  err
344
344
  }, {
345
345
  F: __dxlog_file,
346
- L: 206,
346
+ L: 209,
347
347
  S: this,
348
348
  C: (f, a) => f(...a)
349
349
  });
@@ -353,7 +353,7 @@ var Connection = class {
353
353
  if (err instanceof import_protocols.ConnectionResetError) {
354
354
  import_log.log.info("aborting due to transport ConnectionResetError", void 0, {
355
355
  F: __dxlog_file,
356
- L: 213,
356
+ L: 216,
357
357
  S: this,
358
358
  C: (f, a) => f(...a)
359
359
  });
@@ -361,7 +361,7 @@ var Connection = class {
361
361
  } else if (err instanceof import_protocols.ConnectivityError) {
362
362
  import_log.log.info("aborting due to transport ConnectivityError", void 0, {
363
363
  F: __dxlog_file,
364
- L: 216,
364
+ L: 219,
365
365
  S: this,
366
366
  C: (f, a) => f(...a)
367
367
  });
@@ -371,7 +371,7 @@ var Connection = class {
371
371
  err
372
372
  }, {
373
373
  F: __dxlog_file,
374
- L: 219,
374
+ L: 222,
375
375
  S: this,
376
376
  C: (f, a) => f(...a)
377
377
  });
@@ -389,7 +389,7 @@ var Connection = class {
389
389
  id: this._instanceId
390
390
  }), {
391
391
  F: __dxlog_file,
392
- L: 235,
392
+ L: 238,
393
393
  S: this,
394
394
  C: (f, a) => f(...a)
395
395
  });
@@ -399,14 +399,14 @@ var Connection = class {
399
399
  err
400
400
  }, {
401
401
  F: __dxlog_file,
402
- L: 242,
402
+ L: 245,
403
403
  S: this,
404
404
  C: (f, a) => f(...a)
405
405
  });
406
406
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
407
407
  (0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
408
408
  F: __dxlog_file,
409
- L: 244,
409
+ L: 247,
410
410
  S: this,
411
411
  C: (f, a) => f(...a)
412
412
  });
@@ -421,7 +421,7 @@ var Connection = class {
421
421
  try {
422
422
  (0, import_log.log)("aborting protocol... ", void 0, {
423
423
  F: __dxlog_file,
424
- L: 258,
424
+ L: 261,
425
425
  S: this,
426
426
  C: (f, a) => f(...a)
427
427
  });
@@ -429,7 +429,7 @@ var Connection = class {
429
429
  } catch (err2) {
430
430
  import_log.log.catch(err2, void 0, {
431
431
  F: __dxlog_file,
432
- L: 261,
432
+ L: 264,
433
433
  S: this,
434
434
  C: (f, a) => f(...a)
435
435
  });
@@ -439,7 +439,7 @@ var Connection = class {
439
439
  } catch (err2) {
440
440
  import_log.log.catch(err2, void 0, {
441
441
  F: __dxlog_file,
442
- L: 268,
442
+ L: 271,
443
443
  S: this,
444
444
  C: (f, a) => f(...a)
445
445
  });
@@ -449,7 +449,7 @@ var Connection = class {
449
449
  } catch (err2) {
450
450
  import_log.log.catch(err2, void 0, {
451
451
  F: __dxlog_file,
452
- L: 274,
452
+ L: 277,
453
453
  S: this,
454
454
  C: (f, a) => f(...a)
455
455
  });
@@ -473,7 +473,7 @@ var Connection = class {
473
473
  peerId: this.ownId
474
474
  }, {
475
475
  F: __dxlog_file,
476
- L: 299,
476
+ L: 302,
477
477
  S: this,
478
478
  C: (f, a) => f(...a)
479
479
  });
@@ -483,7 +483,7 @@ var Connection = class {
483
483
  } catch (err2) {
484
484
  import_log.log.catch(err2, void 0, {
485
485
  F: __dxlog_file,
486
- L: 306,
486
+ L: 309,
487
487
  S: this,
488
488
  C: (f, a) => f(...a)
489
489
  });
@@ -493,7 +493,34 @@ var Connection = class {
493
493
  } catch (err2) {
494
494
  import_log.log.catch(err2, void 0, {
495
495
  F: __dxlog_file,
496
- L: 313,
496
+ L: 316,
497
+ S: this,
498
+ C: (f, a) => f(...a)
499
+ });
500
+ }
501
+ } else {
502
+ import_log.log.info(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
503
+ F: __dxlog_file,
504
+ L: 319,
505
+ S: this,
506
+ C: (f, a) => f(...a)
507
+ });
508
+ try {
509
+ await this._protocol.abort();
510
+ } catch (err2) {
511
+ import_log.log.catch(err2, void 0, {
512
+ F: __dxlog_file,
513
+ L: 323,
514
+ S: this,
515
+ C: (f, a) => f(...a)
516
+ });
517
+ }
518
+ try {
519
+ await this._transport?.destroy();
520
+ } catch (err2) {
521
+ import_log.log.catch(err2, void 0, {
522
+ F: __dxlog_file,
523
+ L: 328,
497
524
  S: this,
498
525
  C: (f, a) => f(...a)
499
526
  });
@@ -503,7 +530,7 @@ var Connection = class {
503
530
  peerId: this.ownId
504
531
  }, {
505
532
  F: __dxlog_file,
506
- L: 317,
533
+ L: 332,
507
534
  S: this,
508
535
  C: (f, a) => f(...a)
509
536
  });
@@ -546,7 +573,7 @@ var Connection = class {
546
573
  err
547
574
  }, {
548
575
  F: __dxlog_file,
549
- L: 355,
576
+ L: 370,
550
577
  S: this,
551
578
  C: (f, a) => f(...a)
552
579
  });
@@ -559,7 +586,7 @@ var Connection = class {
559
586
  async signal(msg) {
560
587
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
561
588
  F: __dxlog_file,
562
- L: 364,
589
+ L: 379,
563
590
  S: this,
564
591
  A: [
565
592
  "msg.sessionId",
@@ -569,7 +596,7 @@ var Connection = class {
569
596
  if (!msg.sessionId.equals(this.sessionId)) {
570
597
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
571
598
  F: __dxlog_file,
572
- L: 366,
599
+ L: 381,
573
600
  S: this,
574
601
  C: (f, a) => f(...a)
575
602
  });
@@ -577,7 +604,7 @@ var Connection = class {
577
604
  }
578
605
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
579
606
  F: __dxlog_file,
580
- L: 369,
607
+ L: 384,
581
608
  S: this,
582
609
  A: [
583
610
  "msg.data.signal || msg.data.signalBatch",
@@ -586,7 +613,7 @@ var Connection = class {
586
613
  });
587
614
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
588
615
  F: __dxlog_file,
589
- L: 370,
616
+ L: 385,
590
617
  S: this,
591
618
  A: [
592
619
  "msg.author?.equals(this.remoteId)",
@@ -595,7 +622,7 @@ var Connection = class {
595
622
  });
596
623
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
597
624
  F: __dxlog_file,
598
- L: 371,
625
+ L: 386,
599
626
  S: this,
600
627
  A: [
601
628
  "msg.recipient?.equals(this.ownId)",
@@ -619,7 +646,7 @@ var Connection = class {
619
646
  msg: msg.data
620
647
  }, {
621
648
  F: __dxlog_file,
622
- L: 380,
649
+ L: 395,
623
650
  S: this,
624
651
  C: (f, a) => f(...a)
625
652
  });
@@ -627,7 +654,7 @@ var Connection = class {
627
654
  } else {
628
655
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
629
656
  F: __dxlog_file,
630
- L: 383,
657
+ L: 398,
631
658
  S: this,
632
659
  A: [
633
660
  "this._transport",
@@ -640,7 +667,7 @@ var Connection = class {
640
667
  msg: msg.data
641
668
  }, {
642
669
  F: __dxlog_file,
643
- L: 384,
670
+ L: 399,
644
671
  S: this,
645
672
  C: (f, a) => f(...a)
646
673
  });
@@ -658,13 +685,13 @@ var Connection = class {
658
685
  peerId: this.ownId
659
686
  }, {
660
687
  F: __dxlog_file,
661
- L: 395,
688
+ L: 410,
662
689
  S: this,
663
690
  C: (f, a) => f(...a)
664
691
  });
665
692
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
666
693
  F: __dxlog_file,
667
- L: 396,
694
+ L: 411,
668
695
  S: this,
669
696
  A: [
670
697
  "state !== this._state",
@@ -2818,12 +2845,20 @@ var SimplePeerTransport = class {
2818
2845
  if (err.errorDetail === "sctp-failure") {
2819
2846
  this.errors.raise(new import_protocols7.ConnectionResetError("sctp-failure from RTCError", err));
2820
2847
  } else {
2848
+ import_log11.log.info("unknown RTCError", {
2849
+ err
2850
+ }, {
2851
+ F: __dxlog_file12,
2852
+ L: 74,
2853
+ S: this,
2854
+ C: (f, a) => f(...a)
2855
+ });
2821
2856
  this.errors.raise(new import_protocols7.UnknownProtocolError("unknown RTCError", err));
2822
2857
  }
2823
2858
  } else if ("code" in err) {
2824
2859
  import_log11.log.info("simple-peer error", err, {
2825
2860
  F: __dxlog_file12,
2826
- L: 78,
2861
+ L: 79,
2827
2862
  S: this,
2828
2863
  C: (f, a) => f(...a)
2829
2864
  });
@@ -2831,10 +2866,12 @@ var SimplePeerTransport = class {
2831
2866
  case "ERR_WEBRTC_SUPPORT":
2832
2867
  this.errors.raise(new import_protocols7.ProtocolError("WebRTC not supported", err));
2833
2868
  break;
2869
+ case "ERR_SIGNALING":
2870
+ this.errors.raise(new import_protocols7.ConnectivityError("signaling failure", err));
2871
+ break;
2834
2872
  case "ERR_ICE_CONNECTION_FAILURE":
2835
2873
  case "ERR_DATA_CHANNEL":
2836
2874
  case "ERR_CONNECTION_FAILURE":
2837
- case "ERR_SIGNALING":
2838
2875
  this.errors.raise(new import_protocols7.ConnectivityError("unknown communication failure", err));
2839
2876
  break;
2840
2877
  case "ERR_CREATE_OFFER":
@@ -2851,7 +2888,7 @@ var SimplePeerTransport = class {
2851
2888
  } else {
2852
2889
  import_log11.log.info("unknown peer connection error", err, {
2853
2890
  F: __dxlog_file12,
2854
- L: 102,
2891
+ L: 105,
2855
2892
  S: this,
2856
2893
  C: (f, a) => f(...a)
2857
2894
  });
@@ -2865,7 +2902,7 @@ var SimplePeerTransport = class {
2865
2902
  stats
2866
2903
  }, {
2867
2904
  F: __dxlog_file12,
2868
- L: 110,
2905
+ L: 113,
2869
2906
  S: this,
2870
2907
  C: (f, a) => f(...a)
2871
2908
  });
@@ -2874,7 +2911,7 @@ var SimplePeerTransport = class {
2874
2911
  } catch (err2) {
2875
2912
  import_log11.log.catch(err2, void 0, {
2876
2913
  F: __dxlog_file12,
2877
- L: 117,
2914
+ L: 120,
2878
2915
  S: this,
2879
2916
  C: (f, a) => f(...a)
2880
2917
  });
@@ -2885,7 +2922,7 @@ var SimplePeerTransport = class {
2885
2922
  id: this._instanceId
2886
2923
  }), {
2887
2924
  F: __dxlog_file12,
2888
- L: 122,
2925
+ L: 125,
2889
2926
  S: this,
2890
2927
  C: (f, a) => f(...a)
2891
2928
  });
@@ -2893,7 +2930,7 @@ var SimplePeerTransport = class {
2893
2930
  async destroy() {
2894
2931
  (0, import_log11.log)("closing...", void 0, {
2895
2932
  F: __dxlog_file12,
2896
- L: 126,
2933
+ L: 129,
2897
2934
  S: this,
2898
2935
  C: (f, a) => f(...a)
2899
2936
  });
@@ -2906,7 +2943,7 @@ var SimplePeerTransport = class {
2906
2943
  this.closed.emit();
2907
2944
  (0, import_log11.log)("closed", void 0, {
2908
2945
  F: __dxlog_file12,
2909
- L: 134,
2946
+ L: 137,
2910
2947
  S: this,
2911
2948
  C: (f, a) => f(...a)
2912
2949
  });
@@ -3427,16 +3464,21 @@ var LibDataChannelTransport = class {
3427
3464
  const duplex = new import_stream.Duplex({
3428
3465
  read: () => {
3429
3466
  },
3430
- write: (chunk, encoding, callback) => {
3467
+ write: async (chunk, encoding, callback) => {
3431
3468
  if (chunk.length > MAX_MESSAGE_SIZE) {
3432
3469
  this.errors.raise(new Error(`message too large: ${chunk.length} > ${MAX_MESSAGE_SIZE}`));
3433
3470
  }
3434
- dataChannel.send(chunk);
3471
+ try {
3472
+ dataChannel.send(chunk);
3473
+ } catch (err) {
3474
+ this.errors.raise(err);
3475
+ await this._close();
3476
+ }
3435
3477
  if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3436
3478
  if (this._writeCallback !== null) {
3437
3479
  import_log14.log.error("consumer trying to write before we're ready for more data", void 0, {
3438
3480
  F: __dxlog_file15,
3439
- L: 139,
3481
+ L: 143,
3440
3482
  S: this,
3441
3483
  C: (f, a) => f(...a)
3442
3484
  });
@@ -3461,7 +3503,7 @@ var LibDataChannelTransport = class {
3461
3503
  err
3462
3504
  }, {
3463
3505
  F: __dxlog_file15,
3464
- L: 159,
3506
+ L: 163,
3465
3507
  S: this,
3466
3508
  C: (f, a) => f(...a)
3467
3509
  });
@@ -3498,7 +3540,7 @@ var LibDataChannelTransport = class {
3498
3540
  peer
3499
3541
  }, {
3500
3542
  F: __dxlog_file15,
3501
- L: 194,
3543
+ L: 198,
3502
3544
  S: this,
3503
3545
  C: (f, a) => f(...a)
3504
3546
  });
@@ -3526,7 +3568,7 @@ var LibDataChannelTransport = class {
3526
3568
  err
3527
3569
  }, {
3528
3570
  F: __dxlog_file15,
3529
- L: 205,
3571
+ L: 209,
3530
3572
  S: this,
3531
3573
  C: (f, a) => f(...a)
3532
3574
  });
@@ -3546,7 +3588,7 @@ var LibDataChannelTransport = class {
3546
3588
  err
3547
3589
  }, {
3548
3590
  F: __dxlog_file15,
3549
- L: 216,
3591
+ L: 220,
3550
3592
  S: this,
3551
3593
  C: (f, a) => f(...a)
3552
3594
  });
@@ -3565,7 +3607,7 @@ var LibDataChannelTransport = class {
3565
3607
  signal
3566
3608
  }, {
3567
3609
  F: __dxlog_file15,
3568
- L: 227,
3610
+ L: 231,
3569
3611
  S: this,
3570
3612
  C: (f, a) => f(...a)
3571
3613
  });
@@ -3574,7 +3616,7 @@ var LibDataChannelTransport = class {
3574
3616
  }).catch((err) => {
3575
3617
  import_log14.log.catch(err, void 0, {
3576
3618
  F: __dxlog_file15,
3577
- L: 232,
3619
+ L: 236,
3578
3620
  S: this,
3579
3621
  C: (f, a) => f(...a)
3580
3622
  });
@@ -3768,4 +3810,4 @@ var createTeleportProtocolFactory = (onConnection) => {
3768
3810
  createSimplePeerTransportFactory,
3769
3811
  createTeleportProtocolFactory
3770
3812
  });
3771
- //# sourceMappingURL=chunk-QWUG7JSH.cjs.map
3813
+ //# sourceMappingURL=chunk-6AD7QA4X.cjs.map