@dxos/network-manager 0.1.58-main.ffbb8a1 → 0.1.58-next.3349da8

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 (33) hide show
  1. package/dist/lib/browser/{chunk-VP6DWC3F.mjs → chunk-PSWNMALH.mjs} +180 -93
  2. package/dist/lib/browser/chunk-PSWNMALH.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 +155 -22
  6. package/dist/lib/browser/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +177 -90
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +332 -112
  11. package/dist/lib/node/testing/index.cjs.map +4 -4
  12. package/dist/types/src/swarm/connection.d.ts +3 -1
  13. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  14. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  15. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  16. package/dist/types/src/tests/tcp-transport.test.d.ts +2 -0
  17. package/dist/types/src/tests/tcp-transport.test.d.ts.map +1 -0
  18. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  19. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  20. package/dist/types/src/transport/tcp-transport.d.ts +23 -0
  21. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -0
  22. package/dist/types/src/transport/transport.d.ts +2 -1
  23. package/dist/types/src/transport/transport.d.ts.map +1 -1
  24. package/package.json +18 -18
  25. package/src/swarm/connection.ts +52 -26
  26. package/src/swarm/peer.ts +4 -1
  27. package/src/testing/test-builder.ts +5 -1
  28. package/src/tests/tcp-transport.test.ts +67 -0
  29. package/src/transport/simplepeer-transport-proxy.ts +28 -2
  30. package/src/transport/simplepeer-transport.ts +39 -2
  31. package/src/transport/tcp-transport.ts +107 -0
  32. package/src/transport/transport.ts +1 -0
  33. package/dist/lib/browser/chunk-VP6DWC3F.mjs.map +0 -7
@@ -602,6 +602,8 @@ var ConnectionState;
602
602
  */
603
603
  "CLOSED"
604
604
  ] = "CLOSED";
605
+ ConnectionState5["ABORTING"] = "ABORTING";
606
+ ConnectionState5["ABORTED"] = "ABORTED";
605
607
  })(ConnectionState || (ConnectionState = {}));
606
608
  var Connection = class {
607
609
  constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
@@ -633,7 +635,7 @@ var Connection = class {
633
635
  initiator: this.initiator
634
636
  }, {
635
637
  F: __dxlog_file,
636
- L: 114,
638
+ L: 123,
637
639
  S: this,
638
640
  C: (f, a) => f(...a)
639
641
  });
@@ -653,7 +655,7 @@ var Connection = class {
653
655
  async openConnection() {
654
656
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
655
657
  F: __dxlog_file,
656
- L: 139,
658
+ L: 148,
657
659
  S: this,
658
660
  A: [
659
661
  "this._state === ConnectionState.INITIAL",
@@ -664,7 +666,7 @@ var Connection = class {
664
666
  id: this._instanceId
665
667
  }), {
666
668
  F: __dxlog_file,
667
- L: 140,
669
+ L: 149,
668
670
  S: this,
669
671
  C: (f, a) => f(...a)
670
672
  });
@@ -676,7 +678,7 @@ var Connection = class {
676
678
  initiator: this.initiator
677
679
  }, {
678
680
  F: __dxlog_file,
679
- L: 141,
681
+ L: 150,
680
682
  S: this,
681
683
  C: (f, a) => f(...a)
682
684
  });
