@dxos/network-manager 0.1.57-main.6b5f268 → 0.1.57-main.b6e249b

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.
@@ -64,7 +64,7 @@ var ConnectionState;
64
64
  ] = "CLOSED";
65
65
  })(ConnectionState || (ConnectionState = {}));
66
66
  var Connection = class {
67
- constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory) {
67
+ constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
68
68
  this.topic = topic;
69
69
  this.ownId = ownId;
70
70
  this.remoteId = remoteId;
@@ -73,6 +73,7 @@ var Connection = class {
73
73
  this._signalMessaging = _signalMessaging;
74
74
  this._protocol = _protocol;
75
75
  this._transportFactory = _transportFactory;
76
+ this._callbacks = _callbacks;
76
77
  this._ctx = new Context();
77
78
  this._state = ConnectionState.INITIAL;
78
79
  this._incomingSignalBuffer = [];
@@ -92,7 +93,7 @@ var Connection = class {
92
93
  initiator: this.initiator
93
94
  }, {
94
95
  F: __dxlog_file,
95
- L: 96,
96
+ L: 109,
96
97
  S: this,
97
98
  C: (f, a) => f(...a)
98
99
  });
@@ -112,7 +113,7 @@ var Connection = class {
112
113
  async openConnection() {
113
114
  invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
114
115
  F: __dxlog_file,
115
- L: 121,
116
+ L: 134,
116
117
  S: this,
117
118
  A: [
118
119
  "this._state === ConnectionState.INITIAL",
@@ -123,7 +124,7 @@ var Connection = class {
123
124
  id: this._instanceId
124
125
  }), {
125
126
  F: __dxlog_file,
126
- L: 122,
127
+ L: 135,
127
128
  S: this,
128
129
  C: (f, a) => f(...a)
129
130
  });
@@ -135,7 +136,7 @@ var Connection = class {
135
136
  initiator: this.initiator
136
137
  }, {
137
138
  F: __dxlog_file,
138
- L: 123,
139
+ L: 136,
139
140
  S: this,
140
141
  C: (f, a) => f(...a)
141
142
  });
@@ -146,7 +147,7 @@ var Connection = class {
146
147
  this._protocol.stream.on("close", () => {
147
148
  log("protocol stream closed", void 0, {
148
149
  F: __dxlog_file,
149
- L: 140,
150
+ L: 153,
150
151
  S: this,
151
152
  C: (f, a) => f(...a)
152
153
  });
@@ -154,7 +155,7 @@ var Connection = class {
154
155
  });
155
156
  invariant(!this._transport, void 0, {
156
157
  F: __dxlog_file,
157
- L: 144,
158
+ L: 157,
158
159
  S: this,
159
160
  A: [
160
161
  "!this._transport",
@@ -168,6 +169,7 @@ var Connection = class {
168
169
  });
169
170
  this._transport.connected.once(() => {
170
171
  this._changeState(ConnectionState.CONNECTED);
172
+ this._callbacks?.onConnected?.();
171
173
  });
172
174
  this._transport.closed.once(() => {
173
175
  this._transport = void 0;
@@ -189,7 +191,7 @@ var Connection = class {
189
191
  id: this._instanceId
190
192
  }), {
191
193
  F: __dxlog_file,
192
- L: 176,
194
+ L: 190,
193
195
  S: this,
194
196
  C: (f, a) => f(...a)
195
197
  });
@@ -207,7 +209,7 @@ var Connection = class {
207
209
  peerId: this.ownId
208
210
  }, {
209
211
  F: __dxlog_file,
210
- L: 191,
212
+ L: 205,
211
213
  S: this,
212
214
  C: (f, a) => f(...a)
213
215
  });
@@ -216,7 +218,7 @@ var Connection = class {
216
218
  } catch (err2) {
217
219
  log.catch(err2, void 0, {
218
220
  F: __dxlog_file,
219
- L: 197,
221
+ L: 211,
220
222
  S: this,
221
223
  C: (f, a) => f(...a)
222
224
  });
@@ -226,7 +228,7 @@ var Connection = class {
226
228
  } catch (err2) {
227
229
  log.catch(err2, void 0, {
228
230
  F: __dxlog_file,
229
- L: 204,
231
+ L: 218,
230
232
  S: this,
231
233
  C: (f, a) => f(...a)
232
234
  });
@@ -235,11 +237,12 @@ var Connection = class {
235
237
  peerId: this.ownId
236
238
  }, {
237
239
  F: __dxlog_file,
238
- L: 207,
240
+ L: 221,
239
241
  S: this,
240
242
  C: (f, a) => f(...a)
241
243
  });
242
244
  this._changeState(ConnectionState.CLOSED);
245
+ this._callbacks?.onClosed?.(err);
243
246
  }
244
247
  _sendSignal(signal) {
245
248
  this._outgoingSignalBuffer.push(signal);
@@ -277,7 +280,7 @@ var Connection = class {
277
280
  err
278
281
  }, {
279
282
  F: __dxlog_file,
280
- L: 243,
283
+ L: 258,
281
284
  S: this,
282
285
  C: (f, a) => f(...a)
283
286
  });
@@ -290,7 +293,7 @@ var Connection = class {
290
293
  async signal(msg) {
291
294
  invariant(msg.sessionId, void 0, {
292
295
  F: __dxlog_file,
293
- L: 252,
296
+ L: 267,
294
297
  S: this,
295
298
  A: [
296
299
  "msg.sessionId",
@@ -300,7 +303,7 @@ var Connection = class {
300
303
  if (!msg.sessionId.equals(this.sessionId)) {
301
304
  log("dropping signal for incorrect session id", void 0, {
302
305
  F: __dxlog_file,
303
- L: 254,
306
+ L: 269,
304
307
  S: this,
305
308
  C: (f, a) => f(...a)
306
309
  });
@@ -308,7 +311,7 @@ var Connection = class {
308
311
  }
309
312
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
310
313
  F: __dxlog_file,
311
- L: 257,
314
+ L: 272,
312
315
  S: this,
313
316
  A: [
314
317
  "msg.data.signal || msg.data.signalBatch",
@@ -317,7 +320,7 @@ var Connection = class {
317
320
  });
318
321
  invariant(msg.author?.equals(this.remoteId), void 0, {
319
322
  F: __dxlog_file,
320
- L: 258,
323
+ L: 273,
321
324
  S: this,
322
325
  A: [
323
326
  "msg.author?.equals(this.remoteId)",
@@ -326,7 +329,7 @@ var Connection = class {
326
329
  });
327
330
  invariant(msg.recipient?.equals(this.ownId), void 0, {
328
331
  F: __dxlog_file,
329
- L: 259,
332
+ L: 274,
330
333
  S: this,
331
334
  A: [
332
335
  "msg.recipient?.equals(this.ownId)",
@@ -347,7 +350,7 @@ var Connection = class {
347
350
  msg: msg.data
348
351
  }, {
349
352
  F: __dxlog_file,
350
- L: 268,
353
+ L: 283,
351
354
  S: this,
352
355
  C: (f, a) => f(...a)
353
356
  });
@@ -355,7 +358,7 @@ var Connection = class {
355
358
  } else {
356
359
  invariant(this._transport, "Connection not ready to accept signals.", {
357
360
  F: __dxlog_file,
358
- L: 271,
361
+ L: 286,
359
362
  S: this,
360
363
  A: [
361
364
  "this._transport",
@@ -368,7 +371,7 @@ var Connection = class {
368
371
  msg: msg.data
369
372
  }, {
370
373
  F: __dxlog_file,
371
- L: 272,
374
+ L: 287,
372
375
  S: this,
373
376
  C: (f, a) => f(...a)
374
377
  });
@@ -383,13 +386,13 @@ var Connection = class {
383
386
  peerId: this.ownId
384
387
  }, {
385
388
  F: __dxlog_file,
386
- L: 279,
389
+ L: 294,
387
390
  S: this,
388
391
  C: (f, a) => f(...a)
389
392
  });
390
393
  invariant(state !== this._state, "Already in this state.", {
391
394
  F: __dxlog_file,
392
- L: 280,
395
+ L: 295,
393
396
  S: this,
394
397
  A: [
395
398
  "state !== this._state",
@@ -637,7 +640,7 @@ var SwarmMessenger = class {
637
640
  };
638
641
 
639
642
  // packages/core/mesh/network-manager/src/swarm/swarm.ts
640
- import { Event as Event2, scheduleTask as scheduleTask2, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
643
+ import { Event as Event3, scheduleTask as scheduleTask2, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
641
644
  import { Context as Context4 } from "@dxos/context";
642
645
  import { ErrorStream as ErrorStream2 } from "@dxos/debug";
643
646
  import { invariant as invariant4 } from "@dxos/invariant";
@@ -647,9 +650,9 @@ import { trace as trace2 } from "@dxos/protocols";
647
650
  import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
648
651
 
649
652
  // packages/core/mesh/network-manager/src/swarm/peer.ts
650
- import { scheduleTask, synchronized as synchronized2 } from "@dxos/async";
653
+ import { Event as Event2, scheduleTask, synchronized as synchronized2 } from "@dxos/async";
651
654
  import { Context as Context3 } from "@dxos/context";
652
- import { CancelledError as CancelledError2 } from "@dxos/errors";
655
+ import { CancelledError as CancelledError2, SystemError } from "@dxos/errors";
653
656
  import { invariant as invariant3 } from "@dxos/invariant";
654
657
  import { PublicKey as PublicKey3 } from "@dxos/keys";
655
658
  import { log as log3 } from "@dxos/log";
@@ -664,6 +667,11 @@ function _ts_decorate2(decorators, target, key, desc) {
664
667
  return c > 3 && r && Object.defineProperty(target, key, r), r;
665
668
  }
666
669
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
670
+ var ConnectionDisplacedError = class extends SystemError {
671
+ constructor() {
672
+ super("Connection displaced by remote initiator.");
673
+ }
674
+ };
667
675
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
668
676
  var Peer = class {
669
677
  // TODO(burdon): Convert to map?
@@ -681,6 +689,7 @@ var Peer = class {
681
689
  this._ctx = new Context3();
682
690
  this.advertizing = false;
683
691
  this.initiating = false;
692
+ this.connectionDisplaced = new Event2();
684
693
  }
685
694
  /**
686
695
  * Respond to remote offer.
@@ -696,12 +705,12 @@ var Peer = class {
696
705
  sessionId: this.connection?.sessionId
697
706
  }, {
698
707
  F: __dxlog_file3,
699
- L: 108,
708
+ L: 116,
700
709
  S: this,
701
710
  C: (f, a) => f(...a)
702
711
  });
703
712
  if (this.connection) {
704
- await this.closeConnection(new Error("Connection displaced by remote initiator."));
713
+ await this.closeConnection(new ConnectionDisplacedError());
705
714
  }
706
715
  } else {
707
716
  return {
@@ -713,7 +722,7 @@ var Peer = class {
713
722
  if (!this.connection) {
714
723
  invariant3(message.sessionId, void 0, {
715
724
  F: __dxlog_file3,
716
- L: 128,
725
+ L: 136,
717
726
  S: this,
718
727
  A: [
719
728
  "message.sessionId",
@@ -733,7 +742,7 @@ var Peer = class {
733
742
  err
734
743
  }, {
735
744
  F: __dxlog_file3,
736
- L: 136,
745
+ L: 144,
737
746
  S: this,
738
747
  C: (f, a) => f(...a)
739
748
  });
@@ -755,7 +764,7 @@ var Peer = class {
755
764
  async initiateConnection() {
756
765
  invariant3(!this.initiating, "Initiation in progress.", {
757
766
  F: __dxlog_file3,
758
- L: 153,
767
+ L: 161,
759
768
  S: this,
760
769
  A: [
761
770
  "!this.initiating",
@@ -764,7 +773,7 @@ var Peer = class {
764
773
  });
765
774
  invariant3(!this.connection, "Already connected.", {
766
775
  F: __dxlog_file3,
767
- L: 154,
776
+ L: 162,
768
777
  S: this,
769
778
  A: [
770
779
  "!this.connection",
@@ -779,7 +788,7 @@ var Peer = class {
779
788
  sessionId
780
789
  }, {
781
790
  F: __dxlog_file3,
782
- L: 156,
791
+ L: 164,
783
792
  S: this,
784
793
  C: (f, a) => f(...a)
785
794
  });
@@ -803,14 +812,14 @@ var Peer = class {
803
812
  remoteId: this.id
804
813
  }, {
805
814
  F: __dxlog_file3,
806
- L: 171,
815
+ L: 179,
807
816
  S: this,
808
817
  C: (f, a) => f(...a)
809
818
  });
810
819
  if (connection.state !== ConnectionState.INITIAL) {
811
820
  log3("ignoring response", void 0, {
812
821
  F: __dxlog_file3,
813
- L: 173,
822
+ L: 181,
814
823
  S: this,
815
824
  C: (f, a) => f(...a)
816
825
  });
@@ -830,7 +839,7 @@ var Peer = class {
830
839
  remoteId: this.id
831
840
  }, {
832
841
  F: __dxlog_file3,
833
- L: 184,
842
+ L: 192,
834
843
  S: this,
835
844
  C: (f, a) => f(...a)
836
845
  });
@@ -853,13 +862,13 @@ var Peer = class {
853
862
  sessionId
854
863
  }, {
855
864
  F: __dxlog_file3,
856
- L: 198,
865
+ L: 206,
857
866
  S: this,
858
867
  C: (f, a) => f(...a)
859
868
  });
860
869
  invariant3(!this.connection, "Already connected.", {
861
870
  F: __dxlog_file3,
862
- L: 205,
871
+ L: 213,
863
872
  S: this,
864
873
  A: [
865
874
  "!this.connection",
@@ -880,14 +889,9 @@ var Peer = class {
880
889
  remotePeerId: this.id,
881
890
  topic: this.topic
882
891
  }),
883
- this._transportFactory
884
- );
885
- this._callbacks.onInitiated(connection);
886
- void this._connectionCtx?.dispose();
887
- this._connectionCtx = this._ctx.derive();
888
- connection.stateChanged.on((state) => {
889
- switch (state) {
890
- case ConnectionState.CONNECTED: {
892
+ this._transportFactory,
893
+ {
894
+ onConnected: () => {
891
895
  this.availableToConnect = true;
892
896
  this._lastConnectionTime = Date.now();
893
897
  this._callbacks.onConnected();
@@ -900,13 +904,12 @@ var Peer = class {
900
904
  initiator
901
905
  }, {
902
906
  F: __dxlog_file3,
903
- L: 231,
907
+ L: 232,
904
908
  S: this,
905
909
  C: (f, a) => f(...a)
906
910
  });
907
- break;
908
- }
909
- case ConnectionState.CLOSED: {
911
+ },
912
+ onClosed: (err) => {
910
913
  log3("connection closed", {
911
914
  topic: this.topic,
912
915
  peerId: this.localPeerId,
@@ -914,13 +917,14 @@ var Peer = class {
914
917
  initiator
915
918
  }, {
916
919
  F: __dxlog_file3,
917
- L: 242,
920
+ L: 241,
918
921
  S: this,
919
922
  C: (f, a) => f(...a)
920
923
  });
924
+ this._connectionLimiter.doneConnecting(sessionId);
921
925
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
922
926
  F: __dxlog_file3,
923
- L: 243,
927
+ L: 246,
924
928
  S: this,
925
929
  A: [
926
930
  "this.connection === connection",
@@ -935,27 +939,32 @@ var Peer = class {
935
939
  initiator
936
940
  }, {
937
941
  F: __dxlog_file3,
938
- L: 245,
942
+ L: 248,
939
943
  S: this,
940
944
  C: (f, a) => f(...a)
941
945
  });
942
- if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
943
- this._availableAfter = 0;
946
+ if (err instanceof ConnectionDisplacedError) {
947
+ this.connectionDisplaced.emit(this.connection);
944
948
  } else {
945
- this.availableToConnect = false;
946
- this._availableAfter = increaseInterval(this._availableAfter);
949
+ if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
950
+ this._availableAfter = 0;
951
+ } else {
952
+ this.availableToConnect = false;
953
+ this._availableAfter = increaseInterval(this._availableAfter);
954
+ }
955
+ this._callbacks.onDisconnected();
956
+ scheduleTask(this._connectionCtx, () => {
957
+ this.availableToConnect = true;
958
+ this._callbacks.onPeerAvailable();
959
+ }, this._availableAfter);
947
960
  }
948
961
  this.connection = void 0;
949
- this._callbacks.onDisconnected();
950
- this._connectionLimiter.doneConnecting(sessionId);
951
- scheduleTask(this._connectionCtx, () => {
952
- this.availableToConnect = true;
953
- this._callbacks.onPeerAvailable();
954
- }, this._availableAfter);
955
- break;
956
962
  }
957
963
  }
958
- });
964
+ );
965
+ this._callbacks.onInitiated(connection);
966
+ void this._connectionCtx?.dispose();
967
+ this._connectionCtx = this._ctx.derive();
959
968
  connection.errors.handle((err) => {
960
969
  log3.warn("connection error", {
961
970
  topic: this.topic,
@@ -965,7 +974,7 @@ var Peer = class {
965
974
  err
966
975
  }, {
967
976
  F: __dxlog_file3,
968
- L: 279,
977
+ L: 288,
969
978
  S: this,
970
979
  C: (f, a) => f(...a)
971
980
  });
@@ -978,7 +987,7 @@ var Peer = class {
978
987
  err
979
988
  }, {
980
989
  F: __dxlog_file3,
981
- L: 280,
990
+ L: 289,
982
991
  S: this,
983
992
  C: (f, a) => f(...a)
984
993
  });
@@ -997,7 +1006,7 @@ var Peer = class {
997
1006
  sessionId: connection.sessionId
998
1007
  }, {
999
1008
  F: __dxlog_file3,
1000
- L: 303,
1009
+ L: 314,
1001
1010
  S: this,
1002
1011
  C: (f, a) => f(...a)
1003
1012
  });
@@ -1007,7 +1016,7 @@ var Peer = class {
1007
1016
  sessionId: connection.sessionId
1008
1017
  }, {
1009
1018
  F: __dxlog_file3,
1010
- L: 309,
1019
+ L: 320,
1011
1020
  S: this,
1012
1021
  C: (f, a) => f(...a)
1013
1022
  });
@@ -1018,7 +1027,7 @@ var Peer = class {
1018
1027
  message
1019
1028
  }, {
1020
1029
  F: __dxlog_file3,
1021
- L: 314,
1030
+ L: 325,
1022
1031
  S: this,
1023
1032
  C: (f, a) => f(...a)
1024
1033
  });
@@ -1033,7 +1042,7 @@ var Peer = class {
1033
1042
  topic: this.topic
1034
1043
  }, {
1035
1044
  F: __dxlog_file3,
1036
- L: 324,
1045
+ L: 335,
1037
1046
  S: this,
1038
1047
  C: (f, a) => f(...a)
1039
1048
  });
@@ -1073,7 +1082,7 @@ var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1073
1082
  var Swarm = class {
1074
1083
  // TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
1075
1084
  // TODO(burdon): Split up properties.
1076
- constructor(_topic, _ownPeerId, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter) {
1085
+ constructor(_topic, _ownPeerId, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
1077
1086
  this._topic = _topic;
1078
1087
  this._ownPeerId = _ownPeerId;
1079
1088
  this._topology = _topology;
@@ -1082,13 +1091,14 @@ var Swarm = class {
1082
1091
  this._transportFactory = _transportFactory;
1083
1092
  this._label = _label;
1084
1093
  this._connectionLimiter = _connectionLimiter;
1094
+ this._initiationDelay = _initiationDelay;
1085
1095
  this._ctx = new Context4();
1086
1096
  this._listeningHandle = void 0;
1087
1097
  this._peers = new ComplexMap2(PublicKey4.hash);
1088
1098
  this._instanceId = PublicKey4.random().toHex();
1089
- this.connectionAdded = new Event2();
1090
- this.disconnected = new Event2();
1091
- this.connected = new Event2();
1099
+ this.connectionAdded = new Event3();
1100
+ this.disconnected = new Event3();
1101
+ this.connected = new Event3();
1092
1102
  this.errors = new ErrorStream2();
1093
1103
  log4.trace("dxos.mesh.swarm.constructor", trace2.begin({
1094
1104
  id: this._instanceId,
@@ -1098,7 +1108,7 @@ var Swarm = class {
1098
1108
  }
1099
1109
  }), {
1100
1110
  F: __dxlog_file4,
1101
- L: 87,
1111
+ L: 88,
1102
1112
  S: this,
1103
1113
  C: (f, a) => f(...a)
1104
1114
  });
@@ -1106,7 +1116,7 @@ var Swarm = class {
1106
1116
  peerId: _ownPeerId
1107
1117
  }, {
1108
1118
  F: __dxlog_file4,
1109
- L: 91,
1119
+ L: 92,
1110
1120
  S: this,
1111
1121
  C: (f, a) => f(...a)
1112
1122
  });
@@ -1121,7 +1131,7 @@ var Swarm = class {
1121
1131
  id: this._instanceId
1122
1132
  }), {
1123
1133
  F: __dxlog_file4,
1124
- L: 100,
1134
+ L: 101,
1125
1135
  S: this,
1126
1136
  C: (f, a) => f(...a)
1127
1137
  });
@@ -1144,7 +1154,7 @@ var Swarm = class {
1144
1154
  async open() {
1145
1155
  invariant4(!this._listeningHandle, void 0, {
1146
1156
  F: __dxlog_file4,
1147
- L: 127,
1157
+ L: 128,
1148
1158
  S: this,
1149
1159
  A: [
1150
1160
  "!this._listeningHandle",
@@ -1159,7 +1169,7 @@ var Swarm = class {
1159
1169
  err
1160
1170
  }, {
1161
1171
  F: __dxlog_file4,
1162
- L: 134,
1172
+ L: 135,
1163
1173
  S: this,
1164
1174
  C: (f, a) => f(...a)
1165
1175
  }));
@@ -1169,7 +1179,7 @@ var Swarm = class {
1169
1179
  async destroy() {
1170
1180
  log4("destroying...", void 0, {
1171
1181
  F: __dxlog_file4,
1172
- L: 140,
1182
+ L: 141,
1173
1183
  S: this,
1174
1184
  C: (f, a) => f(...a)
1175
1185
  });
@@ -1180,7 +1190,7 @@ var Swarm = class {
1180
1190
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
1181
1191
  log4("destroyed", void 0, {
1182
1192
  F: __dxlog_file4,
1183
- L: 147,
1193
+ L: 148,
1184
1194
  S: this,
1185
1195
  C: (f, a) => f(...a)
1186
1196
  });
@@ -1188,7 +1198,7 @@ var Swarm = class {
1188
1198
  async setTopology(topology) {
1189
1199
  invariant4(!this._ctx.disposed, "Swarm is offline", {
1190
1200
  F: __dxlog_file4,
1191
- L: 151,
1201
+ L: 152,
1192
1202
  S: this,
1193
1203
  A: [
1194
1204
  "!this._ctx.disposed",
@@ -1203,7 +1213,7 @@ var Swarm = class {
1203
1213
  topology: getClassName(topology)
1204
1214
  }, {
1205
1215
  F: __dxlog_file4,
1206
- L: 155,
1216
+ L: 156,
1207
1217
  S: this,
1208
1218
  C: (f, a) => f(...a)
1209
1219
  });
@@ -1217,14 +1227,14 @@ var Swarm = class {
1217
1227
  swarmEvent
1218
1228
  }, {
1219
1229
  F: __dxlog_file4,
1220
- L: 168,
1230
+ L: 169,
1221
1231
  S: this,
1222
1232
  C: (f, a) => f(...a)
1223
1233
  });
1224
1234
  if (this._ctx.disposed) {
1225
1235
  log4("swarm event ignored for disposed swarm", void 0, {
1226
1236
  F: __dxlog_file4,
1227
- L: 171,
1237
+ L: 172,
1228
1238
  S: this,
1229
1239
  C: (f, a) => f(...a)
1230
1240
  });
@@ -1236,7 +1246,7 @@ var Swarm = class {
1236
1246
  peerId
1237
1247
  }, {
1238
1248
  F: __dxlog_file4,
1239
- L: 177,
1249
+ L: 178,
1240
1250
  S: this,
1241
1251
  C: (f, a) => f(...a)
1242
1252
  });
@@ -1251,7 +1261,7 @@ var Swarm = class {
1251
1261
  if (peer.connection?.state !== ConnectionState.CONNECTED) {
1252
1262
  void this._destroyPeer(peer.id).catch((err) => log4.catch(err, void 0, {
1253
1263
  F: __dxlog_file4,
1254
- L: 188,
1264
+ L: 189,
1255
1265
  S: this,
1256
1266
  C: (f, a) => f(...a)
1257
1267
  }));
@@ -1265,14 +1275,14 @@ var Swarm = class {
1265
1275
  message
1266
1276
  }, {
1267
1277
  F: __dxlog_file4,
1268
- L: 198,
1278
+ L: 199,
1269
1279
  S: this,
1270
1280
  C: (f, a) => f(...a)
1271
1281
  });
1272
1282
  if (this._ctx.disposed) {
1273
1283
  log4("ignored for disposed swarm", void 0, {
1274
1284
  F: __dxlog_file4,
1275
- L: 200,
1285
+ L: 201,
1276
1286
  S: this,
1277
1287
  C: (f, a) => f(...a)
1278
1288
  });
@@ -1282,7 +1292,7 @@ var Swarm = class {
1282
1292
  }
1283
1293
  invariant4(message.author, void 0, {
1284
1294
  F: __dxlog_file4,
1285
- L: 205,
1295
+ L: 206,
1286
1296
  S: this,
1287
1297
  A: [
1288
1298
  "message.author",
@@ -1294,7 +1304,7 @@ var Swarm = class {
1294
1304
  message
1295
1305
  }, {
1296
1306
  F: __dxlog_file4,
1297
- L: 207,
1307
+ L: 208,
1298
1308
  S: this,
1299
1309
  C: (f, a) => f(...a)
1300
1310
  });
@@ -1307,7 +1317,7 @@ var Swarm = class {
1307
1317
  message
1308
1318
  }, {
1309
1319
  F: __dxlog_file4,
1310
- L: 211,
1320
+ L: 212,
1311
1321
  S: this,
1312
1322
  C: (f, a) => f(...a)
1313
1323
  });
@@ -1325,14 +1335,14 @@ var Swarm = class {
1325
1335
  message
1326
1336
  }, {
1327
1337
  F: __dxlog_file4,
1328
- L: 222,
1338
+ L: 223,
1329
1339
  S: this,
1330
1340
  C: (f, a) => f(...a)
1331
1341
  });
1332
1342
  if (this._ctx.disposed) {
1333
1343
  log4.info("ignored for offline swarm", void 0, {
1334
1344
  F: __dxlog_file4,
1335
- L: 224,
1345
+ L: 225,
1336
1346
  S: this,
1337
1347
  C: (f, a) => f(...a)
1338
1348
  });
@@ -1340,7 +1350,7 @@ var Swarm = class {
1340
1350
  }
1341
1351
  invariant4(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1342
1352
  F: __dxlog_file4,
1343
- L: 227,
1353
+ L: 228,
1344
1354
  S: this,
1345
1355
  A: [
1346
1356
  "message.recipient?.equals(this._ownPeerId)",
@@ -1349,7 +1359,7 @@ var Swarm = class {
1349
1359
  });
1350
1360
  invariant4(message.topic?.equals(this._topic), void 0, {
1351
1361
  F: __dxlog_file4,
1352
- L: 231,
1362
+ L: 232,
1353
1363
  S: this,
1354
1364
  A: [
1355
1365
  "message.topic?.equals(this._topic)",
@@ -1358,7 +1368,7 @@ var Swarm = class {
1358
1368
  });
1359
1369
  invariant4(message.author, void 0, {
1360
1370
  F: __dxlog_file4,
1361
- L: 232,
1371
+ L: 233,
1362
1372
  S: this,
1363
1373
  A: [
1364
1374
  "message.author",
@@ -1418,7 +1428,7 @@ var Swarm = class {
1418
1428
  async _destroyPeer(peerId) {
1419
1429
  invariant4(this._peers.has(peerId), void 0, {
1420
1430
  F: __dxlog_file4,
1421
- L: 302,
1431
+ L: 303,
1422
1432
  S: this,
1423
1433
  A: [
1424
1434
  "this._peers.has(peerId)",
@@ -1445,7 +1455,7 @@ var Swarm = class {
1445
1455
  } catch (err) {
1446
1456
  log4("initiation error", err, {
1447
1457
  F: __dxlog_file4,
1448
- L: 328,
1458
+ L: 329,
1449
1459
  S: this,
1450
1460
  C: (f, a) => f(...a)
1451
1461
  });
@@ -1473,11 +1483,11 @@ var Swarm = class {
1473
1483
  remoteId
1474
1484
  }, {
1475
1485
  F: __dxlog_file4,
1476
- L: 355,
1486
+ L: 356,
1477
1487
  S: this,
1478
1488
  C: (f, a) => f(...a)
1479
1489
  });
1480
- await sleep2(INITIATION_DELAY);
1490
+ await sleep2(this._initiationDelay);
1481
1491
  }
1482
1492
  if (ctx.disposed) {
1483
1493
  return;
@@ -1490,7 +1500,7 @@ var Swarm = class {
1490
1500
  remoteId
1491
1501
  }, {
1492
1502
  F: __dxlog_file4,
1493
- L: 369,
1503
+ L: 370,
1494
1504
  S: this,
1495
1505
  C: (f, a) => f(...a)
1496
1506
  });
@@ -1500,7 +1510,7 @@ var Swarm = class {
1500
1510
  remoteId
1501
1511
  }, {
1502
1512
  F: __dxlog_file4,
1503
- L: 372,
1513
+ L: 373,
1504
1514
  S: this,
1505
1515
  C: (f, a) => f(...a)
1506
1516
  });
@@ -1536,7 +1546,7 @@ _ts_decorate3([
1536
1546
  ], Swarm.prototype, "goOnline", null);
1537
1547
 
1538
1548
  // packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts
1539
- import { Event as Event3, EventSubscriptions } from "@dxos/async";
1549
+ import { Event as Event4, EventSubscriptions } from "@dxos/async";
1540
1550
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1541
1551
  import { log as log5 } from "@dxos/log";
1542
1552
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
@@ -1551,7 +1561,7 @@ var SwarmMapper = class {
1551
1561
  this._subscriptions = new EventSubscriptions();
1552
1562
  this._connectionSubscriptions = new ComplexMap3(PublicKey5.hash);
1553
1563
  this._peers = new ComplexMap3(PublicKey5.hash);
1554
- this.mapUpdated = new Event3();
1564
+ this.mapUpdated = new Event4();
1555
1565
  this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
1556
1566
  this._update();
1557
1567
  this._connectionSubscriptions.set(connection.remoteId, connection.stateChanged.on(() => {
@@ -1688,7 +1698,7 @@ var ConnectionLimiter = class {
1688
1698
  };
1689
1699
 
1690
1700
  // packages/core/mesh/network-manager/src/connection-log.ts
1691
- import { Event as Event4 } from "@dxos/async";
1701
+ import { Event as Event5 } from "@dxos/async";
1692
1702
  import { raise } from "@dxos/debug";
1693
1703
  import { PublicKey as PublicKey7 } from "@dxos/keys";
1694
1704
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
@@ -1706,7 +1716,7 @@ var ConnectionLog = class {
1706
1716
  * SwarmId => info
1707
1717
  */
1708
1718
  this._swarms = new ComplexMap5(PublicKey7.hash);
1709
- this.update = new Event4();
1719
+ this.update = new Event5();
1710
1720
  }
1711
1721
  getSwarmInfo(swarmId) {
1712
1722
  return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
@@ -1758,7 +1768,7 @@ var ConnectionLog = class {
1758
1768
  };
1759
1769
 
1760
1770
  // packages/core/mesh/network-manager/src/network-manager.ts
1761
- import { Event as Event5 } from "@dxos/async";
1771
+ import { Event as Event6 } from "@dxos/async";
1762
1772
  import { invariant as invariant6 } from "@dxos/invariant";
1763
1773
  import { PublicKey as PublicKey8 } from "@dxos/keys";
1764
1774
  import { log as log7 } from "@dxos/log";
@@ -1775,8 +1785,8 @@ var NetworkManager = class {
1775
1785
  this._swarms = new ComplexMap6(PublicKey8.hash);
1776
1786
  this._mappers = new ComplexMap6(PublicKey8.hash);
1777
1787
  this._connectionState = ConnectionState2.ONLINE;
1778
- this.connectionStateChanged = new Event5();
1779
- this.topicsUpdated = new Event5();
1788
+ this.connectionStateChanged = new Event6();
1789
+ this.topicsUpdated = new Event6();
1780
1790
  this._instanceId = PublicKey8.random().toHex();
1781
1791
  this._transportFactory = transportFactory;
1782
1792
  this._signalManager = signalManager;
@@ -2250,7 +2260,7 @@ var StarTopology = class {
2250
2260
 
2251
2261
  // packages/core/mesh/network-manager/src/transport/memory-transport.ts
2252
2262
  import { Transform } from "@dxos/node-std/stream";
2253
- import { Event as Event6, Trigger } from "@dxos/async";
2263
+ import { Event as Event7, Trigger } from "@dxos/async";
2254
2264
  import { ErrorStream as ErrorStream3 } from "@dxos/debug";
2255
2265
  import { invariant as invariant10 } from "@dxos/invariant";
2256
2266
  import { PublicKey as PublicKey9 } from "@dxos/keys";
@@ -2286,8 +2296,8 @@ var MemoryTransport = class _MemoryTransport {
2286
2296
  }
2287
2297
  constructor(options) {
2288
2298
  this.options = options;
2289
- this.closed = new Event6();
2290
- this.connected = new Event6();
2299
+ this.closed = new Event7();
2300
+ this.connected = new Event7();
2291
2301
  this.errors = new ErrorStream3();
2292
2302
  this._instanceId = PublicKey9.random();
2293
2303
  this._remote = new Trigger();
@@ -2436,7 +2446,7 @@ _ts_decorate4([
2436
2446
 
2437
2447
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
2438
2448
  import SimplePeerConstructor from "simple-peer";
2439
- import { Event as Event7 } from "@dxos/async";
2449
+ import { Event as Event8 } from "@dxos/async";
2440
2450
  import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
2441
2451
  import { invariant as invariant11 } from "@dxos/invariant";
2442
2452
  import { PublicKey as PublicKey10 } from "@dxos/keys";
@@ -2457,8 +2467,8 @@ var WebRTCTransport = class {
2457
2467
  this.params = params;
2458
2468
  this._instanceId = PublicKey10.random().toHex();
2459
2469
  this._closed = false;
2460
- this.closed = new Event7();
2461
- this.connected = new Event7();
2470
+ this.closed = new Event8();
2471
+ this.connected = new Event8();
2462
2472
  this.errors = new ErrorStream4();
2463
2473
  log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.begin({
2464
2474
  id: this._instanceId
@@ -2722,7 +2732,7 @@ var WebRTCTransportService = class {
2722
2732
 
2723
2733
  // packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
2724
2734
  import { Writable } from "@dxos/node-std/stream";
2725
- import { Event as Event8 } from "@dxos/async";
2735
+ import { Event as Event9 } from "@dxos/async";
2726
2736
  import { Context as Context6 } from "@dxos/context";
2727
2737
  import { ErrorStream as ErrorStream5 } from "@dxos/debug";
2728
2738
  import { invariant as invariant13 } from "@dxos/invariant";
@@ -2737,8 +2747,8 @@ var WebRTCTransportProxy = class {
2737
2747
  this._params = _params;
2738
2748
  this._proxyId = PublicKey12.random();
2739
2749
  this._ctx = new Context6();
2740
- this.closed = new Event8();
2741
- this.connected = new Event8();
2750
+ this.closed = new Event9();
2751
+ this.connected = new Event9();
2742
2752
  this.errors = new ErrorStream5();
2743
2753
  this._closed = false;
2744
2754
  this._serviceStream = this._params.bridgeService.open({
@@ -2918,4 +2928,4 @@ export {
2918
2928
  WebRTCTransportProxyFactory,
2919
2929
  createTeleportProtocolFactory
2920
2930
  };
2921
- //# sourceMappingURL=chunk-WQ3YXGWP.mjs.map
2931
+ //# sourceMappingURL=chunk-UAB4ONRL.mjs.map