@dxos/network-manager 0.8.4-main.84f28bd → 0.8.4-main.a4bbb77

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 (76) hide show
  1. package/dist/lib/browser/{chunk-HQNQOWFA.mjs → chunk-NRRQ4H6U.mjs} +706 -394
  2. package/dist/lib/browser/chunk-NRRQ4H6U.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 +111 -64
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/browser/transport/tcp/index.mjs +18 -5
  8. package/dist/lib/browser/transport/tcp/index.mjs.map +2 -2
  9. package/dist/lib/node-esm/{chunk-JPPMRZTH.mjs → chunk-AX4TJ2DL.mjs} +706 -394
  10. package/dist/lib/node-esm/chunk-AX4TJ2DL.mjs.map +7 -0
  11. package/dist/lib/node-esm/index.mjs +1 -1
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +111 -64
  14. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  15. package/dist/lib/node-esm/transport/tcp/index.mjs +31 -10
  16. package/dist/lib/node-esm/transport/tcp/index.mjs.map +3 -3
  17. package/dist/types/src/connection-log.d.ts.map +1 -1
  18. package/dist/types/src/index.d.ts +1 -1
  19. package/dist/types/src/index.d.ts.map +1 -1
  20. package/dist/types/src/network-manager.d.ts.map +1 -1
  21. package/dist/types/src/signal/index.d.ts +2 -2
  22. package/dist/types/src/signal/index.d.ts.map +1 -1
  23. package/dist/types/src/signal/swarm-messenger.d.ts +1 -1
  24. package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
  25. package/dist/types/src/swarm/peer.d.ts +2 -2
  26. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  27. package/dist/types/src/swarm/swarm.d.ts +3 -3
  28. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  29. package/dist/types/src/testing/test-builder.d.ts +1 -1
  30. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  31. package/dist/types/src/testing/test-wire-protocol.d.ts +1 -1
  32. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
  33. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  34. package/dist/types/src/topology/index.d.ts +1 -1
  35. package/dist/types/src/topology/index.d.ts.map +1 -1
  36. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +2 -2
  37. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
  38. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts +1 -1
  39. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
  40. package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
  41. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts +1 -1
  42. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
  43. package/dist/types/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +23 -19
  45. package/src/connection-log.ts +1 -1
  46. package/src/index.ts +1 -1
  47. package/src/network-manager.ts +1 -1
  48. package/src/signal/ice.test.ts +1 -1
  49. package/src/signal/index.ts +2 -2
  50. package/src/signal/integration.node.test.ts +2 -2
  51. package/src/signal/swarm-messenger.node.test.ts +1 -1
  52. package/src/signal/swarm-messenger.ts +1 -1
  53. package/src/swarm/connection.test.ts +2 -1
  54. package/src/swarm/connection.ts +4 -4
  55. package/src/swarm/peer.ts +3 -2
  56. package/src/swarm/swarm-mapper.ts +1 -1
  57. package/src/swarm/swarm.test.ts +5 -4
  58. package/src/swarm/swarm.ts +5 -4
  59. package/src/testing/test-builder.ts +12 -4
  60. package/src/testing/test-wire-protocol.ts +2 -2
  61. package/src/tests/basic-test-suite.ts +3 -2
  62. package/src/tests/memory-transport.test.ts +4 -2
  63. package/src/tests/tcp-transport.node.test.ts +4 -2
  64. package/src/tests/webrtc-transport.test.ts +2 -1
  65. package/src/topology/index.ts +1 -1
  66. package/src/transport/tcp/tcp-transport.ts +1 -1
  67. package/src/transport/webrtc/rtc-connection-factory.ts +1 -1
  68. package/src/transport/webrtc/rtc-peer-connection.ts +4 -3
  69. package/src/transport/webrtc/rtc-transport-channel.test.ts +3 -1
  70. package/src/transport/webrtc/rtc-transport-channel.ts +2 -1
  71. package/src/transport/webrtc/rtc-transport-factory.ts +3 -2
  72. package/src/transport/webrtc/rtc-transport-proxy.test.ts +5 -3
  73. package/src/transport/webrtc/rtc-transport-service.ts +6 -5
  74. package/src/transport/webrtc/rtc-transport.test.ts +4 -3
  75. package/dist/lib/browser/chunk-HQNQOWFA.mjs.map +0 -7
  76. package/dist/lib/node-esm/chunk-JPPMRZTH.mjs.map +0 -7
@@ -1,13 +1,26 @@
1
1
  import "@dxos/node-std/globals";
2
2
 
3
3
  // src/swarm/connection.ts
4
- import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized, Trigger } from "@dxos/async";
5
- import { Context, cancelWithContext, ContextDisposedError } from "@dxos/context";
4
+ import { DeferredTask, Event, Trigger, scheduleTask, scheduleTaskInterval, sleep, synchronized } from "@dxos/async";
5
+ import { Context, ContextDisposedError, cancelWithContext } from "@dxos/context";
6
6
  import { ErrorStream } from "@dxos/debug";
7
7
  import { invariant } from "@dxos/invariant";
8
8
  import { PublicKey } from "@dxos/keys";
9
9
  import { log, logInfo } from "@dxos/log";
10
- import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, TimeoutError, trace } from "@dxos/protocols";
10
+ import { CancelledError, ConnectionResetError, ConnectivityError, ProtocolError, TimeoutError, trace } from "@dxos/protocols";
11
+ function _define_property(obj, key, value) {
12
+ if (key in obj) {
13
+ Object.defineProperty(obj, key, {
14
+ value,
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true
18
+ });
19
+ } else {
20
+ obj[key] = value;
21
+ }
22
+ return obj;
23
+ }
11
24
  function _ts_decorate(decorators, target, key, desc) {
12
25
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13
26
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -19,7 +32,7 @@ var STARTING_SIGNALLING_DELAY = 10;
19
32
  var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
20
33
  var TRANSPORT_STATS_INTERVAL = 5e3;
21
34
  var MAX_SIGNALLING_DELAY = 300;
22
- var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
35
+ var ConnectionState = /* @__PURE__ */ (function(ConnectionState5) {
23
36
  ConnectionState5["CREATED"] = "CREATED";
24
37
  ConnectionState5["INITIAL"] = "INITIAL";
25
38
  ConnectionState5["CONNECTING"] = "CONNECTING";
@@ -29,52 +42,8 @@ var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
29
42
  ConnectionState5["ABORTING"] = "ABORTING";
30
43
  ConnectionState5["ABORTED"] = "ABORTED";
31
44
  return ConnectionState5;
32
- }({});
45
+ })({});
33
46
  var Connection = class {
34
- constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
35
- this.topic = topic;
36
- this.localInfo = localInfo;
37
- this.remoteInfo = remoteInfo;
38
- this.sessionId = sessionId;
39
- this.initiator = initiator;
40
- this._signalMessaging = _signalMessaging;
41
- this._protocol = _protocol;
42
- this._transportFactory = _transportFactory;
43
- this._callbacks = _callbacks;
44
- this._ctx = new Context(void 0, {
45
- F: __dxlog_file,
46
- L: 100
47
- });
48
- this.connectedTimeoutContext = new Context(void 0, {
49
- F: __dxlog_file,
50
- L: 101
51
- });
52
- this._protocolClosed = new Trigger();
53
- this._transportClosed = new Trigger();
54
- this._state = "CREATED";
55
- this._incomingSignalBuffer = [];
56
- this._outgoingSignalBuffer = [];
57
- this.stateChanged = new Event();
58
- this.errors = new ErrorStream();
59
- this._instanceId = PublicKey.random().toHex();
60
- this.transportStats = new Event();
61
- this._signalSendTask = new DeferredTask(this._ctx, async () => {
62
- await this._flushSignalBuffer();
63
- });
64
- this._signallingDelay = STARTING_SIGNALLING_DELAY;
65
- log.trace("dxos.mesh.connection.construct", {
66
- sessionId: this.sessionId,
67
- topic: this.topic,
68
- localPeer: this.localInfo,
69
- remotePeer: this.remoteInfo,
70
- initiator: this.initiator
71
- }, {
72
- F: __dxlog_file,
73
- L: 137,
74
- S: this,
75
- C: (f, a) => f(...a)
76
- });
77
- }
78
47
  get sessionIdString() {
79
48
  return this.sessionId.truncate();
80
49
  }
@@ -586,6 +555,74 @@ var Connection = class {
586
555
  this.transportStats.emit(stats);
587
556
  }
588
557
  }
558
+ constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
559
+ _define_property(this, "topic", void 0);
560
+ _define_property(this, "localInfo", void 0);
561
+ _define_property(this, "remoteInfo", void 0);
562
+ _define_property(this, "sessionId", void 0);
563
+ _define_property(this, "initiator", void 0);
564
+ _define_property(this, "_signalMessaging", void 0);
565
+ _define_property(this, "_protocol", void 0);
566
+ _define_property(this, "_transportFactory", void 0);
567
+ _define_property(this, "_callbacks", void 0);
568
+ _define_property(this, "_ctx", void 0);
569
+ _define_property(this, "connectedTimeoutContext", void 0);
570
+ _define_property(this, "_protocolClosed", void 0);
571
+ _define_property(this, "_transportClosed", void 0);
572
+ _define_property(this, "_state", void 0);
573
+ _define_property(this, "_transport", void 0);
574
+ _define_property(this, "closeReason", void 0);
575
+ _define_property(this, "_incomingSignalBuffer", void 0);
576
+ _define_property(this, "_outgoingSignalBuffer", void 0);
577
+ _define_property(this, "stateChanged", void 0);
578
+ _define_property(this, "errors", void 0);
579
+ _define_property(this, "_instanceId", void 0);
580
+ _define_property(this, "transportStats", void 0);
581
+ _define_property(this, "_signalSendTask", void 0);
582
+ _define_property(this, "_signallingDelay", void 0);
583
+ this.topic = topic;
584
+ this.localInfo = localInfo;
585
+ this.remoteInfo = remoteInfo;
586
+ this.sessionId = sessionId;
587
+ this.initiator = initiator;
588
+ this._signalMessaging = _signalMessaging;
589
+ this._protocol = _protocol;
590
+ this._transportFactory = _transportFactory;
591
+ this._callbacks = _callbacks;
592
+ this._ctx = new Context(void 0, {
593
+ F: __dxlog_file,
594
+ L: 100
595
+ });
596
+ this.connectedTimeoutContext = new Context(void 0, {
597
+ F: __dxlog_file,
598
+ L: 101
599
+ });
600
+ this._protocolClosed = new Trigger();
601
+ this._transportClosed = new Trigger();
602
+ this._state = "CREATED";
603
+ this._incomingSignalBuffer = [];
604
+ this._outgoingSignalBuffer = [];
605
+ this.stateChanged = new Event();
606
+ this.errors = new ErrorStream();
607
+ this._instanceId = PublicKey.random().toHex();
608
+ this.transportStats = new Event();
609
+ this._signalSendTask = new DeferredTask(this._ctx, async () => {
610
+ await this._flushSignalBuffer();
611
+ });
612
+ this._signallingDelay = STARTING_SIGNALLING_DELAY;
613
+ log.trace("dxos.mesh.connection.construct", {
614
+ sessionId: this.sessionId,
615
+ topic: this.topic,
616
+ localPeer: this.localInfo,
617
+ remotePeer: this.remoteInfo,
618
+ initiator: this.initiator
619
+ }, {
620
+ F: __dxlog_file,
621
+ L: 137,
622
+ S: this,
623
+ C: (f, a) => f(...a)
624
+ });
625
+ }
589
626
  };