@@ -687,15 +689,15 @@ var Connection = class {
687
689
  this._protocol.stream.on("close", () => {
688
690
  (0, import_log.log)("protocol stream closed", void 0, {
689
691
  F: __dxlog_file,
690
- L: 158,
692
+ L: 167,
691
693
  S: this,
692
694
  C: (f, a) => f(...a)
693
695
  });
694
- this.close().catch((err) => this.errors.raise(err));
696
+ this.close(new import_errors.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
695
697
  });
696
698
  (0, import_invariant.invariant)(!this._transport, void 0, {
697
699
  F: __dxlog_file,
698
- L: 162,
700
+ L: 171,
699
701
  S: this,
700
702
  A: [
701
703
  "!this._transport",
@@ -715,7 +717,7 @@ var Connection = class {
715
717
  this._transport = void 0;
716
718
  (0, import_log.log)("abort triggered by transport close", void 0, {
717
719
  F: __dxlog_file,
718
- L: 176,
720
+ L: 185,
719
721
  S: this,
720
722
  C: (f, a) => f(...a)
721
723
  });
@@ -726,21 +728,38 @@ var Connection = class {
726
728
  err
727
729
  }, {
728
730
  F: __dxlog_file,
729
- L: 181,
731
+ L: 190,
730
732
  S: this,
731
733
  C: (f, a) => f(...a)
732
734
  });
733
735
  if (!this.closeReason) {
734
736
  this.closeReason = err?.message;
735
737
  }
736
- if (err?.message.includes("OperationError")) {
737
- (0, import_log.log)("aborting due to transport OperationError", void 0, {
738
+ if (err instanceof import_errors.ConnectionResetError) {
739
+ (0, import_log.log)("aborting due to transport ConnectionResetError", void 0, {
738
740
  F: __dxlog_file,
739
- L: 187,
741
+ L: 197,
740
742
  S: this,
741
743
  C: (f, a) => f(...a)
742
744
  });
743
745
  this.abort().catch((err2) => this.errors.raise(err2));
746
+ } else if (err instanceof import_errors.ConnectivityError) {
747
+ (0, import_log.log)("aborting due to transport ConnectivityError", void 0, {
748
+ F: __dxlog_file,
749
+ L: 200,
750
+ S: this,
751
+ C: (f, a) => f(...a)
752
+ });
753
+ this.abort().catch((err2) => this.errors.raise(err2));
754
+ } else if (err instanceof import_errors.UnknownProtocolError) {
755
+ (0, import_log.log)("unsure what to do for UnknownProtocolError", {
756
+ err
757
+ }, {
758
+ F: __dxlog_file,
759
+ L: 203,
760
+ S: this,
761
+ C: (f, a) => f(...a)
762
+ });
744
763
  }
745
764
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
746
765
  this.errors.raise(err);
@@ -754,7 +773,7 @@ var Connection = class {
754
773
  id: this._instanceId
755
774
  }), {
756
775
  F: __dxlog_file,
757
- L: 203,
776
+ L: 218,
758
777
  S: this,
759
778
  C: (f, a) => f(...a)
760
779
  });
@@ -764,30 +783,30 @@ var Connection = class {
764
783
  err
765
784
  }, {
766
785
  F: __dxlog_file,
767
- L: 209,
786
+ L: 224,
768
787
  S: this,
769
788
  C: (f, a) => f(...a)
770
789
  });
771
- if (!this.closeReason) {
772
- this.closeReason = err?.message;
773
- }
774
- if (this._state === ConnectionState.CLOSED) {
775
- (0, import_log.log)("abort ignored: already closed", this.closeReason, {
790
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
791
+ (0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
776
792
  F: __dxlog_file,
777
- L: 214,
793
+ L: 226,
778
794
  S: this,
779
795
  C: (f, a) => f(...a)
780
796
  });
781
797
  return;
782
798
  }
783
- this._changeState(ConnectionState.CLOSING);
799
+ this._changeState(ConnectionState.ABORTING);
800
+ if (!this.closeReason) {
801
+ this.closeReason = err?.message;
802
+ }
784
803
  await this._ctx.dispose();
785
804
  try {
786
805
  (0, import_log.log)("aborting protocol... ", {
787
806
  proto: this._protocol
788
807
  }, {
789
808
  F: __dxlog_file,
790
- L: 224,
809
+ L: 239,
791
810
  S: this,
792
811
  C: (f, a) => f(...a)
793
812
  });
@@ -795,7 +814,7 @@ var Connection = class {
795
814
  } catch (err2) {
796
815
  import_log.log.catch(err2, void 0, {
797
816
  F: __dxlog_file,
798
- L: 227,
817
+ L: 242,
799
818
  S: this,
800
819
  C: (f, a) => f(...a)
801
820
  });
@@ -805,56 +824,68 @@ var Connection = class {
805
824
  } catch (err2) {
806
825
  import_log.log.catch(err2, void 0, {
807
826
  F: __dxlog_file,
808
- L: 234,
827
+ L: 249,
809
828
  S: this,
810
829
  C: (f, a) => f(...a)
811
830
  });
812
831
  }
813
- this._changeState(ConnectionState.CLOSED);
814
- this._callbacks?.onClosed?.(err);
832
+ try {
833
+ this._callbacks?.onClosed?.(err);
834
+ } catch (err2) {
835
+ import_log.log.catch(err2, void 0, {
836
+ F: __dxlog_file,
837
+ L: 255,
838
+ S: this,
839
+ C: (f, a) => f(...a)
840
+ });
841
+ }
842
+ this._changeState(ConnectionState.ABORTED);
815
843
  }
816
844
  async close(err) {
817
845
  if (!this.closeReason) {
818
846
  this.closeReason = err?.message;
819
847
  }
820
- if (this._state === ConnectionState.CLOSED) {
848
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
821
849
  return;
822
850
  }
851
+ const lastState = this._state;
823
852
  this._changeState(ConnectionState.CLOSING);
824
853
  await this._ctx.dispose();
825
854
  (0, import_log.log)("closing...", {
826
855
  peerId: this.ownId
827
856
  }, {
828
857
  F: __dxlog_file,
829
- L: 253,
858
+ L: 277,
830
859
  S: this,
831
860
  C: (f, a) => f(...a)
832
861
  });
833
- try {
834
- await this._protocol.close();
835
- } catch (err2) {
836
- import_log.log.catch(err2, void 0, {
837
- F: __dxlog_file,
838
- L: 259,
839
- S: this,
840
- C: (f, a) => f(...a)
841
- });
842
- }
843
- try {
844
- await this._transport?.destroy();
845
- } catch (err2) {
846
- import_log.log.catch(err2, void 0, {
847
- F: __dxlog_file,
848
- L: 266,
849
- S: this,
850
- C: (f, a) => f(...a)
851
- });
862
+ if (lastState === ConnectionState.CONNECTED) {
863
+ try {
864
+ await this._protocol.close();
865
+ } catch (err2) {
866
+ import_log.log.catch(err2, void 0, {
867
+ F: __dxlog_file,
868
+ L: 284,
869
+ S: this,
870
+ C: (f, a) => f(...a)
871
+ });
872
+ }
873
+ try {
874
+ await this._transport?.destroy();
875
+ } catch (err2) {
876
+ import_log.log.catch(err2, void 0, {
877
+ F: __dxlog_file,
878
+ L: 291,
879
+ S: this,
880
+ C: (f, a) => f(...a)
881
+ });
882
+ }
852
883
  }
853
884
  (0, import_log.log)("closed", {
854
885
  peerId: this.ownId
855
886
  }, {
856
887
  F: __dxlog_file,
857
- L: 269,
888
+ L: 295,
858
889
  S: this,
859
890
  C: (f, a) => f(...a)
860
891
  });
@@ -897,7 +928,7 @@ var Connection = class {
897
928
  err
898
929
  }, {
899
930
  F: __dxlog_file,
900
- L: 306,
931
+ L: 332,
901
932
  S: this,
902
933
  C: (f, a) => f(...a)
903
934
  });
@@ -910,7 +941,7 @@ var Connection = class {
910
941
  async signal(msg) {
911
942
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
912
943
  F: __dxlog_file,
913
- L: 315,
944
+ L: 341,
914
945
  S: this,
915
946
  A: [
916
947
  "msg.sessionId",
@@ -920,7 +951,7 @@ var Connection = class {
920
951
  if (!msg.sessionId.equals(this.sessionId)) {
921
952
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
922
953
  F: __dxlog_file,
923
- L: 317,
954
+ L: 343,
924
955
  S: this,
925
956
  C: (f, a) => f(...a)
926
957
  });
@@ -928,7 +959,7 @@ var Connection = class {
928
959
  }
929
960
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
930
961
  F: __dxlog_file,
931
- L: 320,
962
+ L: 346,
932
963
  S: this,
933
964
  A: [
934
965
  "msg.data.signal || msg.data.signalBatch",
@@ -937,7 +968,7 @@ var Connection = class {
937
968
  });
938
969
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
939
970
  F: __dxlog_file,
940
- L: 321,
971
+ L: 347,
941
972
  S: this,
942
973
  A: [
943
974
  "msg.author?.equals(this.remoteId)",
@@ -946,7 +977,7 @@ var Connection = class {
946
977
  });
947
978
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
948
979
  F: __dxlog_file,
949
- L: 322,
980
+ L: 348,
950
981
  S: this,
951
982
  A: [
952
983
  "msg.recipient?.equals(this.ownId)",
@@ -970,7 +1001,7 @@ var Connection = class {
970
1001
  msg: msg.data
971
1002
  }, {
972
1003
  F: __dxlog_file,
973
- L: 331,
1004
+ L: 357,
974
1005
  S: this,
975
1006
  C: (f, a) => f(...a)
976
1007
  });
@@ -978,7 +1009,7 @@ var Connection = class {
978
1009
  } else {
979
1010
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
980
1011
  F: __dxlog_file,
981
- L: 334,
1012
+ L: 360,
982
1013
  S: this,
983
1014
  A: [
984
1015
  "this._transport",
@@ -991,7 +1022,7 @@ var Connection = class {
991
1022
  msg: msg.data
992
1023
  }, {
993
1024
  F: __dxlog_file,
994
- L: 335,
1025
+ L: 361,
995
1026
  S: this,
996
1027
  C: (f, a) => f(...a)
997
1028
  });
@@ -1005,17 +1036,17 @@ var Connection = class {
1005
1036
  _changeState(state) {
1006
1037
  (0, import_log.log)("stateChanged", {
1007
1038
  from: this._state,
1008
- too: state,
1039
+ to: state,
1009
1040
  peerId: this.ownId
1010
1041
  }, {
1011
1042
  F: __dxlog_file,
1012
- L: 346,
1043
+ L: 372,
1013
1044
  S: this,
1014
1045
  C: (f, a) => f(...a)
1015
1046
  });
1016
1047
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
1017
1048
  F: __dxlog_file,
1018
- L: 347,
1049
+ L: 373,
1019
1050
  S: this,
1020
1051
  A: [
1021
1052
  "state !== this._state",
@@ -1471,6 +1502,9 @@ var Peer = class {
1471
1502
  S: this,
1472
1503
  C: (f, a) => f(...a)
1473
1504
  });
1505
+ if (err instanceof import_errors2.TimeoutError) {
1506
+ await connection.abort(err);
1507
+ }
1474
1508
  await this.closeConnection(err);
1475
1509
  throw err;
1476
1510
  } finally {
@@ -1490,13 +1524,13 @@ var Peer = class {
1490
1524
  sessionId
1491
1525
  }, {
1492
1526
  F: __dxlog_file3,
1493
- L: 210,
1527
+ L: 213,
1494
1528
  S: this,
1495
1529
  C: (f, a) => f(...a)
1496
1530
  });
1497
1531
  (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
1498
1532
  F: __dxlog_file3,
1499
- L: 217,
1533
+ L: 220,
1500
1534
  S: this,
1501
1535
  A: [
1502
1536
  "!this.connection",
@@ -1532,7 +1566,7 @@ var Peer = class {
1532
1566
  initiator
1533
1567
  }, {
1534
1568
  F: __dxlog_file3,
1535
- L: 236,
1569
+ L: 239,
1536
1570
  S: this,
1537
1571
  C: (f, a) => f(...a)
1538
1572
  });
@@ -1545,14 +1579,14 @@ var Peer = class {
1545
1579
  initiator
1546
1580
  }, {
1547
1581
  F: __dxlog_file3,
1548
- L: 245,
1582
+ L: 248,
1549
1583
  S: this,
1550
1584
  C: (f, a) => f(...a)
1551
1585
  });
1552
1586
  this._connectionLimiter.doneConnecting(sessionId);
1553
1587
  (0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1554
1588
  F: __dxlog_file3,
1555
- L: 250,
1589
+ L: 253,
1556
1590
  S: this,
1557
1591
  A: [
1558
1592
  "this.connection === connection",
@@ -1567,7 +1601,7 @@ var Peer = class {
1567
1601
  initiator
1568
1602
  }, {
1569
1603
  F: __dxlog_file3,
1570
- L: 252,
1604
+ L: 255,
1571
1605
  S: this,
1572
1606
  C: (f, a) => f(...a)
1573
1607
  });
@@ -1602,7 +1636,7 @@ var Peer = class {
1602
1636
  err
1603
1637
  }, {
1604
1638
  F: __dxlog_file3,
1605
- L: 292,
1639
+ L: 295,
1606
1640
  S: this,
1607
1641
  C: (f, a) => f(...a)
1608
1642
  });
@@ -1615,7 +1649,7 @@ var Peer = class {
1615
1649
  err
1616
1650
  }, {
1617
1651
  F: __dxlog_file3,
1618
- L: 293,
1652
+ L: 296,
1619
1653
  S: this,
1620
1654
  C: (f, a) => f(...a)
1621
1655
  });
@@ -1634,7 +1668,7 @@ var Peer = class {
1634
1668
  sessionId: connection.sessionId
1635
1669
  }, {
1636
1670
  F: __dxlog_file3,
1637
- L: 318,
1671
+ L: 321,
1638
1672
  S: this,
1639
1673
  C: (f, a) => f(...a)
1640
1674
  });
@@ -1644,7 +1678,7 @@ var Peer = class {
1644
1678
  sessionId: connection.sessionId
1645
1679
  }, {
1646
1680
  F: __dxlog_file3,
1647
- L: 324,
1681
+ L: 327,
1648
1682
  S: this,
1649
1683
  C: (f, a) => f(...a)
1650
1684
  });
@@ -1655,7 +1689,7 @@ var Peer = class {
1655
1689
  message
1656
1690
  }, {
1657
1691
  F: __dxlog_file3,
1658
- L: 329,
1692
+ L: 332,
1659
1693
  S: this,
1660
1694
  C: (f, a) => f(...a)
1661
1695
  });
@@ -1670,7 +1704,7 @@ var Peer = class {
1670
1704
  topic: this.topic
1671
1705
  }, {
1672
1706
  F: __dxlog_file3,
1673
- L: 339,
1707
+ L: 342,
1674
1708
  S: this,
1675
1709
  C: (f, a) => f(...a)
1676
1710
  });
@@ -3075,6 +3109,7 @@ var TransportKind;
3075
3109
  TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
3076
3110
  TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
3077
3111
  TransportKind2["MEMORY"] = "MEMORY";
3112
+ TransportKind2["TCP"] = "TCP";
3078
3113
  })(TransportKind || (TransportKind = {}));
3079
3114
 
3080
3115
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
@@ -3082,6 +3117,7 @@ var import_simple_peer = __toESM(require("simple-peer"));
3082
3117
  var import_tiny_invariant = __toESM(require("tiny-invariant"));
3083
3118
  var import_async9 = require("@dxos/async");
3084
3119
  var import_debug5 = require("@dxos/debug");
3120
+ var import_errors4 = require("@dxos/errors");
3085
3121
  var import_keys10 = require("@dxos/keys");
3086
3122
  var import_log11 = require("@dxos/log");
3087
3123
  var import_protocols5 = require("@dxos/protocols");
@@ -3107,13 +3143,13 @@ var SimplePeerTransport = class {
3107
3143
  id: this._instanceId
3108
3144
  }), {
3109
3145
  F: __dxlog_file12,
3110
- L: 39,
3146
+ L: 41,
3111
3147
  S: this,
3112
3148
  C: (f, a) => f(...a)
3113
3149
  });
3114
3150
  (0, import_log11.log)("created connection", params, {
3115
3151
  F: __dxlog_file12,
3116
- L: 40,
3152
+ L: 42,
3117
3153
  S: this,
3118
3154
  C: (f, a) => f(...a)
3119
3155
  });
@@ -3126,7 +3162,7 @@ var SimplePeerTransport = class {
3126
3162
  this._peer.on("signal", async (data) => {
3127
3163
  (0, import_log11.log)("signal", data, {
3128
3164
  F: __dxlog_file12,
3129
- L: 49,
3165
+ L: 51,
3130
3166
  S: this,
3131
3167
  C: (f, a) => f(...a)
3132
3168
  });
@@ -3139,7 +3175,7 @@ var SimplePeerTransport = class {
3139
3175
  this._peer.on("connect", () => {
3140
3176
  (0, import_log11.log)("connected", void 0, {
3141
3177
  F: __dxlog_file12,
3142
- L: 54,
3178
+ L: 56,
3143
3179
  S: this,
3144
3180
  C: (f, a) => f(...a)
3145
3181
  });
@@ -3149,7 +3185,7 @@ var SimplePeerTransport = class {
3149
3185
  this._peer.on("close", async () => {
3150
3186
  (0, import_log11.log)("closed", void 0, {
3151
3187
  F: __dxlog_file12,
3152
- L: 60,
3188
+ L: 62,
3153
3189
  S: this,
3154
3190
  C: (f, a) => f(...a)
3155
3191
  });
@@ -3157,7 +3193,35 @@ var SimplePeerTransport = class {
3157
3193
  this.closed.emit();
3158
3194
  });
3159
3195
  this._peer.on("error", async (err) => {
3160
- this.errors.raise(err);
3196
+ if (typeof RTCError !== "undefined" && err instanceof RTCError) {
3197
+ if (err.errorDetail === "sctp-failure") {
3198
+ this.errors.raise(new import_errors4.ConnectionResetError("sctp-failure from RTCError", err));
3199
+ } else {
3200
+ this.errors.raise(new import_errors4.UnknownProtocolError("unknown RTCError", err));
3201
+ }
3202
+ } else if (err.name === "InvalidStateError") {
3203
+ this.errors.raise(new import_errors4.ConnectionResetError("safari WebRTC error", err));
3204
+ } else if ("code" in err) {
3205
+ switch (err.code) {
3206
+ case "ERR_WEBRTC_SUPPORT":
3207
+ this.errors.raise(new import_errors4.ProtocolError("WebRTC not supported", err));
3208
+ case "ERR_ICE_CONNECTION_FAILURE":
3209
+ case "ERR_DATA_CHANNEL":
3210
+ case "ERR_CONNECTION_FAILURE":
3211
+ case "ERR_SIGNALING":
3212
+ this.errors.raise(new import_errors4.ConnectivityError("unknown communication failure", err));
3213
+ case "ERR_CREATE_OFFER":
3214
+ case "ERR_CREATE_ANSWER":
3215
+ case "ERR_SET_LOCAL_DESCRIPTION":
3216
+ case "ERR_SET_REMOTE_DESCRIPTION":
3217
+ case "ERR_ADD_ICE_CANDIDATE":
3218
+ this.errors.raise(new import_errors4.UnknownProtocolError("unknown simple-peer library failure", err));
3219
+ default:
3220
+ this.errors.raise(new Error("unknown simple-peer error"));
3221
+ }
3222
+ } else {
3223
+ this.errors.raise(err);
3224
+ }
3161
3225
  try {
3162
3226
  if (typeof this._peer?._pc.getStats === "function") {
3163
3227
  this._peer._pc.getStats().then((stats) => {
@@ -3166,13 +3230,19 @@ var SimplePeerTransport = class {
3166
3230
  stats
3167
3231
  }, {
3168
3232
  F: __dxlog_file12,
3169
- L: 72,
3233
+ L: 107,
3170
3234
  S: this,
3171
3235
  C: (f, a) => f(...a)
3172
3236
  });
3173
3237
  });
3174
3238
  }
3175
- } catch {
3239
+ } catch (err2) {
3240
+ import_log11.log.catch(err2, void 0, {
3241
+ F: __dxlog_file12,
3242
+ L: 114,
3243
+ S: this,
3244
+ C: (f, a) => f(...a)
3245
+ });
3176
3246
  }
3177
3247
  await this.destroy();
3178
3248
  });
@@ -3180,7 +3250,7 @@ var SimplePeerTransport = class {
3180
3250
  id: this._instanceId
3181
3251
  }), {
3182
3252
  F: __dxlog_file12,
3183
- L: 82,
3253
+ L: 119,
3184
3254
  S: this,
3185
3255
  C: (f, a) => f(...a)
3186
3256
  });
@@ -3188,7 +3258,7 @@ var SimplePeerTransport = class {
3188
3258
  async destroy() {
3189
3259
  (0, import_log11.log)("closing...", void 0, {
3190
3260
  F: __dxlog_file12,
3191
- L: 86,
3261
+ L: 123,
3192
3262
  S: this,
3193
3263
  C: (f, a) => f(...a)
3194
3264
  });
@@ -3198,7 +3268,7 @@ var SimplePeerTransport = class {
3198
3268
  this.closed.emit();
3199
3269
  (0, import_log11.log)("closed", void 0, {
3200
3270
  F: __dxlog_file12,
3201
- L: 91,
3271
+ L: 128,
3202
3272
  S: this,
3203
3273
  C: (f, a) => f(...a)
3204
3274
  });
@@ -3356,6 +3426,7 @@ var import_node_stream3 = require("node:stream");
3356
3426
  var import_async10 = require("@dxos/async");
3357
3427
  var import_context6 = require("@dxos/context");
3358
3428
  var import_debug6 = require("@dxos/debug");
3429
+ var import_errors5 = require("@dxos/errors");
3359
3430
  var import_invariant12 = require("@dxos/invariant");
3360
3431
  var import_keys12 = require("@dxos/keys");
3361
3432
  var import_log13 = require("@dxos/log");
@@ -3380,7 +3451,7 @@ var SimplePeerTransportProxy = class {
3380
3451
  this._serviceStream.subscribe(async (event) => {
3381
3452
  (0, import_log13.log)("SimplePeerTransportProxy: event", event, {
3382
3453
  F: __dxlog_file14,
3383
- L: 51,
3454
+ L: 58,
3384
3455
  S: this,
3385
3456
  C: (f, a) => f(...a)
3386
3457
  });
@@ -3400,7 +3471,7 @@ var SimplePeerTransportProxy = class {
3400
3471
  }).then(() => callback(), (err) => {
3401
3472
  import_log13.log.catch(err, void 0, {
3402
3473
  F: __dxlog_file14,
3403
- L: 69,
3474
+ L: 76,
3404
3475
  S: this,
3405
3476
  C: (f, a) => f(...a)
3406
3477
  });
@@ -3409,14 +3480,14 @@ var SimplePeerTransportProxy = class {
3409
3480
  }));
3410
3481
  }, (error) => import_log13.log.catch(error, void 0, {
3411
3482
  F: __dxlog_file14,
3412
- L: 75,
3483
+ L: 82,
3413
3484
  S: this,
3414
3485
  C: (f, a) => f(...a)
3415
3486
  }));
3416
3487
  }
3417
3488
  async _handleConnection(connectionEvent) {
3418
3489
  if (connectionEvent.error) {
3419
- this.errors.raise(new Error(connectionEvent.error));
3490
+ this.errors.raise(decodeError(connectionEvent.error));
3420
3491
  }
3421
3492
  switch (connectionEvent.state) {
3422
3493
  case import_bridge2.ConnectionState.CONNECTED: {
@@ -3439,7 +3510,7 @@ var SimplePeerTransportProxy = class {
3439
3510
  this._params.bridgeService.sendSignal({
3440
3511
  proxyId: this._proxyId,
3441
3512
  signal
3442
- }).catch((err) => this.errors.raise(err));
3513
+ }).catch((err) => this.errors.raise(decodeError(err)));
3443
3514
  }
3444
3515
  // TODO(burdon): Move open from constructor.
3445
3516
  async destroy() {
@@ -3455,7 +3526,7 @@ var SimplePeerTransportProxy = class {
3455
3526
  } catch (err) {
3456
3527
  import_log13.log.catch(err, void 0, {
3457
3528
  F: __dxlog_file14,
3458
- L: 126,
3529
+ L: 133,
3459
3530
  S: this,
3460
3531
  C: (f, a) => f(...a)
3461
3532
  });
@@ -3491,7 +3562,7 @@ var SimplePeerTransportProxyFactory = class {
3491
3562
  createTransport(options) {
3492
3563
  (0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3493
3564
  F: __dxlog_file14,
3494
- L: 163,
3565
+ L: 170,
3495
3566
  S: this,
3496
3567
  A: [
3497
3568
  "this._bridgeService",
@@ -3507,6 +3578,22 @@ var SimplePeerTransportProxyFactory = class {
3507
3578
  return transport;
3508
3579
  }
3509
3580
  };
3581
+ var decodeError = (err) => {
3582
+ const message = typeof err === "string" ? err : err.message;
3583
+ if (message.includes("ConnectionResetError")) {
3584
+ return new import_errors5.ConnectionResetError(message);
3585
+ } else if (message.includes("TimeoutError")) {
3586
+ return new import_errors5.TimeoutError(message);
3587
+ } else if (message.includes("ProtocolError")) {
3588
+ return new import_errors5.ProtocolError(message);
3589
+ } else if (message.includes("ConnectivityError")) {
3590
+ return new import_errors5.ConnectivityError(message);
3591
+ } else if (message.includes("UnknownProtocolError")) {
3592
+ return new import_errors5.UnknownProtocolError(message);
3593
+ } else {
3594
+ return typeof err === "string" ? new Error(err) : err;
3595
+ }
3596
+ };
3510
3597
 
3511
3598
  // packages/core/mesh/network-manager/src/transport/index.ts
3512
3599
  init_datachannel();