590
627
  _ts_decorate([
591
628
  logInfo
@@ -638,20 +675,22 @@ import { log as log3 } from "@dxos/log";
638
675
  import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
639
676
  import { schema } from "@dxos/protocols/proto";
640
677
  import { ComplexMap } from "@dxos/util";
678
+ function _define_property2(obj, key, value) {
679
+ if (key in obj) {
680
+ Object.defineProperty(obj, key, {
681
+ value,
682
+ enumerable: true,
683
+ configurable: true,
684
+ writable: true
685
+ });
686
+ } else {
687
+ obj[key] = value;
688
+ }
689
+ return obj;
690
+ }
641
691
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
642
692
  var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
643
693
  var SwarmMessenger = class {
644
- constructor({ sendMessage, onSignal, onOffer, topic }) {
645
- this._ctx = new Context2(void 0, {
646
- F: __dxlog_file3,
647
- L: 35
648
- });
649
- this._offerRecords = new ComplexMap((key) => key.toHex());
650
- this._sendMessage = sendMessage;
651
- this._onSignal = onSignal;
652
- this._onOffer = onOffer;
653
- this._topic = topic;
654
- }
655
694
  async receiveMessage({ author, recipient, payload }) {
656
695
  if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
657
696
  return;
@@ -875,6 +914,21 @@ var SwarmMessenger = class {
875
914
  };
876
915
  await this._onSignal(signalMessage);
877
916
  }
917
+ constructor({ sendMessage, onSignal, onOffer, topic }) {
918
+ _define_property2(this, "_ctx", new Context2(void 0, {
919
+ F: __dxlog_file3,
920
+ L: 35
921
+ }));
922
+ _define_property2(this, "_sendMessage", void 0);
923
+ _define_property2(this, "_onSignal", void 0);
924
+ _define_property2(this, "_onOffer", void 0);
925
+ _define_property2(this, "_topic", void 0);
926
+ _define_property2(this, "_offerRecords", new ComplexMap((key) => key.toHex()));
927
+ this._sendMessage = sendMessage;
928
+ this._onSignal = onSignal;
929
+ this._onOffer = onOffer;
930
+ this._topic = topic;
931
+ }
878
932
  };
879
933
 
880
934
  // src/swarm/swarm.ts
@@ -895,6 +949,19 @@ import { invariant as invariant3 } from "@dxos/invariant";
895
949
  import { PublicKey as PublicKey3 } from "@dxos/keys";
896
950
  import { log as log4 } from "@dxos/log";
897
951
  import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
952
+ function _define_property3(obj, key, value) {
953
+ if (key in obj) {
954
+ Object.defineProperty(obj, key, {
955
+ value,
956
+ enumerable: true,
957
+ configurable: true,
958
+ writable: true
959
+ });
960
+ } else {
961
+ obj[key] = value;
962
+ }
963
+ return obj;
964
+ }
898
965
  function _ts_decorate2(decorators, target, key, desc) {
899
966
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
900
967
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -909,25 +976,6 @@ var ConnectionDisplacedError = class extends SystemError {
909
976
  };
910
977
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
911
978
  var Peer = class {
912
- constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
913
- this.remoteInfo = remoteInfo;
914
- this.topic = topic;
915
- this.localInfo = localInfo;
916
- this._signalMessaging = _signalMessaging;
917
- this._protocolProvider = _protocolProvider;
918
- this._transportFactory = _transportFactory;
919
- this._connectionLimiter = _connectionLimiter;
920
- this._callbacks = _callbacks;
921
- this._availableAfter = 0;
922
- this.availableToConnect = true;
923
- this._ctx = new Context3(void 0, {
924
- F: __dxlog_file4,
925
- L: 80
926
- });
927
- this.advertizing = false;
928
- this.initiating = false;
929
- this.connectionDisplaced = new Event2();
930
- }
931
979
  /**
932
980
  * Respond to remote offer.
933
981
  */
@@ -940,7 +988,7 @@ var Peer = class {
940
988
  ].includes(this.connection.state)) {
941
989
  log4.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
942
990
  F: __dxlog_file4,
943
- L: 115,
991
+ L: 116,
944
992
  S: this,
945
993
  C: (f, a) => f(...a)
946
994
  });
@@ -957,7 +1005,7 @@ var Peer = class {
957
1005
  sessionId: this.connection?.sessionId
958
1006
  }, {
959
1007
  F: __dxlog_file4,
960
- L: 124,
1008
+ L: 125,
961
1009
  S: this,
962
1010
  C: (f, a) => f(...a)
963
1011
  });
@@ -974,7 +1022,7 @@ var Peer = class {
974
1022
  if (!this.connection) {
975
1023
  invariant3(message.sessionId, void 0, {
976
1024
  F: __dxlog_file4,
977
- L: 144,
1025
+ L: 145,
978
1026
  S: this,
979
1027
  A: [
980
1028
  "message.sessionId",
@@ -995,7 +1043,7 @@ var Peer = class {
995
1043
  err
996
1044
  }, {
997
1045
  F: __dxlog_file4,
998
- L: 154,
1046
+ L: 155,
999
1047
  S: this,
1000
1048
  C: (f, a) => f(...a)
1001
1049
  });
@@ -1017,7 +1065,7 @@ var Peer = class {
1017
1065
  async initiateConnection() {
1018
1066
  invariant3(!this.initiating, "Initiation in progress.", {
1019
1067
  F: __dxlog_file4,
1020
- L: 171,
1068
+ L: 172,
1021
1069
  S: this,
1022
1070
  A: [
1023
1071
  "!this.initiating",
@@ -1026,7 +1074,7 @@ var Peer = class {
1026
1074
  });
1027
1075
  invariant3(!this.connection, "Already connected.", {
1028
1076
  F: __dxlog_file4,
1029
- L: 172,
1077
+ L: 173,
1030
1078
  S: this,
1031
1079
  A: [
1032
1080
  "!this.connection",
@@ -1041,7 +1089,7 @@ var Peer = class {
1041
1089
  sessionId
1042
1090
  }, {
1043
1091
  F: __dxlog_file4,
1044
- L: 174,
1092
+ L: 175,
1045
1093
  S: this,
1046
1094
  C: (f, a) => f(...a)
1047
1095
  });
@@ -1067,14 +1115,14 @@ var Peer = class {
1067
1115
  remote: this.remoteInfo
1068
1116
  }, {
1069
1117
  F: __dxlog_file4,
1070
- L: 191,
1118
+ L: 192,
1071
1119
  S: this,
1072
1120
  C: (f, a) => f(...a)
1073
1121
  });
1074
1122
  if (connection.state !== ConnectionState.INITIAL) {
1075
1123
  log4("ignoring response", void 0, {
1076
1124
  F: __dxlog_file4,
1077
- L: 193,
1125
+ L: 194,
1078
1126
  S: this,
1079
1127
  C: (f, a) => f(...a)
1080
1128
  });
@@ -1088,7 +1136,7 @@ var Peer = class {
1088
1136
  remote: this.remoteInfo
1089
1137
  }, {
1090
1138
  F: __dxlog_file4,
1091
- L: 197,
1139
+ L: 198,
1092
1140
  S: this,
1093
1141
  C: (f, a) => f(...a)
1094
1142
  });
@@ -1110,7 +1158,7 @@ var Peer = class {
1110
1158
  remote: this.remoteInfo
1111
1159
  }, {
1112
1160
  F: __dxlog_file4,
1113
- L: 210,
1161
+ L: 211,
1114
1162
  S: this,
1115
1163
  C: (f, a) => f(...a)
1116
1164
  });
@@ -1122,7 +1170,7 @@ var Peer = class {
1122
1170
  try {
1123
1171
  log4("opening connection as initiator", void 0, {
1124
1172
  F: __dxlog_file4,
1125
- L: 223,
1173
+ L: 224,
1126
1174
  S: this,
1127
1175
  C: (f, a) => f(...a)
1128
1176
  });
@@ -1136,7 +1184,7 @@ var Peer = class {
1136
1184
  remote: this.remoteInfo
1137
1185
  }, {
1138
1186
  F: __dxlog_file4,
1139
- L: 227,
1187
+ L: 228,
1140
1188
  S: this,
1141
1189
  C: (f, a) => f(...a)
1142
1190
  });
@@ -1144,7 +1192,7 @@ var Peer = class {
1144
1192
  err
1145
1193
  }, {
1146
1194
  F: __dxlog_file4,
1147
- L: 234,
1195
+ L: 235,
1148
1196
  S: this,
1149
1197
  C: (f, a) => f(...a)
1150
1198
  });
@@ -1167,13 +1215,13 @@ var Peer = class {
1167
1215
  sessionId
1168
1216
  }, {
1169
1217
  F: __dxlog_file4,
1170
- L: 248,
1218
+ L: 249,
1171
1219
  S: this,
1172
1220
  C: (f, a) => f(...a)
1173
1221
  });
1174
1222
  invariant3(!this.connection, "Already connected.", {
1175
1223
  F: __dxlog_file4,
1176
- L: 255,
1224
+ L: 256,
1177
1225
  S: this,
1178
1226
  A: [
1179
1227
  "!this.connection",
@@ -1209,7 +1257,7 @@ var Peer = class {
1209
1257
  initiator
1210
1258
  }, {
1211
1259
  F: __dxlog_file4,
1212
- L: 279,
1260
+ L: 280,
1213
1261
  S: this,
1214
1262
  C: (f, a) => f(...a)
1215
1263
  });
@@ -1223,14 +1271,14 @@ var Peer = class {
1223
1271
  };
1224
1272
  log4("connection closed", logMeta, {
1225
1273
  F: __dxlog_file4,
1226
- L: 289,
1274
+ L: 290,
1227
1275
  S: this,
1228
1276
  C: (f, a) => f(...a)
1229
1277
  });
1230
1278
  this._connectionLimiter.doneConnecting(sessionId);
1231
1279
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1232
1280
  F: __dxlog_file4,
1233
- L: 294,
1281
+ L: 295,
1234
1282
  S: this,
1235
1283
  A: [
1236
1284
  "this.connection === connection",
@@ -1245,7 +1293,7 @@ var Peer = class {
1245
1293
  initiator
1246
1294
  }, {
1247
1295
  F: __dxlog_file4,
1248
- L: 296,
1296
+ L: 297,
1249
1297
  S: this,
1250
1298
  C: (f, a) => f(...a)
1251
1299
  });
@@ -1262,7 +1310,7 @@ var Peer = class {
1262
1310
  scheduleTask2(this._connectionCtx, () => {
1263
1311
  log4("peer became available", logMeta, {
1264
1312
  F: __dxlog_file4,
1265
- L: 320,
1313
+ L: 321,
1266
1314
  S: this,
1267
1315
  C: (f, a) => f(...a)
1268
1316
  });
@@ -1286,7 +1334,7 @@ var Peer = class {
1286
1334
  err
1287
1335
  }, {
1288
1336
  F: __dxlog_file4,
1289
- L: 338,
1337
+ L: 339,
1290
1338
  S: this,
1291
1339
  C: (f, a) => f(...a)
1292
1340
  });
@@ -1299,7 +1347,7 @@ var Peer = class {
1299
1347
  err
1300
1348
  }, {
1301
1349
  F: __dxlog_file4,
1302
- L: 345,
1350
+ L: 346,
1303
1351
  S: this,
1304
1352
  C: (f, a) => f(...a)
1305
1353
  });
@@ -1318,7 +1366,7 @@ var Peer = class {
1318
1366
  sessionId: connection.sessionId
1319
1367
  }, {
1320
1368
  F: __dxlog_file4,
1321
- L: 370,
1369
+ L: 371,
1322
1370
  S: this,
1323
1371
  C: (f, a) => f(...a)
1324
1372
  });
@@ -1330,7 +1378,7 @@ var Peer = class {
1330
1378
  sessionId: connection.sessionId
1331
1379
  }, {
1332
1380
  F: __dxlog_file4,
1333
- L: 376,
1381
+ L: 377,
1334
1382
  S: this,
1335
1383
  C: (f, a) => f(...a)
1336
1384
  });
@@ -1341,7 +1389,7 @@ var Peer = class {
1341
1389
  message
1342
1390
  }, {
1343
1391
  F: __dxlog_file4,
1344
- L: 381,
1392
+ L: 382,
1345
1393
  S: this,
1346
1394
  C: (f, a) => f(...a)
1347
1395
  });
@@ -1356,7 +1404,7 @@ var Peer = class {
1356
1404
  topic: this.topic
1357
1405
  }, {
1358
1406
  F: __dxlog_file4,
1359
- L: 391,
1407
+ L: 392,
1360
1408
  S: this,
1361
1409
  C: (f, a) => f(...a)
1362
1410
  });
@@ -1364,6 +1412,42 @@ var Peer = class {
1364
1412
  reason
1365
1413
  });
1366
1414
  }
1415
+ constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
1416
+ _define_property3(this, "remoteInfo", void 0);
1417
+ _define_property3(this, "topic", void 0);
1418
+ _define_property3(this, "localInfo", void 0);
1419
+ _define_property3(this, "_signalMessaging", void 0);
1420
+ _define_property3(this, "_protocolProvider", void 0);
1421
+ _define_property3(this, "_transportFactory", void 0);
1422
+ _define_property3(this, "_connectionLimiter", void 0);
1423
+ _define_property3(this, "_callbacks", void 0);
1424
+ _define_property3(this, "_availableAfter", void 0);
1425
+ _define_property3(this, "availableToConnect", void 0);
1426
+ _define_property3(this, "_lastConnectionTime", void 0);
1427
+ _define_property3(this, "_ctx", void 0);
1428
+ _define_property3(this, "_connectionCtx", void 0);
1429
+ _define_property3(this, "connection", void 0);
1430
+ _define_property3(this, "advertizing", void 0);
1431
+ _define_property3(this, "initiating", void 0);
1432
+ _define_property3(this, "connectionDisplaced", void 0);
1433
+ this.remoteInfo = remoteInfo;
1434
+ this.topic = topic;
1435
+ this.localInfo = localInfo;
1436
+ this._signalMessaging = _signalMessaging;
1437
+ this._protocolProvider = _protocolProvider;
1438
+ this._transportFactory = _transportFactory;
1439
+ this._connectionLimiter = _connectionLimiter;
1440
+ this._callbacks = _callbacks;
1441
+ this._availableAfter = 0;
1442
+ this.availableToConnect = true;
1443
+ this._ctx = new Context3(void 0, {
1444
+ F: __dxlog_file4,
1445
+ L: 81
1446
+ });
1447
+ this.advertizing = false;
1448
+ this.initiating = false;
1449
+ this.connectionDisplaced = new Event2();
1450
+ }
1367
1451
  };
1368
1452
  _ts_decorate2([
1369
1453
  synchronized2
@@ -1382,6 +1466,19 @@ var increaseInterval = (interval) => {
1382
1466
  };
1383
1467
 
1384
1468
  // src/swarm/swarm.ts
1469
+ function _define_property4(obj, key, value) {
1470
+ if (key in obj) {
1471
+ Object.defineProperty(obj, key, {
1472
+ value,
1473
+ enumerable: true,
1474
+ configurable: true,
1475
+ writable: true
1476
+ });
1477
+ } else {
1478
+ obj[key] = value;
1479
+ }
1480
+ return obj;
1481
+ }
1385
1482
  function _ts_decorate3(decorators, target, key, desc) {
1386
1483
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1387
1484
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1392,65 +1489,6 @@ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm
1392
1489
  var INITIATION_DELAY = 100;
1393
1490
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1394
1491
  var Swarm = class {
1395
- // TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
1396
- // TODO(burdon): Pass in object.
1397
- constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
1398
- this._topic = _topic;
1399
- this._ownPeer = _ownPeer;
1400
- this._topology = _topology;
1401
- this._protocolProvider = _protocolProvider;
1402
- this._messenger = _messenger;
1403
- this._transportFactory = _transportFactory;
1404
- this._label = _label;
1405
- this._connectionLimiter = _connectionLimiter;
1406
- this._initiationDelay = _initiationDelay;
1407
- this._ctx = new Context4(void 0, {
1408
- F: __dxlog_file5,
1409
- L: 38
1410
- });
1411
- this._listeningHandle = void 0;
1412
- this._peers = new ComplexMap2(PeerInfoHash);
1413
- this._instanceId = PublicKey4.random().toHex();
1414
- this.connectionAdded = new Event3();
1415
- this.disconnected = new Event3();
1416
- this.connected = new Event3();
1417
- this.errors = new ErrorStream2();
1418
- log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
1419
- id: this._instanceId,
1420
- data: {
1421
- topic: this._topic.toHex(),
1422
- peer: this._ownPeer
1423
- }
1424
- }), {
1425
- F: __dxlog_file5,
1426
- L: 88,
1427
- S: this,
1428
- C: (f, a) => f(...a)
1429
- });
1430
- log5("creating swarm", {
1431
- peerId: _ownPeer
1432
- }, {
1433
- F: __dxlog_file5,
1434
- L: 92,
1435
- S: this,
1436
- C: (f, a) => f(...a)
1437
- });
1438
- _topology.init(this._getSwarmController());
1439
- this._swarmMessenger = new SwarmMessenger({
1440
- sendMessage: async (msg) => await this._messenger.sendMessage(msg),
1441
- onSignal: async (msg) => await this.onSignal(msg),
1442
- onOffer: async (msg) => await this.onOffer(msg),
1443
- topic: this._topic
1444
- });
1445
- log5.trace("dxos.mesh.swarm.constructor", trace2.end({
1446
- id: this._instanceId
1447
- }), {
1448
- F: __dxlog_file5,
1449
- L: 101,
1450
- S: this,
1451
- C: (f, a) => f(...a)
1452
- });
1453
- }
1454
1492
  get connections() {
1455
1493
  return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable2);
1456
1494
  }
@@ -1472,7 +1510,7 @@ var Swarm = class {
1472
1510
  async open() {
1473
1511
  invariant4(!this._listeningHandle, void 0, {
1474
1512
  F: __dxlog_file5,
1475
- L: 132,
1513
+ L: 133,
1476
1514
  S: this,
1477
1515
  A: [
1478
1516
  "!this._listeningHandle",
@@ -1487,7 +1525,7 @@ var Swarm = class {
1487
1525
  err
1488
1526
  }, {
1489
1527
  F: __dxlog_file5,
1490
- L: 140,
1528
+ L: 141,
1491
1529
  S: this,
1492
1530
  C: (f, a) => f(...a)
1493
1531
  }));
@@ -1497,7 +1535,7 @@ var Swarm = class {
1497
1535
  async destroy() {
1498
1536
  log5("destroying...", void 0, {
1499
1537
  F: __dxlog_file5,
1500
- L: 146,
1538
+ L: 147,
1501
1539
  S: this,
1502
1540
  C: (f, a) => f(...a)
1503
1541
  });
@@ -1508,7 +1546,7 @@ var Swarm = class {
1508
1546
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
1509
1547
  log5("destroyed", void 0, {
1510
1548
  F: __dxlog_file5,
1511
- L: 153,
1549
+ L: 154,
1512
1550
  S: this,
1513
1551
  C: (f, a) => f(...a)
1514
1552
  });
@@ -1516,7 +1554,7 @@ var Swarm = class {
1516
1554
  async setTopology(topology) {
1517
1555
  invariant4(!this._ctx.disposed, "Swarm is offline", {
1518
1556
  F: __dxlog_file5,
1519
- L: 157,
1557
+ L: 158,
1520
1558
  S: this,
1521
1559
  A: [
1522
1560
  "!this._ctx.disposed",
@@ -1531,7 +1569,7 @@ var Swarm = class {
1531
1569
  topology: getClassName(topology)
1532
1570
  }, {
1533
1571
  F: __dxlog_file5,
1534
- L: 161,
1572
+ L: 162,
1535
1573
  S: this,
1536
1574
  C: (f, a) => f(...a)
1537
1575
  });
@@ -1545,14 +1583,14 @@ var Swarm = class {
1545
1583
  swarmEvent
1546
1584
  }, {
1547
1585
  F: __dxlog_file5,
1548
- L: 174,
1586
+ L: 175,
1549
1587
  S: this,
1550
1588
  C: (f, a) => f(...a)
1551
1589
  });
1552
1590
  if (this._ctx.disposed) {
1553
1591
  log5("swarm event ignored for disposed swarm", void 0, {
1554
1592
  F: __dxlog_file5,
1555
- L: 177,
1593
+ L: 178,
1556
1594
  S: this,
1557
1595
  C: (f, a) => f(...a)
1558
1596
  });
@@ -1565,7 +1603,7 @@ var Swarm = class {
1565
1603
  peerId
1566
1604
  }, {
1567
1605
  F: __dxlog_file5,
1568
- L: 184,
1606
+ L: 185,
1569
1607
  S: this,
1570
1608
  C: (f, a) => f(...a)
1571
1609
  });
@@ -1579,13 +1617,13 @@ var Swarm = class {
1579
1617
  if (this._isConnectionEstablishmentInProgress(peer)) {
1580
1618
  log5(`destroying peer, state: ${peer.connection?.state}`, void 0, {
1581
1619
  F: __dxlog_file5,
1582
- L: 195,
1620
+ L: 196,
1583
1621
  S: this,
1584
1622
  C: (f, a) => f(...a)
1585
1623
  });
1586
1624
  void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log5.catch(err, void 0, {
1587
1625
  F: __dxlog_file5,
1588
- L: 196,
1626
+ L: 197,
1589
1627
  S: this,
1590
1628
  C: (f, a) => f(...a)
1591
1629
  }));
@@ -1595,7 +1633,7 @@ var Swarm = class {
1595
1633
  peer: swarmEvent.peerLeft.peer.peerKey
1596
1634
  }, {
1597
1635
  F: __dxlog_file5,
1598
- L: 199,
1636
+ L: 200,
1599
1637
  S: this,
1600
1638
  C: (f, a) => f(...a)
1601
1639
  });
@@ -1608,14 +1646,14 @@ var Swarm = class {
1608
1646
  message
1609
1647
  }, {
1610
1648
  F: __dxlog_file5,
1611
- L: 208,
1649
+ L: 209,
1612
1650
  S: this,
1613
1651
  C: (f, a) => f(...a)
1614
1652
  });
1615
1653
  if (this._ctx.disposed) {
1616
1654
  log5("ignored for disposed swarm", void 0, {
1617
1655
  F: __dxlog_file5,
1618
- L: 210,
1656
+ L: 211,
1619
1657
  S: this,
1620
1658
  C: (f, a) => f(...a)
1621
1659
  });
@@ -1625,7 +1663,7 @@ var Swarm = class {
1625
1663
  }
1626
1664
  invariant4(message.author, void 0, {
1627
1665
  F: __dxlog_file5,
1628
- L: 215,
1666
+ L: 216,
1629
1667
  S: this,
1630
1668
  A: [
1631
1669
  "message.author",
@@ -1637,7 +1675,7 @@ var Swarm = class {
1637
1675
  message
1638
1676
  }, {
1639
1677
  F: __dxlog_file5,
1640
- L: 217,
1678
+ L: 218,
1641
1679
  S: this,
1642
1680
  C: (f, a) => f(...a)
1643
1681
  });
@@ -1650,7 +1688,7 @@ var Swarm = class {
1650
1688
  message
1651
1689
  }, {
1652
1690
  F: __dxlog_file5,
1653
- L: 221,
1691
+ L: 222,
1654
1692
  S: this,
1655
1693
  C: (f, a) => f(...a)
1656
1694
  });
@@ -1678,14 +1716,14 @@ var Swarm = class {
1678
1716
  message
1679
1717
  }, {
1680
1718
  F: __dxlog_file5,
1681
- L: 246,
1719
+ L: 247,
1682
1720
  S: this,
1683
1721
  C: (f, a) => f(...a)
1684
1722
  });
1685
1723
  if (this._ctx.disposed) {
1686
1724
  log5.info("ignored for offline swarm", void 0, {
1687
1725
  F: __dxlog_file5,
1688
- L: 248,
1726
+ L: 249,
1689
1727
  S: this,
1690
1728
  C: (f, a) => f(...a)
1691
1729
  });
@@ -1693,7 +1731,7 @@ var Swarm = class {
1693
1731
  }
1694
1732
  invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1695
1733
  F: __dxlog_file5,
1696
- L: 251,
1734
+ L: 252,
1697
1735
  S: this,
1698
1736
  A: [
1699
1737
  "message.recipient.peerKey === this._ownPeer.peerKey",
@@ -1702,7 +1740,7 @@ var Swarm = class {
1702
1740
  });
1703
1741
  invariant4(message.topic?.equals(this._topic), void 0, {
1704
1742
  F: __dxlog_file5,
1705
- L: 255,
1743
+ L: 256,
1706
1744
  S: this,
1707
1745
  A: [
1708
1746
  "message.topic?.equals(this._topic)",
@@ -1711,7 +1749,7 @@ var Swarm = class {
1711
1749
  });
1712
1750
  invariant4(message.author, void 0, {
1713
1751
  F: __dxlog_file5,
1714
- L: 256,
1752
+ L: 257,
1715
1753
  S: this,
1716
1754
  A: [
1717
1755
  "message.author",
@@ -1732,13 +1770,13 @@ var Swarm = class {
1732
1770
  async goOnline() {
1733
1771
  this._ctx = new Context4(void 0, {
1734
1772
  F: __dxlog_file5,
1735
- L: 272
1773
+ L: 273
1736
1774
  });
1737
1775
  }
1738
1776
  _getOrCreatePeer(peerInfo) {
1739
1777
  invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
1740
1778
  F: __dxlog_file5,
1741
- L: 276,
1779
+ L: 277,
1742
1780
  S: this,
1743
1781
  A: [
1744
1782
  "peerInfo.peerKey",
@@ -1758,7 +1796,7 @@ var Swarm = class {
1758
1796
  if (this._isUnregistered(peer)) {
1759
1797
  log5.verbose("ignored onDisconnected for unregistered peer", void 0, {
1760
1798
  F: __dxlog_file5,
1761
- L: 296,
1799
+ L: 297,
1762
1800
  S: this,
1763
1801
  C: (f, a) => f(...a)
1764
1802
  });
@@ -1776,7 +1814,7 @@ var Swarm = class {
1776
1814
  peerInfo
1777
1815
  }, {
1778
1816
  F: __dxlog_file5,
1779
- L: 310,
1817
+ L: 311,
1780
1818
  S: this,
1781
1819
  C: (f, a) => f(...a)
1782
1820
  });
@@ -1803,14 +1841,14 @@ var Swarm = class {
1803
1841
  reason
1804
1842
  }, {
1805
1843
  F: __dxlog_file5,
1806
- L: 332,
1844
+ L: 333,
1807
1845
  S: this,
1808
1846
  C: (f, a) => f(...a)
1809
1847
  });
1810
1848
  const peer = this._peers.get(peerInfo);
1811
1849
  invariant4(peer, void 0, {
1812
1850
  F: __dxlog_file5,
1813
- L: 334,
1851
+ L: 335,
1814
1852
  S: this,
1815
1853
  A: [
1816
1854
  "peer",
@@ -1840,7 +1878,7 @@ var Swarm = class {
1840
1878
  } catch (err) {
1841
1879
  log5("initiation error", err, {
1842
1880
  F: __dxlog_file5,
1843
- L: 361,
1881
+ L: 362,
1844
1882
  S: this,
1845
1883
  C: (f, a) => f(...a)
1846
1884
  });
@@ -1871,7 +1909,7 @@ var Swarm = class {
1871
1909
  remotePeer
1872
1910
  }, {
1873
1911
  F: __dxlog_file5,
1874
- L: 389,
1912
+ L: 390,
1875
1913
  S: this,
1876
1914
  C: (f, a) => f(...a)
1877
1915
  });
@@ -1890,7 +1928,7 @@ var Swarm = class {
1890
1928
  remotePeer
1891
1929
  }, {
1892
1930
  F: __dxlog_file5,
1893
- L: 405,
1931
+ L: 406,
1894
1932
  S: this,
1895
1933
  C: (f, a) => f(...a)
1896
1934
  });
@@ -1900,7 +1938,7 @@ var Swarm = class {
1900
1938
  remotePeer
1901
1939
  }, {
1902
1940
  F: __dxlog_file5,
1903
- L: 408,
1941
+ L: 409,
1904
1942
  S: this,
1905
1943
  C: (f, a) => f(...a)
1906
1944
  });
@@ -1925,6 +1963,83 @@ var Swarm = class {
1925
1963
  _isUnregistered(peer) {
1926
1964
  return !peer || this._peers.get(peer.remoteInfo) !== peer;
1927
1965
  }
1966
+ // TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
1967
+ // TODO(burdon): Pass in object.
1968
+ constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
1969
+ _define_property4(this, "_topic", void 0);
1970
+ _define_property4(this, "_ownPeer", void 0);
1971
+ _define_property4(this, "_topology", void 0);
1972
+ _define_property4(this, "_protocolProvider", void 0);
1973
+ _define_property4(this, "_messenger", void 0);
1974
+ _define_property4(this, "_transportFactory", void 0);
1975
+ _define_property4(this, "_label", void 0);
1976
+ _define_property4(this, "_connectionLimiter", void 0);
1977
+ _define_property4(this, "_initiationDelay", void 0);
1978
+ _define_property4(this, "_swarmMessenger", void 0);
1979
+ _define_property4(this, "_ctx", void 0);
1980
+ _define_property4(this, "_listeningHandle", void 0);
1981
+ _define_property4(this, "_peers", void 0);
1982
+ _define_property4(this, "_instanceId", void 0);
1983
+ _define_property4(this, "connectionAdded", void 0);
1984
+ _define_property4(this, "disconnected", void 0);
1985
+ _define_property4(this, "connected", void 0);
1986
+ _define_property4(this, "errors", void 0);
1987
+ this._topic = _topic;
1988
+ this._ownPeer = _ownPeer;
1989
+ this._topology = _topology;
1990
+ this._protocolProvider = _protocolProvider;
1991
+ this._messenger = _messenger;
1992
+ this._transportFactory = _transportFactory;
1993
+ this._label = _label;
1994
+ this._connectionLimiter = _connectionLimiter;
1995
+ this._initiationDelay = _initiationDelay;
1996
+ this._ctx = new Context4(void 0, {
1997
+ F: __dxlog_file5,
1998
+ L: 39
1999
+ });
2000
+ this._listeningHandle = void 0;
2001
+ this._peers = new ComplexMap2(PeerInfoHash);
2002
+ this._instanceId = PublicKey4.random().toHex();
2003
+ this.connectionAdded = new Event3();
2004
+ this.disconnected = new Event3();
2005
+ this.connected = new Event3();
2006
+ this.errors = new ErrorStream2();
2007
+ log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
2008
+ id: this._instanceId,
2009
+ data: {
2010
+ topic: this._topic.toHex(),
2011
+ peer: this._ownPeer
2012
+ }
2013
+ }), {
2014
+ F: __dxlog_file5,
2015
+ L: 89,
2016
+ S: this,
2017
+ C: (f, a) => f(...a)
2018
+ });
2019
+ log5("creating swarm", {
2020
+ peerId: _ownPeer
2021
+ }, {
2022
+ F: __dxlog_file5,
2023
+ L: 93,
2024
+ S: this,
2025
+ C: (f, a) => f(...a)
2026
+ });
2027
+ _topology.init(this._getSwarmController());
2028
+ this._swarmMessenger = new SwarmMessenger({
2029
+ sendMessage: async (msg) => await this._messenger.sendMessage(msg),
2030
+ onSignal: async (msg) => await this.onSignal(msg),
2031
+ onOffer: async (msg) => await this.onOffer(msg),
2032
+ topic: this._topic
2033
+ });
2034
+ log5.trace("dxos.mesh.swarm.constructor", trace2.end({
2035
+ id: this._instanceId
2036
+ }), {
2037
+ F: __dxlog_file5,
2038
+ L: 102,
2039
+ S: this,
2040
+ C: (f, a) => f(...a)
2041
+ });
2042
+ }
1928
2043
  };
1929
2044
  _ts_decorate3([
1930
2045
  logInfo2
@@ -1946,37 +2061,31 @@ _ts_decorate3([
1946
2061
  ], Swarm.prototype, "goOffline", null);
1947
2062
  _ts_decorate3([
1948
2063
  synchronized3
1949
- ], Swarm.prototype, "goOnline", null);
1950
-
1951
- // src/swarm/swarm-mapper.ts
1952
- import { Event as Event4, SubscriptionList } from "@dxos/async";
1953
- import { PublicKey as PublicKey5 } from "@dxos/keys";
1954
- import { log as log6 } from "@dxos/log";
1955
- import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
1956
- import { ComplexMap as ComplexMap3 } from "@dxos/util";
1957
- var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1958
- var SwarmMapper = class {
1959
- get peers() {
1960
- return Array.from(this._peers.values());
1961
- }
1962
- constructor(_swarm) {
1963
- this._swarm = _swarm;
1964
- this._subscriptions = new SubscriptionList();
1965
- this._connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
1966
- this._peers = new ComplexMap3(PeerInfoHash2);
1967
- this.mapUpdated = new Event4();
1968
- this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
1969
- this._update();
1970
- this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
1971
- this._update();
1972
- }));
1973
- }));
1974
- this._subscriptions.add(_swarm.disconnected.on((peerId) => {
1975
- this._connectionSubscriptions.get(peerId)?.();
1976
- this._connectionSubscriptions.delete(peerId);
1977
- this._update();
1978
- }));
1979
- this._update();
2064
+ ], Swarm.prototype, "goOnline", null);
2065
+
2066
+ // src/swarm/swarm-mapper.ts
2067
+ import { Event as Event4, SubscriptionList } from "@dxos/async";
2068
+ import { PublicKey as PublicKey5 } from "@dxos/keys";
2069
+ import { log as log6 } from "@dxos/log";
2070
+ import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
2071
+ import { ComplexMap as ComplexMap3 } from "@dxos/util";
2072
+ function _define_property5(obj, key, value) {
2073
+ if (key in obj) {
2074
+ Object.defineProperty(obj, key, {
2075
+ value,
2076
+ enumerable: true,
2077
+ configurable: true,
2078
+ writable: true
2079
+ });
2080
+ } else {
2081
+ obj[key] = value;
2082
+ }
2083
+ return obj;
2084
+ }
2085
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2086
+ var SwarmMapper = class {
2087
+ get peers() {
2088
+ return Array.from(this._peers.values());
1980
2089
  }
1981
2090
  _update() {
1982
2091
  log6("updating swarm", void 0, {
@@ -2017,6 +2126,30 @@ var SwarmMapper = class {
2017
2126
  this._connectionSubscriptions.clear();
2018
2127
  this._subscriptions.clear();
2019
2128
  }
2129
+ constructor(_swarm) {
2130
+ _define_property5(this, "_swarm", void 0);
2131
+ _define_property5(this, "_subscriptions", void 0);
2132
+ _define_property5(this, "_connectionSubscriptions", void 0);
2133
+ _define_property5(this, "_peers", void 0);
2134
+ _define_property5(this, "mapUpdated", void 0);
2135
+ this._swarm = _swarm;
2136
+ this._subscriptions = new SubscriptionList();
2137
+ this._connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
2138
+ this._peers = new ComplexMap3(PeerInfoHash2);
2139
+ this.mapUpdated = new Event4();
2140
+ this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
2141
+ this._update();
2142
+ this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
2143
+ this._update();
2144
+ }));
2145
+ }));
2146
+ this._subscriptions.add(_swarm.disconnected.on((peerId) => {
2147
+ this._connectionSubscriptions.get(peerId)?.();
2148
+ this._connectionSubscriptions.delete(peerId);
2149
+ this._update();
2150
+ }));
2151
+ this._update();
2152
+ }
2020
2153
  };
2021
2154
 
2022
2155
  // src/swarm/connection-limiter.ts
@@ -2027,25 +2160,22 @@ import { PublicKey as PublicKey6 } from "@dxos/keys";
2027
2160
  import { log as log7 } from "@dxos/log";
2028
2161
  import { CancelledError as CancelledError3 } from "@dxos/protocols";
2029
2162
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
2163
+ function _define_property6(obj, key, value) {
2164
+ if (key in obj) {
2165
+ Object.defineProperty(obj, key, {
2166
+ value,
2167
+ enumerable: true,
2168
+ configurable: true,
2169
+ writable: true
2170
+ });
2171
+ } else {
2172
+ obj[key] = value;
2173
+ }
2174
+ return obj;
2175
+ }
2030
2176
  var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2031
2177
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2032
2178
  var ConnectionLimiter = class {
2033
- constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2034
- this._ctx = new Context5(void 0, {
2035
- F: __dxlog_file7,
2036
- L: 23
2037
- });
2038
- /**
2039
- * Queue of promises to resolve when initiating connections amount is below the limit.
2040
- */
2041
- this._waitingPromises = new ComplexMap4(PublicKey6.hash);
2042
- this.resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
2043
- Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
2044
- resolve();
2045
- });
2046
- });
2047
- this._maxConcurrentInitConnections = maxConcurrentInitConnections;
2048
- }
2049
2179
  /**
2050
2180
  * @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
2051
2181
  */
@@ -2102,6 +2232,20 @@ var ConnectionLimiter = class {
2102
2232
  this._waitingPromises.delete(sessionId);
2103
2233
  this.resolveWaitingPromises.schedule();
2104
2234
  }
2235
+ constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2236
+ _define_property6(this, "_ctx", new Context5(void 0, {
2237
+ F: __dxlog_file7,
2238
+ L: 23
2239
+ }));
2240
+ _define_property6(this, "_maxConcurrentInitConnections", void 0);
2241
+ _define_property6(this, "_waitingPromises", new ComplexMap4(PublicKey6.hash));
2242
+ _define_property6(this, "resolveWaitingPromises", new DeferredTask2(this._ctx, async () => {
2243
+ Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
2244
+ resolve();
2245
+ });
2246
+ }));
2247
+ this._maxConcurrentInitConnections = maxConcurrentInitConnections;
2248
+ }
2105
2249
  };
2106
2250
 
2107
2251
  // src/connection-log.ts
@@ -2109,23 +2253,29 @@ import { Event as Event5 } from "@dxos/async";
2109
2253
  import { raise } from "@dxos/debug";
2110
2254
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2111
2255
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
2256
+ function _define_property7(obj, key, value) {
2257
+ if (key in obj) {
2258
+ Object.defineProperty(obj, key, {
2259
+ value,
2260
+ enumerable: true,
2261
+ configurable: true,
2262
+ writable: true
2263
+ });
2264
+ } else {
2265
+ obj[key] = value;
2266
+ }
2267
+ return obj;
2268
+ }
2112
2269
  var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
2113
- var EventType = /* @__PURE__ */ function(EventType2) {
2270
+ var EventType = /* @__PURE__ */ (function(EventType2) {
2114
2271
  EventType2["CONNECTION_STATE_CHANGED"] = "CONNECTION_STATE_CHANGED";
2115
2272
  EventType2["PROTOCOL_ERROR"] = "PROTOCOL_ERROR";
2116
2273
  EventType2["PROTOCOL_EXTENSIONS_INITIALIZED"] = "PROTOCOL_EXTENSIONS_INITIALIZED";
2117
2274
  EventType2["PROTOCOL_EXTENSIONS_HANDSHAKE"] = "PROTOCOL_EXTENSIONS_HANDSHAKE";
2118
2275
  EventType2["PROTOCOL_HANDSHAKE"] = "PROTOCOL_HANDSHAKE";
2119
2276
  return EventType2;
2120
- }({});
2277
+ })({});
2121
2278
  var ConnectionLog = class {
2122
- constructor() {
2123
- /**
2124
- * SwarmId => info
2125
- */
2126
- this._swarms = new ComplexMap5(PublicKey7.hash);
2127
- this.update = new Event5();
2128
- }
2129
2279
  getSwarmInfo(swarmId) {
2130
2280
  return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
2131
2281
  }
@@ -2189,6 +2339,10 @@ var ConnectionLog = class {
2189
2339
  this.getSwarmInfo(PublicKey7.from(swarm._instanceId)).isActive = false;
2190
2340
  this.update.emit();
2191
2341
  }
2342
+ constructor() {
2343
+ _define_property7(this, "_swarms", new ComplexMap5(PublicKey7.hash));
2344
+ _define_property7(this, "update", new Event5());
2345
+ }
2192
2346
  };
2193
2347
  var gcSwarm = (swarm) => {
2194
2348
  swarm.connections = swarm.connections?.filter((connection) => {
@@ -2205,6 +2359,19 @@ import { Messenger } from "@dxos/messaging";
2205
2359
  import { trace as trace3 } from "@dxos/protocols";
2206
2360
  import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
2207
2361
  import { ComplexMap as ComplexMap6 } from "@dxos/util";
2362
+ function _define_property8(obj, key, value) {
2363
+ if (key in obj) {
2364
+ Object.defineProperty(obj, key, {
2365
+ value,
2366
+ enumerable: true,
2367
+ configurable: true,
2368
+ writable: true
2369
+ });
2370
+ } else {
2371
+ obj[key] = value;
2372
+ }
2373
+ return obj;
2374
+ }
2208
2375
  function _ts_decorate4(decorators, target, key, desc) {
2209
2376
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2210
2377
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -2213,33 +2380,6 @@ function _ts_decorate4(decorators, target, key, desc) {
2213
2380
  }
2214
2381
  var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2215
2382
  var SwarmNetworkManager = class {
2216
- constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }) {
2217
- /**
2218
- * @internal
2219
- */
2220
- this._swarms = new ComplexMap6(PublicKey8.hash);
2221
- this._mappers = new ComplexMap6(PublicKey8.hash);
2222
- this._instanceId = PublicKey8.random().toHex();
2223
- this._peerInfo = void 0;
2224
- this._connectionState = ConnectionState2.ONLINE;
2225
- this.connectionStateChanged = new Event6();
2226
- this.topicsUpdated = new Event6();
2227
- this._transportFactory = transportFactory;
2228
- this._signalManager = signalManager;
2229
- this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
2230
- this._messenger = new Messenger({
2231
- signalManager: this._signalManager
2232
- });
2233
- this._signalConnection = {
2234
- join: (opts) => this._signalManager.join(opts),
2235
- leave: (opts) => this._signalManager.leave(opts)
2236
- };
2237
- this._peerInfo = peerInfo;
2238
- this._connectionLimiter = new ConnectionLimiter();
2239
- if (enableDevtoolsLogging) {
2240
- this._connectionLog = new ConnectionLog();
2241
- }
2242
- }
2243
2383
  // TODO(burdon): Remove access (Devtools only).
2244
2384
  get connectionLog() {
2245
2385
  return this._connectionLog;
@@ -2448,6 +2588,36 @@ var SwarmNetworkManager = class {
2448
2588
  }
2449
2589
  this.connectionStateChanged.emit(this._connectionState);
2450
2590
  }
2591
+ constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }) {
2592
+ _define_property8(this, "_swarms", new ComplexMap6(PublicKey8.hash));
2593
+ _define_property8(this, "_mappers", new ComplexMap6(PublicKey8.hash));
2594
+ _define_property8(this, "_transportFactory", void 0);
2595
+ _define_property8(this, "_signalManager", void 0);
2596
+ _define_property8(this, "_messenger", void 0);
2597
+ _define_property8(this, "_signalConnection", void 0);
2598
+ _define_property8(this, "_connectionLimiter", void 0);
2599
+ _define_property8(this, "_connectionLog", void 0);
2600
+ _define_property8(this, "_instanceId", PublicKey8.random().toHex());
2601
+ _define_property8(this, "_peerInfo", void 0);
2602
+ _define_property8(this, "_connectionState", ConnectionState2.ONLINE);
2603
+ _define_property8(this, "connectionStateChanged", new Event6());
2604
+ _define_property8(this, "topicsUpdated", new Event6());
2605
+ this._transportFactory = transportFactory;
2606
+ this._signalManager = signalManager;
2607
+ this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
2608
+ this._messenger = new Messenger({
2609
+ signalManager: this._signalManager
2610
+ });
2611
+ this._signalConnection = {
2612
+ join: (opts) => this._signalManager.join(opts),
2613
+ leave: (opts) => this._signalManager.leave(opts)
2614
+ };
2615
+ this._peerInfo = peerInfo;
2616
+ this._connectionLimiter = new ConnectionLimiter();
2617
+ if (enableDevtoolsLogging) {
2618
+ this._connectionLog = new ConnectionLog();
2619
+ }
2620
+ }
2451
2621
  };
2452
2622
  _ts_decorate4([
2453
2623
  synchronized4
@@ -2458,6 +2628,19 @@ _ts_decorate4([
2458
2628
 
2459
2629
  // src/topology/fully-connected-topology.ts
2460
2630
  import { invariant as invariant7 } from "@dxos/invariant";
2631
+ function _define_property9(obj, key, value) {
2632
+ if (key in obj) {
2633
+ Object.defineProperty(obj, key, {
2634
+ value,
2635
+ enumerable: true,
2636
+ configurable: true,
2637
+ writable: true
2638
+ });
2639
+ } else {
2640
+ obj[key] = value;
2641
+ }
2642
+ return obj;
2643
+ }
2461
2644
  var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2462
2645
  var FullyConnectedTopology = class {
2463
2646
  toString() {
@@ -2495,22 +2678,31 @@ var FullyConnectedTopology = class {
2495
2678
  }
2496
2679
  async destroy() {
2497
2680
  }
2681
+ constructor() {
2682
+ _define_property9(this, "_controller", void 0);
2683
+ }
2498
2684
  };
2499
2685
 
2500
2686
  // src/topology/mmst-topology.ts
2501
2687
  import { invariant as invariant8 } from "@dxos/invariant";
2502
2688
  import { log as log9 } from "@dxos/log";
2689
+ function _define_property10(obj, key, value) {
2690
+ if (key in obj) {
2691
+ Object.defineProperty(obj, key, {
2692
+ value,
2693
+ enumerable: true,
2694
+ configurable: true,
2695
+ writable: true
2696
+ });
2697
+ } else {
2698
+ obj[key] = value;
2699
+ }
2700
+ return obj;
2701
+ }
2503
2702
  var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2504
2703
  var MIN_UPDATE_INTERVAL = 1e3 * 10;
2505
2704
  var MAX_CHANGES_PER_UPDATE = 1;
2506
2705
  var MMSTTopology = class {
2507
- constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2508
- this._sampleCollected = false;
2509
- this._lastAction = /* @__PURE__ */ new Date(0);
2510
- this._originateConnections = originateConnections;
2511
- this._maxPeers = maxPeers;
2512
- this._sampleSize = sampleSize;
2513
- }
2514
2706
  init(controller) {
2515
2707
  invariant8(!this._controller, "Already initialized", {
2516
2708
  F: __dxlog_file10,
@@ -2667,6 +2859,17 @@ var MMSTTopology = class {
2667
2859
  toString() {
2668
2860
  return "MMSTTopology";
2669
2861
  }
2862
+ constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2863
+ _define_property10(this, "_originateConnections", void 0);
2864
+ _define_property10(this, "_maxPeers", void 0);
2865
+ _define_property10(this, "_sampleSize", void 0);
2866
+ _define_property10(this, "_controller", void 0);
2867
+ _define_property10(this, "_sampleCollected", false);
2868
+ _define_property10(this, "_lastAction", /* @__PURE__ */ new Date(0));
2869
+ this._originateConnections = originateConnections;
2870
+ this._maxPeers = maxPeers;
2871
+ this._sampleSize = sampleSize;
2872
+ }
2670
2873
  };
2671
2874
  var sortByXorDistance = (keys, reference) => {
2672
2875
  const sorted = keys.sort((a, b) => {
@@ -2706,11 +2909,21 @@ var compareXor = (a, b) => {
2706
2909
  // src/topology/star-topology.ts
2707
2910
  import { invariant as invariant9 } from "@dxos/invariant";
2708
2911
  import { log as log10 } from "@dxos/log";
2912
+ function _define_property11(obj, key, value) {
2913
+ if (key in obj) {
2914
+ Object.defineProperty(obj, key, {
2915
+ value,
2916
+ enumerable: true,
2917
+ configurable: true,
2918
+ writable: true
2919
+ });
2920
+ } else {
2921
+ obj[key] = value;
2922
+ }
2923
+ return obj;
2924
+ }
2709
2925
  var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2710
2926
  var StarTopology = class {
2711
- constructor(_centralPeer) {
2712
- this._centralPeer = _centralPeer;
2713
- }
2714
2927
  toString() {
2715
2928
  return `StarTopology(${this._centralPeer.truncate()})`;
2716
2929
  }
@@ -2797,6 +3010,11 @@ var StarTopology = class {
2797
3010
  }
2798
3011
  async destroy() {
2799
3012
  }
3013
+ constructor(_centralPeer) {
3014
+ _define_property11(this, "_centralPeer", void 0);
3015
+ _define_property11(this, "_controller", void 0);
3016
+ this._centralPeer = _centralPeer;
3017
+ }
2800
3018
  };
2801
3019
 
2802
3020
  // src/transport/memory-transport.ts
@@ -2807,6 +3025,19 @@ import { invariant as invariant10 } from "@dxos/invariant";
2807
3025
  import { PublicKey as PublicKey9 } from "@dxos/keys";
2808
3026
  import { log as log11, logInfo as logInfo3 } from "@dxos/log";
2809
3027
  import { ComplexMap as ComplexMap7 } from "@dxos/util";
3028
+ function _define_property12(obj, key, value) {
3029
+ if (key in obj) {
3030
+ Object.defineProperty(obj, key, {
3031
+ value,
3032
+ enumerable: true,
3033
+ configurable: true,
3034
+ writable: true
3035
+ });
3036
+ } else {
3037
+ obj[key] = value;
3038
+ }
3039
+ return obj;
3040
+ }
2810
3041
  function _ts_decorate5(decorators, target, key, desc) {
2811
3042
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2812
3043
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -2827,31 +3058,6 @@ var MemoryTransportFactory = {
2827
3058
  createTransport: (options) => new MemoryTransport(options)
2828
3059
  };
2829
3060
  var MemoryTransport = class _MemoryTransport {
2830
- static {
2831
- // TODO(burdon): Remove static properties (inject context into constructor).
2832
- this._connections = new ComplexMap7(PublicKey9.hash);
2833
- }
2834
- constructor(_options) {
2835
- this._options = _options;
2836
- this._instanceId = PublicKey9.random();
2837
- this._remote = new Trigger2();
2838
- this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2839
- this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2840
- this._closed = false;
2841
- this.closed = new Event7();
2842
- this.connected = new Event7();
2843
- this.errors = new ErrorStream3();
2844
- invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2845
- F: __dxlog_file12,
2846
- L: 64,
2847
- S: this,
2848
- A: [
2849
- "!MemoryTransport._connections.has(this._instanceId)",
2850
- "'Duplicate memory connection'"
2851
- ]
2852
- });
2853
- _MemoryTransport._connections.set(this._instanceId, this);
2854
- }
2855
3061
  get isOpen() {
2856
3062
  return !this._closed;
2857
3063
  }
@@ -2982,7 +3188,40 @@ var MemoryTransport = class _MemoryTransport {
2982
3188
  packetsReceived: 0
2983
3189
  };
2984
3190
  }
3191
+ constructor(_options) {
3192
+ _define_property12(this, "_options", void 0);
3193
+ _define_property12(this, "_instanceId", void 0);
3194
+ _define_property12(this, "_remote", void 0);
3195
+ _define_property12(this, "_outgoingDelay", void 0);
3196
+ _define_property12(this, "_incomingDelay", void 0);
3197
+ _define_property12(this, "_closed", void 0);
3198
+ _define_property12(this, "_remoteInstanceId", void 0);
3199
+ _define_property12(this, "_remoteConnection", void 0);
3200
+ _define_property12(this, "closed", void 0);
3201
+ _define_property12(this, "connected", void 0);
3202
+ _define_property12(this, "errors", void 0);
3203
+ this._options = _options;
3204
+ this._instanceId = PublicKey9.random();
3205
+ this._remote = new Trigger2();
3206
+ this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
3207
+ this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
3208
+ this._closed = false;
3209
+ this.closed = new Event7();
3210
+ this.connected = new Event7();
3211
+ this.errors = new ErrorStream3();
3212
+ invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
3213
+ F: __dxlog_file12,
3214
+ L: 64,
3215
+ S: this,
3216
+ A: [
3217
+ "!MemoryTransport._connections.has(this._instanceId)",
3218
+ "'Duplicate memory connection'"
3219
+ ]
3220
+ });
3221
+ _MemoryTransport._connections.set(this._instanceId, this);
3222
+ }
2985
3223
  };
3224
+ _define_property12(MemoryTransport, "_connections", new ComplexMap7(PublicKey9.hash));
2986
3225
  _ts_decorate5([
2987
3226
  logInfo3
2988
3227
  ], MemoryTransport.prototype, "_instanceId", void 0);
@@ -2992,16 +3231,29 @@ _ts_decorate5([
2992
3231
  var toError = (err) => err instanceof Error ? err : new Error(String(err));
2993
3232
 
2994
3233
  // src/transport/transport.ts
2995
- var TransportKind = /* @__PURE__ */ function(TransportKind2) {
3234
+ var TransportKind = /* @__PURE__ */ (function(TransportKind2) {
2996
3235
  TransportKind2["WEB_RTC"] = "WEB-RTC";
2997
3236
  TransportKind2["WEB_RTC_PROXY"] = "WEB-RTC_PROXY";
2998
3237
  TransportKind2["MEMORY"] = "MEMORY";
2999
3238
  TransportKind2["TCP"] = "TCP";
3000
3239
  return TransportKind2;
3001
- }({});
3240
+ })({});
3002
3241
 
3003
3242
  // src/transport/webrtc/rtc-connection-factory.ts
3004
3243
  import { Mutex } from "@dxos/async";
3244
+ function _define_property13(obj, key, value) {
3245
+ if (key in obj) {
3246
+ Object.defineProperty(obj, key, {
3247
+ value,
3248
+ enumerable: true,
3249
+ configurable: true,
3250
+ writable: true
3251
+ });
3252
+ } else {
3253
+ obj[key] = value;
3254
+ }
3255
+ return obj;
3256
+ }
3005
3257
  var BrowserRtcConnectionFactory = class {
3006
3258
  async initialize() {
3007
3259
  }
@@ -3014,14 +3266,8 @@ var BrowserRtcConnectionFactory = class {
3014
3266
  }
3015
3267
  };
3016
3268
  var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
3017
- static {
3018
- this._createdConnections = 0;
3019
- }
3020
- static {
3021
- this._cleanupMutex = new Mutex();
3022
- }
3023
3269
  // This should be inside the function to avoid triggering `eval` in the global scope.
3024
- // eslint-disable-next-line no-new-func
3270
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
3025
3271
  // TODO(burdon): Do imports here?
3026
3272
  async initialize() {
3027
3273
  }
@@ -3045,12 +3291,14 @@ var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
3045
3291
  }
3046
3292
  }
3047
3293
  };
3294
+ _define_property13(NodeRtcConnectionFactory, "_createdConnections", 0);
3295
+ _define_property13(NodeRtcConnectionFactory, "_cleanupMutex", new Mutex());
3048
3296
  var getRtcConnectionFactory = () => {
3049
3297
  return typeof globalThis.RTCPeerConnection === "undefined" ? new NodeRtcConnectionFactory() : new BrowserRtcConnectionFactory();
3050
3298
  };
3051
3299
 
3052
3300
  // src/transport/webrtc/rtc-peer-connection.ts
3053
- import { synchronized as synchronized5, Trigger as Trigger3, Mutex as Mutex2 } from "@dxos/async";
3301
+ import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
3054
3302
  import { invariant as invariant12 } from "@dxos/invariant";
3055
3303
  import { log as log13, logInfo as logInfo4 } from "@dxos/log";
3056
3304
  import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
@@ -3113,13 +3361,23 @@ var getRtcConnectionStats = async (connection, channelTopic) => {
3113
3361
  };
3114
3362
 
3115
3363
  // src/transport/webrtc/rtc-transport-channel.ts
3364
+ function _define_property14(obj, key, value) {
3365
+ if (key in obj) {
3366
+ Object.defineProperty(obj, key, {
3367
+ value,
3368
+ enumerable: true,
3369
+ configurable: true,
3370
+ writable: true
3371
+ });
3372
+ } else {
3373
+ obj[key] = value;
3374
+ }
3375
+ return obj;
3376
+ }
3116
3377
  var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
3117
3378
  var MAX_MESSAGE_SIZE = 64 * 1024;
3118
3379
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3119
3380
  var RtcTransportChannel = class extends Resource {
3120
- constructor(_connection, _options) {
3121
- super(), this._connection = _connection, this._options = _options, this.closed = new AsyncEvent(), this.connected = new AsyncEvent(), this.errors = new ErrorStream4(), this._streamDataFlushedCallback = null, this._isChannelCreationInProgress = false;
3122
- }
3123
3381
  get isRtcChannelCreationInProgress() {
3124
3382
  return this._isChannelCreationInProgress;
3125
3383
  }
@@ -3131,7 +3389,7 @@ var RtcTransportChannel = class extends Resource {
3131
3389
  async _open() {
3132
3390
  invariant11(!this._isChannelCreationInProgress, void 0, {
3133
3391
  F: __dxlog_file13,
3134
- L: 56,
3392
+ L: 57,
3135
3393
  S: this,
3136
3394
  A: [
3137
3395
  "!this._isChannelCreationInProgress",
@@ -3155,7 +3413,7 @@ var RtcTransportChannel = class extends Resource {
3155
3413
  err
3156
3414
  }, {
3157
3415
  F: __dxlog_file13,
3158
- L: 76,
3416
+ L: 77,
3159
3417
  S: this,
3160
3418
  C: (f, a) => f(...a)
3161
3419
  });
@@ -3173,7 +3431,7 @@ var RtcTransportChannel = class extends Resource {
3173
3431
  this.closed.emit();
3174
3432
  log12("closed", void 0, {
3175
3433
  F: __dxlog_file13,
3176
- L: 92,
3434
+ L: 93,
3177
3435
  S: this,
3178
3436
  C: (f, a) => f(...a)
3179
3437
  });
@@ -3186,7 +3444,7 @@ var RtcTransportChannel = class extends Resource {
3186
3444
  topic: this._options.topic
3187
3445
  }, {
3188
3446
  F: __dxlog_file13,
3189
- L: 99,
3447
+ L: 100,
3190
3448
  S: this,
3191
3449
  C: (f, a) => f(...a)
3192
3450
  });
@@ -3195,7 +3453,7 @@ var RtcTransportChannel = class extends Resource {
3195
3453
  }
3196
3454
  log12("onopen", void 0, {
3197
3455
  F: __dxlog_file13,
3198
- L: 104,
3456
+ L: 105,
3199
3457
  S: this,
3200
3458
  C: (f, a) => f(...a)
3201
3459
  });
@@ -3213,7 +3471,7 @@ var RtcTransportChannel = class extends Resource {
3213
3471
  onclose: async () => {
3214
3472
  log12("onclose", void 0, {
3215
3473
  F: __dxlog_file13,
3216
- L: 117,
3474
+ L: 118,
3217
3475
  S: this,
3218
3476
  C: (f, a) => f(...a)
3219
3477
  });
@@ -3223,7 +3481,7 @@ var RtcTransportChannel = class extends Resource {
3223
3481
  if (!this._stream) {
3224
3482
  log12.warn("ignoring message on a closed channel", void 0, {
3225
3483
  F: __dxlog_file13,
3226
- L: 123,
3484
+ L: 124,
3227
3485
  S: this,
3228
3486
  C: (f, a) => f(...a)
3229
3487
  });
@@ -3254,7 +3512,7 @@ var RtcTransportChannel = class extends Resource {
3254
3512
  if (!this._channel) {
3255
3513
  log12.warn("writing to a channel after a connection was closed", void 0, {
3256
3514
  F: __dxlog_file13,
3257
- L: 153,
3515
+ L: 154,
3258
3516
  S: this,
3259
3517
  C: (f, a) => f(...a)
3260
3518
  });
@@ -3277,7 +3535,7 @@ var RtcTransportChannel = class extends Resource {
3277
3535
  if (this._streamDataFlushedCallback !== null) {
3278
3536
  log12.error("consumer trying to write before we are ready for more data", void 0, {
3279
3537
  F: __dxlog_file13,
3280
- L: 174,
3538
+ L: 175,
3281
3539
  S: this,
3282
3540
  C: (f, a) => f(...a)
3283
3541
  });
@@ -3293,7 +3551,7 @@ var RtcTransportChannel = class extends Resource {
3293
3551
  } catch (error) {
3294
3552
  log12.catch(error, void 0, {
3295
3553
  F: __dxlog_file13,
3296
- L: 186,
3554
+ L: 187,
3297
3555
  S: this,
3298
3556
  C: (f, a) => f(...a)
3299
3557
  });
@@ -3308,6 +3566,9 @@ var RtcTransportChannel = class extends Resource {
3308
3566
  async getStats() {
3309
3567
  return createRtcTransportStats(this._connection.currentConnection, this._options.topic);
3310
3568
  }
3569
+ constructor(_connection, _options) {
3570
+ super(), _define_property14(this, "_connection", void 0), _define_property14(this, "_options", void 0), _define_property14(this, "closed", void 0), _define_property14(this, "connected", void 0), _define_property14(this, "errors", void 0), _define_property14(this, "_channel", void 0), _define_property14(this, "_stream", void 0), _define_property14(this, "_streamDataFlushedCallback", void 0), _define_property14(this, "_isChannelCreationInProgress", void 0), this._connection = _connection, this._options = _options, this.closed = new AsyncEvent(), this.connected = new AsyncEvent(), this.errors = new ErrorStream4(), this._streamDataFlushedCallback = null, this._isChannelCreationInProgress = false;
3571
+ }
3311
3572
  };
3312
3573
 
3313
3574
  // src/transport/webrtc/utils.ts
@@ -3337,6 +3598,19 @@ var deduplicatedSdpLines = (sdp) => {
3337
3598
  };
3338
3599
 
3339
3600
  // src/transport/webrtc/rtc-peer-connection.ts
3601
+ function _define_property15(obj, key, value) {
3602
+ if (key in obj) {
3603
+ Object.defineProperty(obj, key, {
3604
+ value,
3605
+ enumerable: true,
3606
+ configurable: true,
3607
+ writable: true
3608
+ });
3609
+ } else {
3610
+ obj[key] = value;
3611
+ }
3612
+ return obj;
3613
+ }
3340
3614
  function _ts_decorate6(decorators, target, key, desc) {
3341
3615
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3342
3616
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -3345,16 +3619,6 @@ function _ts_decorate6(decorators, target, key, desc) {
3345
3619
  }
3346
3620
  var __dxlog_file14 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
3347
3621
  var RtcPeerConnection = class {
3348
- constructor(_factory, _options) {
3349
- this._factory = _factory;
3350
- this._options = _options;
3351
- this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
3352
- this._transportChannels = /* @__PURE__ */ new Map();
3353
- this._dataChannels = /* @__PURE__ */ new Map();
3354
- this._readyForCandidates = new Trigger3();
3355
- this._offerProcessingMutex = new Mutex2();
3356
- this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
3357
- }
3358
3622
  get transportChannelCount() {
3359
3623
  return this._transportChannels.size;
3360
3624
  }
@@ -3380,7 +3644,7 @@ var RtcPeerConnection = class {
3380
3644
  }
3381
3645
  log13("waiting for initiator-peer to open a data channel", void 0, {
3382
3646
  F: __dxlog_file14,
3383
- L: 95,
3647
+ L: 96,
3384
3648
  S: this,
3385
3649
  C: (f, a) => f(...a)
3386
3650
  });
@@ -3411,7 +3675,7 @@ var RtcPeerConnection = class {
3411
3675
  remotePeer: this._options.remotePeerKey
3412
3676
  }), {
3413
3677
  F: __dxlog_file14,
3414
- L: 120,
3678
+ L: 121,
3415
3679
  S: this,
3416
3680
  C: (f, a) => f(...a)
3417
3681
  });
@@ -3422,7 +3686,7 @@ var RtcPeerConnection = class {
3422
3686
  onnegotiationneeded: async () => {
3423
3687
  invariant12(this._initiator, void 0, {
3424
3688
  F: __dxlog_file14,
3425
- L: 135,
3689
+ L: 136,
3426
3690
  S: this,
3427
3691
  A: [
3428
3692
  "this._initiator",
@@ -3435,7 +3699,7 @@ var RtcPeerConnection = class {
3435
3699
  }
3436
3700
  log13("onnegotiationneeded", void 0, {
3437
3701
  F: __dxlog_file14,
3438
- L: 142,
3702
+ L: 143,
3439
3703
  S: this,
3440
3704
  C: (f, a) => f(...a)
3441
3705
  });
@@ -3459,7 +3723,7 @@ var RtcPeerConnection = class {
3459
3723
  candidate: event.candidate.candidate
3460
3724
  }, {
3461
3725
  F: __dxlog_file14,
3462
- L: 161,
3726
+ L: 162,
3463
3727
  S: this,
3464
3728
  C: (f, a) => f(...a)
3465
3729
  });
@@ -3467,7 +3731,7 @@ var RtcPeerConnection = class {
3467
3731
  } else {
3468
3732
  log13("onicecandidate gathering complete", void 0, {
3469
3733
  F: __dxlog_file14,
3470
- L: 164,
3734
+ L: 165,
3471
3735
  S: this,
3472
3736
  C: (f, a) => f(...a)
3473
3737
  });
@@ -3495,7 +3759,7 @@ var RtcPeerConnection = class {
3495
3759
  state: connection.iceConnectionState
3496
3760
  }, {
3497
3761
  F: __dxlog_file14,
3498
- L: 184,
3762
+ L: 185,
3499
3763
  S: this,
3500
3764
  C: (f, a) => f(...a)
3501
3765
  });
@@ -3517,7 +3781,7 @@ var RtcPeerConnection = class {
3517
3781
  state: connection.connectionState
3518
3782
  }, {
3519
3783
  F: __dxlog_file14,
3520
- L: 201,
3784
+ L: 202,
3521
3785
  S: this,
3522
3786
  C: (f, a) => f(...a)
3523
3787
  });
@@ -3530,7 +3794,7 @@ var RtcPeerConnection = class {
3530
3794
  state: connection.signalingState
3531
3795
  }, {
3532
3796
  F: __dxlog_file14,
3533
- L: 208,
3797
+ L: 209,
3534
3798
  S: this,
3535
3799
  C: (f, a) => f(...a)
3536
3800
  });
@@ -3540,7 +3804,7 @@ var RtcPeerConnection = class {
3540
3804
  ondatachannel: (event) => {
3541
3805
  invariant12(!this._initiator, "Initiator is expected to create data channels.", {
3542
3806
  F: __dxlog_file14,
3543
- L: 214,
3807
+ L: 215,
3544
3808
  S: this,
3545
3809
  A: [
3546
3810
  "!this._initiator",
@@ -3555,7 +3819,7 @@ var RtcPeerConnection = class {
3555
3819
  label: event.channel.label
3556
3820
  }, {
3557
3821
  F: __dxlog_file14,
3558
- L: 221,
3822
+ L: 222,
3559
3823
  S: this,
3560
3824
  C: (f, a) => f(...a)
3561
3825
  });
@@ -3583,7 +3847,7 @@ var RtcPeerConnection = class {
3583
3847
  error
3584
3848
  }, {
3585
3849
  F: __dxlog_file14,
3586
- L: 246,
3850
+ L: 247,
3587
3851
  S: this,
3588
3852
  C: (f, a) => f(...a)
3589
3853
  });
@@ -3604,7 +3868,7 @@ var RtcPeerConnection = class {
3604
3868
  reason: error.message
3605
3869
  }, {
3606
3870
  F: __dxlog_file14,
3607
- L: 260,
3871
+ L: 261,
3608
3872
  S: this,
3609
3873
  C: (f, a) => f(...a)
3610
3874
  });
@@ -3612,7 +3876,7 @@ var RtcPeerConnection = class {
3612
3876
  async _lockAndCloseConnection() {
3613
3877
  invariant12(this._transportChannels.size === 0, void 0, {
3614
3878
  F: __dxlog_file14,
3615
- L: 265,
3879
+ L: 266,
3616
3880
  S: this,
3617
3881
  A: [
3618
3882
  "this._transportChannels.size === 0",
@@ -3623,7 +3887,7 @@ var RtcPeerConnection = class {
3623
3887
  this._safeCloseConnection();
3624
3888
  log13("connection closed", void 0, {
3625
3889
  F: __dxlog_file14,
3626
- L: 268,
3890
+ L: 269,
3627
3891
  S: this,
3628
3892
  C: (f, a) => f(...a)
3629
3893
  });
@@ -3636,7 +3900,7 @@ var RtcPeerConnection = class {
3636
3900
  type: signal.payload.data.type
3637
3901
  }, {
3638
3902
  F: __dxlog_file14,
3639
- L: 276,
3903
+ L: 277,
3640
3904
  S: this,
3641
3905
  C: (f, a) => f(...a)
3642
3906
  });
@@ -3703,7 +3967,7 @@ var RtcPeerConnection = class {
3703
3967
  type: data.type
3704
3968
  }, {
3705
3969
  F: __dxlog_file14,
3706
- L: 335,
3970
+ L: 336,
3707
3971
  S: this,
3708
3972
  C: (f, a) => f(...a)
3709
3973
  });
@@ -3716,7 +3980,7 @@ var RtcPeerConnection = class {
3716
3980
  candidate
3717
3981
  }, {
3718
3982
  F: __dxlog_file14,
3719
- L: 343,
3983
+ L: 344,
3720
3984
  S: this,
3721
3985
  C: (f, a) => f(...a)
3722
3986
  });
@@ -3725,7 +3989,7 @@ var RtcPeerConnection = class {
3725
3989
  } catch (err) {
3726
3990
  log13.catch(err, void 0, {
3727
3991
  F: __dxlog_file14,
3728
- L: 347,
3992
+ L: 348,
3729
3993
  S: this,
3730
3994
  C: (f, a) => f(...a)
3731
3995
  });
@@ -3735,7 +3999,7 @@ var RtcPeerConnection = class {
3735
3999
  if (connection === this._connection) {
3736
4000
  log13("ready to process ice candidates", void 0, {
3737
4001
  F: __dxlog_file14,
3738
- L: 353,
4002
+ L: 354,
3739
4003
  S: this,
3740
4004
  C: (f, a) => f(...a)
3741
4005
  });
@@ -3743,7 +4007,7 @@ var RtcPeerConnection = class {
3743
4007
  } else {
3744
4008
  log13.warn("session was negotiated after connection became inactive", void 0, {
3745
4009
  F: __dxlog_file14,
3746
- L: 356,
4010
+ L: 357,
3747
4011
  S: this,
3748
4012
  C: (f, a) => f(...a)
3749
4013
  });
@@ -3755,7 +4019,7 @@ var RtcPeerConnection = class {
3755
4019
  state: connection.connectionState
3756
4020
  }, {
3757
4021
  F: __dxlog_file14,
3758
- L: 361,
4022
+ L: 362,
3759
4023
  S: this,
3760
4024
  C: (f, a) => f(...a)
3761
4025
  });
@@ -3768,7 +4032,7 @@ var RtcPeerConnection = class {
3768
4032
  } catch (err) {
3769
4033
  log13.catch(err, void 0, {
3770
4034
  F: __dxlog_file14,
3771
- L: 373,
4035
+ L: 374,
3772
4036
  S: this,
3773
4037
  C: (f, a) => f(...a)
3774
4038
  });
@@ -3779,7 +4043,7 @@ var RtcPeerConnection = class {
3779
4043
  this._readyForCandidates.wake();
3780
4044
  void this._factory.onConnectionDestroyed().catch((err) => log13.catch(err, void 0, {
3781
4045
  F: __dxlog_file14,
3782
- L: 379,
4046
+ L: 380,
3783
4047
  S: this,
3784
4048
  C: (f, a) => f(...a)
3785
4049
  }));
@@ -3804,7 +4068,7 @@ var RtcPeerConnection = class {
3804
4068
  } catch (error) {
3805
4069
  log13.catch(error, void 0, {
3806
4070
  F: __dxlog_file14,
3807
- L: 395,
4071
+ L: 396,
3808
4072
  S: this,
3809
4073
  C: (f, a) => f(...a)
3810
4074
  });
@@ -3831,7 +4095,7 @@ var RtcPeerConnection = class {
3831
4095
  err
3832
4096
  }, {
3833
4097
  F: __dxlog_file14,
3834
- L: 416,
4098
+ L: 417,
3835
4099
  S: this,
3836
4100
  C: (f, a) => f(...a)
3837
4101
  });
@@ -3878,6 +4142,25 @@ var RtcPeerConnection = class {
3878
4142
  channels: this._transportChannels.size
3879
4143
  };
3880
4144
  }
4145
+ constructor(_factory, _options) {
4146
+ _define_property15(this, "_factory", void 0);
4147
+ _define_property15(this, "_options", void 0);
4148
+ _define_property15(this, "_channelCreatedCallbacks", void 0);
4149
+ _define_property15(this, "_transportChannels", void 0);
4150
+ _define_property15(this, "_dataChannels", void 0);
4151
+ _define_property15(this, "_readyForCandidates", void 0);
4152
+ _define_property15(this, "_offerProcessingMutex", void 0);
4153
+ _define_property15(this, "_initiator", void 0);
4154
+ _define_property15(this, "_connection", void 0);
4155
+ this._factory = _factory;
4156
+ this._options = _options;
4157
+ this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
4158
+ this._transportChannels = /* @__PURE__ */ new Map();
4159
+ this._dataChannels = /* @__PURE__ */ new Map();
4160
+ this._readyForCandidates = new Trigger3();
4161
+ this._offerProcessingMutex = new Mutex2();
4162
+ this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
4163
+ }
3881
4164
  };
3882
4165
  _ts_decorate6([
3883
4166
  synchronized5
@@ -3941,14 +4224,24 @@ import { log as log14 } from "@dxos/log";
3941
4224
  import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
3942
4225
  import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3943
4226
  import { arrayToBuffer } from "@dxos/util";
4227
+ function _define_property16(obj, key, value) {
4228
+ if (key in obj) {
4229
+ Object.defineProperty(obj, key, {
4230
+ value,
4231
+ enumerable: true,
4232
+ configurable: true,
4233
+ writable: true
4234
+ });
4235
+ } else {
4236
+ obj[key] = value;
4237
+ }
4238
+ return obj;
4239
+ }
3944
4240
  var __dxlog_file15 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
3945
4241
  var RPC_TIMEOUT = 1e4;
3946
4242
  var CLOSE_RPC_TIMEOUT = 3e3;
3947
4243
  var RESP_MIN_THRESHOLD = 500;
3948
4244
  var RtcTransportProxy = class extends Resource2 {
3949
- constructor(_options) {
3950
- super(), this._options = _options, this._proxyId = PublicKey10.random(), this.closed = new Event8(), this.connected = new Event8(), this.errors = new ErrorStream5();
3951
- }
3952
4245
  async _open() {
3953
4246
  let stream;
3954
4247
  try {
@@ -4154,11 +4447,11 @@ var RtcTransportProxy = class extends Resource2 {
4154
4447
  void this._serviceStream?.close();
4155
4448
  this.closed.emit();
4156
4449
  }
4450
+ constructor(_options) {
4451
+ super(), _define_property16(this, "_options", void 0), _define_property16(this, "_proxyId", void 0), _define_property16(this, "closed", void 0), _define_property16(this, "connected", void 0), _define_property16(this, "errors", void 0), _define_property16(this, "_serviceStream", void 0), this._options = _options, this._proxyId = PublicKey10.random(), this.closed = new Event8(), this.connected = new Event8(), this.errors = new ErrorStream5();
4452
+ }
4157
4453
  };
4158
4454
  var RtcTransportProxyFactory = class {
4159
- constructor() {
4160
- this._connections = /* @__PURE__ */ new Set();
4161
- }
4162
4455
  /**
4163
4456
  * Sets the current BridgeService to be used to open connections.
4164
4457
  * Calling this method will close any existing connections.
@@ -4190,6 +4483,10 @@ var RtcTransportProxyFactory = class {
4190
4483
  });
4191
4484
  return transport;
4192
4485
  }
4486
+ constructor() {
4487
+ _define_property16(this, "_bridgeService", void 0);
4488
+ _define_property16(this, "_connections", /* @__PURE__ */ new Set());
4489
+ }
4193
4490
  };
4194
4491
  var decodeError = (err) => {
4195
4492
  const message = typeof err === "string" ? err : err.message;
@@ -4212,12 +4509,21 @@ import { PublicKey as PublicKey11 } from "@dxos/keys";
4212
4509
  import { log as log15 } from "@dxos/log";
4213
4510
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
4214
4511
  import { ComplexMap as ComplexMap8 } from "@dxos/util";
4512
+ function _define_property17(obj, key, value) {
4513
+ if (key in obj) {
4514
+ Object.defineProperty(obj, key, {
4515
+ value,
4516
+ enumerable: true,
4517
+ configurable: true,
4518
+ writable: true
4519
+ });
4520
+ } else {
4521
+ obj[key] = value;
4522
+ }
4523
+ return obj;
4524
+ }
4215
4525
  var __dxlog_file16 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
4216
4526
  var RtcTransportService = class {
4217
- constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
4218
- this._transportFactory = _transportFactory;
4219
- this._openTransports = new ComplexMap8(PublicKey11.hash);
4220
- }
4221
4527
  hasOpenTransports() {
4222
4528
  return this._openTransports.size > 0;
4223
4529
  }
@@ -4226,7 +4532,7 @@ var RtcTransportService = class {
4226
4532
  if (existingTransport) {
4227
4533
  log15.error("requesting a new transport bridge for an existing proxy", void 0, {
4228
4534
  F: __dxlog_file16,
4229
- L: 53,
4535
+ L: 54,
4230
4536
  S: this,
4231
4537
  C: (f, a) => f(...a)
4232
4538
  });
@@ -4292,7 +4598,7 @@ var RtcTransportService = class {
4292
4598
  ready();
4293
4599
  log15("stream ready", void 0, {
4294
4600
  F: __dxlog_file16,
4295
- L: 115,
4601
+ L: 116,
4296
4602
  S: this,
4297
4603
  C: (f, a) => f(...a)
4298
4604
  });
@@ -4303,7 +4609,7 @@ var RtcTransportService = class {
4303
4609
  const transport = this._openTransports.get(proxyId);
4304
4610
  invariant14(transport, void 0, {
4305
4611
  F: __dxlog_file16,
4306
- L: 123,
4612
+ L: 124,
4307
4613
  S: this,
4308
4614
  A: [
4309
4615
  "transport",
@@ -4316,7 +4622,7 @@ var RtcTransportService = class {
4316
4622
  const transport = this._openTransports.get(proxyId);
4317
4623
  invariant14(transport, void 0, {
4318
4624
  F: __dxlog_file16,
4319
- L: 130,
4625
+ L: 131,
4320
4626
  S: this,
4321
4627
  A: [
4322
4628
  "transport",
@@ -4331,7 +4637,7 @@ var RtcTransportService = class {
4331
4637
  const transport = this._openTransports.get(proxyId);
4332
4638
  invariant14(transport, void 0, {
4333
4639
  F: __dxlog_file16,
4334
- L: 137,
4640
+ L: 138,
4335
4641
  S: this,
4336
4642
  A: [
4337
4643
  "transport",
@@ -4346,7 +4652,7 @@ var RtcTransportService = class {
4346
4652
  const transport = this._openTransports.get(proxyId);
4347
4653
  invariant14(transport, void 0, {
4348
4654
  F: __dxlog_file16,
4349
- L: 144,
4655
+ L: 145,
4350
4656
  S: this,
4351
4657
  A: [
4352
4658
  "transport",
@@ -4380,7 +4686,7 @@ var RtcTransportService = class {
4380
4686
  message: error?.message
4381
4687
  }, {
4382
4688
  F: __dxlog_file16,
4383
- L: 174,
4689
+ L: 175,
4384
4690
  S: this,
4385
4691
  C: (f, a) => f(...a)
4386
4692
  });
@@ -4392,18 +4698,24 @@ var RtcTransportService = class {
4392
4698
  message: error?.message
4393
4699
  }, {
4394
4700
  F: __dxlog_file16,
4395
- L: 179,
4701
+ L: 180,
4396
4702
  S: this,
4397
4703
  C: (f, a) => f(...a)
4398
4704
  });
4399
4705
  }
4400
4706
  log15("closed", void 0, {
4401
4707
  F: __dxlog_file16,
4402
- L: 181,
4708
+ L: 182,
4403
4709
  S: this,
4404
4710
  C: (f, a) => f(...a)
4405
4711
  });
4406
4712
  }
4713
+ constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
4714
+ _define_property17(this, "_transportFactory", void 0);
4715
+ _define_property17(this, "_openTransports", void 0);
4716
+ this._transportFactory = _transportFactory;
4717
+ this._openTransports = new ComplexMap8(PublicKey11.hash);
4718
+ }
4407
4719
  };
4408
4720
  var createStateUpdater = (next) => {
4409
4721
  return (state, err) => {
@@ -4466,4 +4778,4 @@ export {
4466
4778
  RtcTransportService,
4467
4779
  createTeleportProtocolFactory
4468
4780
  };
4469
- //# sourceMappingURL=chunk-HQNQOWFA.mjs.map
4781
+ //# sourceMappingURL=chunk-NRRQ4H6U.mjs.map