@dxos/network-manager 0.1.56-main.83e9b8a → 0.1.56-main.a25bb93

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 (37) hide show
  1. package/dist/lib/browser/{chunk-5R7TDXUU.mjs → chunk-FC6CWDES.mjs} +622 -187
  2. package/dist/lib/browser/chunk-FC6CWDES.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +1 -1
  6. package/dist/lib/node/index.cjs +621 -186
  7. package/dist/lib/node/index.cjs.map +3 -3
  8. package/dist/lib/node/meta.json +1 -1
  9. package/dist/lib/node/testing/index.cjs +547 -168
  10. package/dist/lib/node/testing/index.cjs.map +3 -3
  11. package/dist/types/src/network-manager.d.ts.map +1 -1
  12. package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
  13. package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
  14. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  15. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  16. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  17. package/dist/types/src/topology/fully-connected-topology.d.ts.map +1 -1
  18. package/dist/types/src/topology/star-topology.d.ts.map +1 -1
  19. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  20. package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
  21. package/dist/types/src/transport/webrtc-transport-service.d.ts.map +1 -1
  22. package/dist/types/src/transport/webrtc-transport.d.ts.map +1 -1
  23. package/package.json +18 -18
  24. package/src/network-manager.ts +1 -2
  25. package/src/signal/swarm-messenger.ts +1 -2
  26. package/src/swarm/connection-limiter.ts +2 -1
  27. package/src/swarm/connection.ts +17 -3
  28. package/src/swarm/peer.ts +24 -2
  29. package/src/swarm/swarm.ts +1 -2
  30. package/src/topology/fully-connected-topology.ts +1 -2
  31. package/src/topology/mmst-topology.ts +1 -1
  32. package/src/topology/star-topology.ts +1 -2
  33. package/src/transport/memory-transport.ts +1 -1
  34. package/src/transport/webrtc-transport-proxy.ts +14 -12
  35. package/src/transport/webrtc-transport-service.ts +31 -8
  36. package/src/transport/webrtc-transport.ts +1 -1
  37. package/dist/lib/browser/chunk-5R7TDXUU.mjs.map +0 -7
@@ -61,11 +61,11 @@ var import_keys7 = require("@dxos/keys");
61
61
  var import_util5 = require("@dxos/util");
62
62
 
63
63
  // packages/core/mesh/network-manager/src/swarm/connection.ts
64
- var import_tiny_invariant = __toESM(require("tiny-invariant"));
65
64
  var import_async = require("@dxos/async");
66
65
  var import_context = require("@dxos/context");
67
66
  var import_debug = require("@dxos/debug");
68
67
  var import_errors = require("@dxos/errors");
68
+ var import_invariant = require("@dxos/invariant");
69
69
  var import_keys = require("@dxos/keys");
70
70
  var import_log = require("@dxos/log");
71
71
  var import_protocols = require("@dxos/protocols");
@@ -137,6 +137,18 @@ var Connection = class {
137
137
  await this._flushSignalBuffer();
138
138
  });
139
139
  this._signallingDelay = STARTING_SIGNALLING_DELAY;
140
+ import_log.log.trace("dxos.mesh.connection.construct", {
141
+ sessionId: this.sessionId,
142
+ topic: this.topic,
143
+ localPeerId: this.ownId,
144
+ remotePeerId: this.remoteId,
145
+ initiator: this.initiator
146
+ }, {
147
+ F: __dxlog_file,
148
+ L: 95,
149
+ S: this,
150
+ C: (f, a) => f(...a)
151
+ });
140
152
  }
141
153
  get state() {
142
154
  return this._state;
@@ -151,12 +163,32 @@ var Connection = class {
151
163
  * Create an underlying transport and prepares it for the connection.
152
164
  */
153
165
  async openConnection() {
154
- (0, import_tiny_invariant.default)(this._state === ConnectionState.INITIAL, "Invalid state.");
166
+ (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
167
+ F: __dxlog_file,
168
+ L: 120,
169
+ S: this,
170
+ A: [
171
+ "this._state === ConnectionState.INITIAL",
172
+ "'Invalid state.'"
173
+ ]
174
+ });
155
175
  import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
156
176
  id: this._instanceId
157
177
  }), {
158
178
  F: __dxlog_file,
159
- L: 114,
179
+ L: 121,
180
+ S: this,
181
+ C: (f, a) => f(...a)
182
+ });
183
+ import_log.log.trace("dxos.mesh.connection.open", {
184
+ sessionId: this.sessionId,
185
+ topic: this.topic,
186
+ localPeerId: this.ownId,
187
+ remotePeerId: this.remoteId,
188
+ initiator: this.initiator
189
+ }, {
190
+ F: __dxlog_file,
191
+ L: 122,
160
192
  S: this,
161
193
  C: (f, a) => f(...a)
162
194
  });
@@ -167,13 +199,21 @@ var Connection = class {
167
199
  this._protocol.stream.on("close", () => {
168
200
  (0, import_log.log)("protocol stream closed", void 0, {
169
201
  F: __dxlog_file,
170
- L: 125,
202
+ L: 139,
171
203
  S: this,
172
204
  C: (f, a) => f(...a)
173
205
  });
174
206
  this.close().catch((err) => this.errors.raise(err));
175
207
  });
176
- (0, import_tiny_invariant.default)(!this._transport);
208
+ (0, import_invariant.invariant)(!this._transport, void 0, {
209
+ F: __dxlog_file,
210
+ L: 143,
211
+ S: this,
212
+ A: [
213
+ "!this._transport",
214
+ ""
215
+ ]
216
+ });
177
217
  this._transport = this._transportFactory.createTransport({
178
218
  initiator: this.initiator,
179
219
  stream: this._protocol.stream,
@@ -199,7 +239,7 @@ var Connection = class {
199
239
  id: this._instanceId
200
240
  }), {
201
241
  F: __dxlog_file,
202
- L: 158,
242
+ L: 172,
203
243
  S: this,
204
244
  C: (f, a) => f(...a)
205
245
  });
@@ -215,7 +255,7 @@ var Connection = class {
215
255
  peerId: this.ownId
216
256
  }, {
217
257
  F: __dxlog_file,
218
- L: 170,
258
+ L: 184,
219
259
  S: this,
220
260
  C: (f, a) => f(...a)
221
261
  });
@@ -224,7 +264,7 @@ var Connection = class {
224
264
  } catch (err) {
225
265
  import_log.log.catch(err, void 0, {
226
266
  F: __dxlog_file,
227
- L: 176,
267
+ L: 190,
228
268
  S: this,
229
269
  C: (f, a) => f(...a)
230
270
  });
@@ -234,7 +274,7 @@ var Connection = class {
234
274
  } catch (err) {
235
275
  import_log.log.catch(err, void 0, {
236
276
  F: __dxlog_file,
237
- L: 183,
277
+ L: 197,
238
278
  S: this,
239
279
  C: (f, a) => f(...a)
240
280
  });
@@ -243,7 +283,7 @@ var Connection = class {
243
283
  peerId: this.ownId
244
284
  }, {
245
285
  F: __dxlog_file,
246
- L: 186,
286
+ L: 200,
247
287
  S: this,
248
288
  C: (f, a) => f(...a)
249
289
  });
@@ -283,7 +323,7 @@ var Connection = class {
283
323
  err
284
324
  }, {
285
325
  F: __dxlog_file,
286
- L: 220,
326
+ L: 234,
287
327
  S: this,
288
328
  C: (f, a) => f(...a)
289
329
  });
@@ -295,19 +335,51 @@ var Connection = class {
295
335
  */
296
336
  async signal(msg) {
297
337
  var _a, _b, _c;
298
- (0, import_tiny_invariant.default)(msg.sessionId);
338
+ (0, import_invariant.invariant)(msg.sessionId, void 0, {
339
+ F: __dxlog_file,
340
+ L: 243,
341
+ S: this,
342
+ A: [
343
+ "msg.sessionId",
344
+ ""
345
+ ]
346
+ });
299
347
  if (!msg.sessionId.equals(this.sessionId)) {
300
348
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
301
349
  F: __dxlog_file,
302
- L: 231,
350
+ L: 245,
303
351
  S: this,
304
352
  C: (f, a) => f(...a)
305
353
  });
306
354
  return;
307
355
  }
308
- (0, import_tiny_invariant.default)(msg.data.signal || msg.data.signalBatch);
309
- (0, import_tiny_invariant.default)((_a = msg.author) == null ? void 0 : _a.equals(this.remoteId));
310
- (0, import_tiny_invariant.default)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId));
356
+ (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
357
+ F: __dxlog_file,
358
+ L: 248,
359
+ S: this,
360
+ A: [
361
+ "msg.data.signal || msg.data.signalBatch",
362
+ ""
363
+ ]
364
+ });
365
+ (0, import_invariant.invariant)((_a = msg.author) == null ? void 0 : _a.equals(this.remoteId), void 0, {
366
+ F: __dxlog_file,
367
+ L: 249,
368
+ S: this,
369
+ A: [
370
+ "msg.author?.equals(this.remoteId)",
371
+ ""
372
+ ]
373
+ });
374
+ (0, import_invariant.invariant)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId), void 0, {
375
+ F: __dxlog_file,
376
+ L: 250,
377
+ S: this,
378
+ A: [
379
+ "msg.recipient?.equals(this.ownId)",
380
+ ""
381
+ ]
382
+ });
311
383
  const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
312
384
  msg.data.signal
313
385
  ];
@@ -322,20 +394,28 @@ var Connection = class {
322
394
  msg: msg.data
323
395
  }, {
324
396
  F: __dxlog_file,
325
- L: 245,
397
+ L: 259,
326
398
  S: this,
327
399
  C: (f, a) => f(...a)
328
400
  });
329
401
  this._incomingSignalBuffer.push(signal);
330
402
  } else {
331
- (0, import_tiny_invariant.default)(this._transport, "Connection not ready to accept signals.");
403
+ (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
404
+ F: __dxlog_file,
405
+ L: 262,
406
+ S: this,
407
+ A: [
408
+ "this._transport",
409
+ "'Connection not ready to accept signals.'"
410
+ ]
411
+ });
332
412
  (0, import_log.log)("received signal", {
333
413
  peerId: this.ownId,
334
414
  remoteId: this.remoteId,
335
415
  msg: msg.data
336
416
  }, {
337
417
  F: __dxlog_file,
338
- L: 249,
418
+ L: 263,
339
419
  S: this,
340
420
  C: (f, a) => f(...a)
341
421
  });
@@ -350,11 +430,19 @@ var Connection = class {
350
430
  peerId: this.ownId
351
431
  }, {
352
432
  F: __dxlog_file,
353
- L: 256,
433
+ L: 270,
354
434
  S: this,
355
435
  C: (f, a) => f(...a)
356
436
  });
357
- (0, import_tiny_invariant.default)(state !== this._state, "Already in this state.");
437
+ (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
438
+ F: __dxlog_file,
439
+ L: 271,
440
+ S: this,
441
+ A: [
442
+ "state !== this._state",
443
+ "'Already in this state.'"
444
+ ]
445
+ });
358
446
  this._state = state;
359
447
  this.stateChanged.emit(state);
360
448
  }
@@ -364,18 +452,18 @@ _ts_decorate([
364
452
  ], Connection.prototype, "close", null);
365
453
 
366
454
  // packages/core/mesh/network-manager/src/swarm/swarm.ts
367
- var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
368
455
  var import_async3 = require("@dxos/async");
369
456
  var import_context4 = require("@dxos/context");
370
457
  var import_debug2 = require("@dxos/debug");
458
+ var import_invariant4 = require("@dxos/invariant");
371
459
  var import_keys4 = require("@dxos/keys");
372
460
  var import_log4 = require("@dxos/log");
373
461
  var import_protocols3 = require("@dxos/protocols");
374
462
  var import_util2 = require("@dxos/util");
375
463
 
376
464
  // packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
377
- var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
378
465
  var import_context2 = require("@dxos/context");
466
+ var import_invariant2 = require("@dxos/invariant");
379
467
  var import_keys2 = require("@dxos/keys");
380
468
  var import_log2 = require("@dxos/log");
381
469
  var import_protocols2 = require("@dxos/protocols");
@@ -406,7 +494,7 @@ var SwarmMessenger = class {
406
494
  msg: message
407
495
  }, {
408
496
  F: __dxlog_file2,
409
- L: 70,
497
+ L: 69,
410
498
  S: this,
411
499
  C: (f, a) => f(...a)
412
500
  });
@@ -435,7 +523,7 @@ var SwarmMessenger = class {
435
523
  message
436
524
  }, {
437
525
  F: __dxlog_file2,
438
- L: 81,
526
+ L: 80,
439
527
  S: this,
440
528
  C: (f, a) => f(...a)
441
529
  });
@@ -443,7 +531,15 @@ var SwarmMessenger = class {
443
531
  }
444
532
  async signal(message) {
445
533
  var _a, _b;
446
- (0, import_tiny_invariant2.default)(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message");
534
+ (0, import_invariant2.invariant)(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message", {
535
+ F: __dxlog_file2,
536
+ L: 85,
537
+ S: this,
538
+ A: [
539
+ "message.data?.signal || message.data?.signalBatch",
540
+ "'Invalid message'"
541
+ ]
542
+ });
447
543
  await this._sendReliableMessage({
448
544
  author: message.author,
449
545
  recipient: message.recipient,
@@ -479,7 +575,7 @@ var SwarmMessenger = class {
479
575
  msg: networkMessage
480
576
  }, {
481
577
  F: __dxlog_file2,
482
- L: 124,
578
+ L: 123,
483
579
  S: this,
484
580
  C: (f, a) => f(...a)
485
581
  });
@@ -494,16 +590,32 @@ var SwarmMessenger = class {
494
590
  }
495
591
  async _resolveAnswers(message) {
496
592
  var _a, _b, _c;
497
- (0, import_tiny_invariant2.default)((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId");
593
+ (0, import_invariant2.invariant)((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId", {
594
+ F: __dxlog_file2,
595
+ L: 135,
596
+ S: this,
597
+ A: [
598
+ "message.data?.answer?.offerMessageId",
599
+ "'No offerMessageId'"
600
+ ]
601
+ });
498
602
  const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
499
603
  if (offerRecord) {
500
604
  this._offerRecords.delete(message.data.answer.offerMessageId);
501
- (0, import_tiny_invariant2.default)((_c = message.data) == null ? void 0 : _c.answer, "No answer");
605
+ (0, import_invariant2.invariant)((_c = message.data) == null ? void 0 : _c.answer, "No answer", {
606
+ F: __dxlog_file2,
607
+ L: 139,
608
+ S: this,
609
+ A: [
610
+ "message.data?.answer",
611
+ "'No answer'"
612
+ ]
613
+ });
502
614
  (0, import_log2.log)("resolving", {
503
615
  answer: message.data.answer
504
616
  }, {
505
617
  F: __dxlog_file2,
506
- L: 141,
618
+ L: 140,
507
619
  S: this,
508
620
  C: (f, a) => f(...a)
509
621
  });
@@ -511,7 +623,15 @@ var SwarmMessenger = class {
511
623
  }
512
624
  }
513
625
  async _handleOffer({ author, recipient, message }) {
514
- (0, import_tiny_invariant2.default)(message.data.offer, "No offer");
626
+ (0, import_invariant2.invariant)(message.data.offer, "No offer", {
627
+ F: __dxlog_file2,
628
+ L: 154,
629
+ S: this,
630
+ A: [
631
+ "message.data.offer",
632
+ "'No offer'"
633
+ ]
634
+ });
515
635
  const offerMessage = {
516
636
  author,
517
637
  recipient,
@@ -539,15 +659,31 @@ var SwarmMessenger = class {
539
659
  err
540
660
  }, {
541
661
  F: __dxlog_file2,
542
- L: 175,
662
+ L: 174,
543
663
  S: this,
544
664
  C: (f, a) => f(...a)
545
665
  });
546
666
  }
547
667
  }
548
668
  async _handleSignal({ author, recipient, message }) {
549
- (0, import_tiny_invariant2.default)(message.messageId);
550
- (0, import_tiny_invariant2.default)(message.data.signal || message.data.signalBatch, "Invalid message");
669
+ (0, import_invariant2.invariant)(message.messageId, void 0, {
670
+ F: __dxlog_file2,
671
+ L: 187,
672
+ S: this,
673
+ A: [
674
+ "message.messageId",
675
+ ""
676
+ ]
677
+ });
678
+ (0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
679
+ F: __dxlog_file2,
680
+ L: 188,
681
+ S: this,
682
+ A: [
683
+ "message.data.signal || message.data.signalBatch",
684
+ "'Invalid message'"
685
+ ]
686
+ });
551
687
  const signalMessage = {
552
688
  author,
553
689
  recipient,
@@ -562,10 +698,10 @@ var SwarmMessenger = class {
562
698
  };
563
699
 
564
700
  // packages/core/mesh/network-manager/src/swarm/peer.ts
565
- var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
566
701
  var import_async2 = require("@dxos/async");
567
702
  var import_context3 = require("@dxos/context");
568
703
  var import_errors2 = require("@dxos/errors");
704
+ var import_invariant3 = require("@dxos/invariant");
569
705
  var import_keys3 = require("@dxos/keys");
570
706
  var import_log3 = require("@dxos/log");
571
707
  function _ts_decorate2(decorators, target, key, desc) {
@@ -611,7 +747,7 @@ var Peer = class {
611
747
  sessionId: (_a = this.connection) == null ? void 0 : _a.sessionId
612
748
  }, {
613
749
  F: __dxlog_file3,
614
- L: 107,
750
+ L: 106,
615
751
  S: this,
616
752
  C: (f, a) => f(...a)
617
753
  });
@@ -626,7 +762,15 @@ var Peer = class {
626
762
  }
627
763
  if (await this._callbacks.onOffer(remoteId)) {
628
764
  if (!this.connection) {
629
- (0, import_tiny_invariant3.default)(message.sessionId);
765
+ (0, import_invariant3.invariant)(message.sessionId, void 0, {
766
+ F: __dxlog_file3,
767
+ L: 126,
768
+ S: this,
769
+ A: [
770
+ "message.sessionId",
771
+ ""
772
+ ]
773
+ });
630
774
  const connection = this._createConnection(false, message.sessionId);
631
775
  try {
632
776
  await this._connectionLimiter.connecting(message.sessionId);
@@ -640,7 +784,7 @@ var Peer = class {
640
784
  err
641
785
  }, {
642
786
  F: __dxlog_file3,
643
- L: 135,
787
+ L: 134,
644
788
  S: this,
645
789
  C: (f, a) => f(...a)
646
790
  });
@@ -660,8 +804,24 @@ var Peer = class {
660
804
  * Initiate a connection to the remote peer.
661
805
  */
662
806
  async initiateConnection() {
663
- (0, import_tiny_invariant3.default)(!this.initiating, "Initiation in progress.");
664
- (0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
807
+ (0, import_invariant3.invariant)(!this.initiating, "Initiation in progress.", {
808
+ F: __dxlog_file3,
809
+ L: 151,
810
+ S: this,
811
+ A: [
812
+ "!this.initiating",
813
+ "'Initiation in progress.'"
814
+ ]
815
+ });
816
+ (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
817
+ F: __dxlog_file3,
818
+ L: 152,
819
+ S: this,
820
+ A: [
821
+ "!this.connection",
822
+ "'Already connected.'"
823
+ ]
824
+ });
665
825
  const sessionId = import_keys3.PublicKey.random();
666
826
  (0, import_log3.log)("initiating...", {
667
827
  id: this.id,
@@ -670,7 +830,7 @@ var Peer = class {
670
830
  sessionId
671
831
  }, {
672
832
  F: __dxlog_file3,
673
- L: 155,
833
+ L: 154,
674
834
  S: this,
675
835
  C: (f, a) => f(...a)
676
836
  });
@@ -694,14 +854,14 @@ var Peer = class {
694
854
  remoteId: this.id
695
855
  }, {
696
856
  F: __dxlog_file3,
697
- L: 170,
857
+ L: 169,
698
858
  S: this,
699
859
  C: (f, a) => f(...a)
700
860
  });
701
861
  if (connection.state !== ConnectionState.INITIAL) {
702
862
  (0, import_log3.log)("ignoring response", void 0, {
703
863
  F: __dxlog_file3,
704
- L: 172,
864
+ L: 171,
705
865
  S: this,
706
866
  C: (f, a) => f(...a)
707
867
  });
@@ -721,7 +881,7 @@ var Peer = class {
721
881
  remoteId: this.id
722
882
  }, {
723
883
  F: __dxlog_file3,
724
- L: 183,
884
+ L: 182,
725
885
  S: this,
726
886
  C: (f, a) => f(...a)
727
887
  });
@@ -745,11 +905,19 @@ var Peer = class {
745
905
  sessionId
746
906
  }, {
747
907
  F: __dxlog_file3,
748
- L: 197,
908
+ L: 196,
749
909
  S: this,
750
910
  C: (f, a) => f(...a)
751
911
  });
752
- (0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
912
+ (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
913
+ F: __dxlog_file3,
914
+ L: 203,
915
+ S: this,
916
+ A: [
917
+ "!this.connection",
918
+ "'Already connected.'"
919
+ ]
920
+ });
753
921
  const connection = new Connection(
754
922
  this.topic,
755
923
  this.localPeerId,
@@ -776,6 +944,18 @@ var Peer = class {
776
944
  this._lastConnectionTime = Date.now();
777
945
  this._callbacks.onConnected();
778
946
  this._connectionLimiter.doneConnecting(sessionId);
947
+ import_log3.log.trace("dxos.mesh.connection.connected", {
948
+ topic: this.topic,
949
+ localPeerId: this.localPeerId,
950
+ remotePeerId: this.id,
951
+ sessionId,
952
+ initiator
953
+ }, {
954
+ F: __dxlog_file3,
955
+ L: 229,
956
+ S: this,
957
+ C: (f, a) => f(...a)
958
+ });
779
959
  break;
780
960
  }
781
961
  case ConnectionState.CLOSED: {
@@ -786,11 +966,31 @@ var Peer = class {
786
966
  initiator
787
967
  }, {
788
968
  F: __dxlog_file3,
789
- L: 234,
969
+ L: 240,
970
+ S: this,
971
+ C: (f, a) => f(...a)
972
+ });
973
+ (0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
974
+ F: __dxlog_file3,
975
+ L: 241,
976
+ S: this,
977
+ A: [
978
+ "this.connection === connection",
979
+ "'Connection mismatch (race condition).'"
980
+ ]
981
+ });
982
+ import_log3.log.trace("dxos.mesh.connection.closed", {
983
+ topic: this.topic,
984
+ localPeerId: this.localPeerId,
985
+ remotePeerId: this.id,
986
+ sessionId,
987
+ initiator
988
+ }, {
989
+ F: __dxlog_file3,
990
+ L: 243,
790
991
  S: this,
791
992
  C: (f, a) => f(...a)
792
993
  });
793
- (0, import_tiny_invariant3.default)(this.connection === connection, "Connection mismatch (race condition).");
794
994
  if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
795
995
  this._availableAfter = 0;
796
996
  } else {
@@ -817,7 +1017,20 @@ var Peer = class {
817
1017
  err
818
1018
  }, {
819
1019
  F: __dxlog_file3,
820
- L: 263,
1020
+ L: 277,
1021
+ S: this,
1022
+ C: (f, a) => f(...a)
1023
+ });
1024
+ import_log3.log.trace("dxos.mesh.connection.error", {
1025
+ topic: this.topic,
1026
+ localPeerId: this.localPeerId,
1027
+ remotePeerId: this.id,
1028
+ sessionId,
1029
+ initiator,
1030
+ err
1031
+ }, {
1032
+ F: __dxlog_file3,
1033
+ L: 278,
821
1034
  S: this,
822
1035
  C: (f, a) => f(...a)
823
1036
  });
@@ -836,7 +1049,7 @@ var Peer = class {
836
1049
  sessionId: connection.sessionId
837
1050
  }, {
838
1051
  F: __dxlog_file3,
839
- L: 279,
1052
+ L: 301,
840
1053
  S: this,
841
1054
  C: (f, a) => f(...a)
842
1055
  });
@@ -846,7 +1059,7 @@ var Peer = class {
846
1059
  sessionId: connection.sessionId
847
1060
  }, {
848
1061
  F: __dxlog_file3,
849
- L: 285,
1062
+ L: 307,
850
1063
  S: this,
851
1064
  C: (f, a) => f(...a)
852
1065
  });
@@ -857,7 +1070,7 @@ var Peer = class {
857
1070
  message
858
1071
  }, {
859
1072
  F: __dxlog_file3,
860
- L: 290,
1073
+ L: 312,
861
1074
  S: this,
862
1075
  C: (f, a) => f(...a)
863
1076
  });
@@ -873,7 +1086,7 @@ var Peer = class {
873
1086
  topic: this.topic
874
1087
  }, {
875
1088
  F: __dxlog_file3,
876
- L: 300,
1089
+ L: 322,
877
1090
  S: this,
878
1091
  C: (f, a) => f(...a)
879
1092
  });
@@ -938,7 +1151,7 @@ var Swarm = class {
938
1151
  }
939
1152
  }), {
940
1153
  F: __dxlog_file4,
941
- L: 88,
1154
+ L: 87,
942
1155
  S: this,
943
1156
  C: (f, a) => f(...a)
944
1157
  });
@@ -946,7 +1159,7 @@ var Swarm = class {
946
1159
  peerId: _ownPeerId
947
1160
  }, {
948
1161
  F: __dxlog_file4,
949
- L: 92,
1162
+ L: 91,
950
1163
  S: this,
951
1164
  C: (f, a) => f(...a)
952
1165
  });
@@ -961,7 +1174,7 @@ var Swarm = class {
961
1174
  id: this._instanceId
962
1175
  }), {
963
1176
  F: __dxlog_file4,
964
- L: 101,
1177
+ L: 100,
965
1178
  S: this,
966
1179
  C: (f, a) => f(...a)
967
1180
  });
@@ -982,7 +1195,15 @@ var Swarm = class {
982
1195
  return this._topic;
983
1196
  }
984
1197
  async open() {
985
- (0, import_tiny_invariant4.default)(!this._listeningHandle);
1198
+ (0, import_invariant4.invariant)(!this._listeningHandle, void 0, {
1199
+ F: __dxlog_file4,
1200
+ L: 127,
1201
+ S: this,
1202
+ A: [
1203
+ "!this._listeningHandle",
1204
+ ""
1205
+ ]
1206
+ });
986
1207
  this._listeningHandle = await this._messenger.listen({
987
1208
  peerId: this._ownPeerId,
988
1209
  payloadType: "dxos.mesh.swarm.SwarmMessage",
@@ -991,7 +1212,7 @@ var Swarm = class {
991
1212
  err
992
1213
  }, {
993
1214
  F: __dxlog_file4,
994
- L: 135,
1215
+ L: 134,
995
1216
  S: this,
996
1217
  C: (f, a) => f(...a)
997
1218
  }));
@@ -1002,7 +1223,7 @@ var Swarm = class {
1002
1223
  var _a;
1003
1224
  (0, import_log4.log)("destroying...", void 0, {
1004
1225
  F: __dxlog_file4,
1005
- L: 141,
1226
+ L: 140,
1006
1227
  S: this,
1007
1228
  C: (f, a) => f(...a)
1008
1229
  });
@@ -1013,13 +1234,21 @@ var Swarm = class {
1013
1234
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
1014
1235
  (0, import_log4.log)("destroyed", void 0, {
1015
1236
  F: __dxlog_file4,
1016
- L: 148,
1237
+ L: 147,
1017
1238
  S: this,
1018
1239
  C: (f, a) => f(...a)
1019
1240
  });
1020
1241
  }
1021
1242
  async setTopology(topology) {
1022
- (0, import_tiny_invariant4.default)(!this._ctx.disposed, "Swarm is offline");
1243
+ (0, import_invariant4.invariant)(!this._ctx.disposed, "Swarm is offline", {
1244
+ F: __dxlog_file4,
1245
+ L: 151,
1246
+ S: this,
1247
+ A: [
1248
+ "!this._ctx.disposed",
1249
+ "'Swarm is offline'"
1250
+ ]
1251
+ });
1023
1252
  if (topology === this._topology) {
1024
1253
  return;
1025
1254
  }
@@ -1028,7 +1257,7 @@ var Swarm = class {
1028
1257
  topology: getClassName(topology)
1029
1258
  }, {
1030
1259
  F: __dxlog_file4,
1031
- L: 156,
1260
+ L: 155,
1032
1261
  S: this,
1033
1262
  C: (f, a) => f(...a)
1034
1263
  });
@@ -1043,14 +1272,14 @@ var Swarm = class {
1043
1272
  swarmEvent
1044
1273
  }, {
1045
1274
  F: __dxlog_file4,
1046
- L: 169,
1275
+ L: 168,
1047
1276
  S: this,
1048
1277
  C: (f, a) => f(...a)
1049
1278
  });
1050
1279
  if (this._ctx.disposed) {
1051
1280
  (0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
1052
1281
  F: __dxlog_file4,
1053
- L: 172,
1282
+ L: 171,
1054
1283
  S: this,
1055
1284
  C: (f, a) => f(...a)
1056
1285
  });
@@ -1062,7 +1291,7 @@ var Swarm = class {
1062
1291
  peerId
1063
1292
  }, {
1064
1293
  F: __dxlog_file4,
1065
- L: 178,
1294
+ L: 177,
1066
1295
  S: this,
1067
1296
  C: (f, a) => f(...a)
1068
1297
  });
@@ -1077,7 +1306,7 @@ var Swarm = class {
1077
1306
  if (((_a = peer.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
1078
1307
  void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
1079
1308
  F: __dxlog_file4,
1080
- L: 189,
1309
+ L: 188,
1081
1310
  S: this,
1082
1311
  C: (f, a) => f(...a)
1083
1312
  }));
@@ -1092,14 +1321,14 @@ var Swarm = class {
1092
1321
  message
1093
1322
  }, {
1094
1323
  F: __dxlog_file4,
1095
- L: 199,
1324
+ L: 198,
1096
1325
  S: this,
1097
1326
  C: (f, a) => f(...a)
1098
1327
  });
1099
1328
  if (this._ctx.disposed) {
1100
1329
  (0, import_log4.log)("ignored for disposed swarm", void 0, {
1101
1330
  F: __dxlog_file4,
1102
- L: 201,
1331
+ L: 200,
1103
1332
  S: this,
1104
1333
  C: (f, a) => f(...a)
1105
1334
  });
@@ -1107,13 +1336,21 @@ var Swarm = class {
1107
1336
  accept: false
1108
1337
  };
1109
1338
  }
1110
- (0, import_tiny_invariant4.default)(message.author);
1339
+ (0, import_invariant4.invariant)(message.author, void 0, {
1340
+ F: __dxlog_file4,
1341
+ L: 205,
1342
+ S: this,
1343
+ A: [
1344
+ "message.author",
1345
+ ""
1346
+ ]
1347
+ });
1111
1348
  if (!((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId))) {
1112
1349
  (0, import_log4.log)("rejecting offer with incorrect peerId", {
1113
1350
  message
1114
1351
  }, {
1115
1352
  F: __dxlog_file4,
1116
- L: 208,
1353
+ L: 207,
1117
1354
  S: this,
1118
1355
  C: (f, a) => f(...a)
1119
1356
  });
@@ -1126,7 +1363,7 @@ var Swarm = class {
1126
1363
  message
1127
1364
  }, {
1128
1365
  F: __dxlog_file4,
1129
- L: 212,
1366
+ L: 211,
1130
1367
  S: this,
1131
1368
  C: (f, a) => f(...a)
1132
1369
  });
@@ -1145,22 +1382,46 @@ var Swarm = class {
1145
1382
  message
1146
1383
  }, {
1147
1384
  F: __dxlog_file4,
1148
- L: 223,
1385
+ L: 222,
1149
1386
  S: this,
1150
1387
  C: (f, a) => f(...a)
1151
1388
  });
1152
1389
  if (this._ctx.disposed) {
1153
1390
  import_log4.log.info("ignored for offline swarm", void 0, {
1154
1391
  F: __dxlog_file4,
1155
- L: 225,
1392
+ L: 224,
1156
1393
  S: this,
1157
1394
  C: (f, a) => f(...a)
1158
1395
  });
1159
1396
  return;
1160
1397
  }
1161
- (0, import_tiny_invariant4.default)((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`);
1162
- (0, import_tiny_invariant4.default)((_b = message.topic) == null ? void 0 : _b.equals(this._topic));
1163
- (0, import_tiny_invariant4.default)(message.author);
1398
+ (0, import_invariant4.invariant)((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1399
+ F: __dxlog_file4,
1400
+ L: 227,
1401
+ S: this,
1402
+ A: [
1403
+ "message.recipient?.equals(this._ownPeerId)",
1404
+ "`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
1405
+ ]
1406
+ });
1407
+ (0, import_invariant4.invariant)((_b = message.topic) == null ? void 0 : _b.equals(this._topic), void 0, {
1408
+ F: __dxlog_file4,
1409
+ L: 231,
1410
+ S: this,
1411
+ A: [
1412
+ "message.topic?.equals(this._topic)",
1413
+ ""
1414
+ ]
1415
+ });
1416
+ (0, import_invariant4.invariant)(message.author, void 0, {
1417
+ F: __dxlog_file4,
1418
+ L: 232,
1419
+ S: this,
1420
+ A: [
1421
+ "message.author",
1422
+ ""
1423
+ ]
1424
+ });
1164
1425
  const peer = this._getOrCreatePeer(message.author);
1165
1426
  await peer.onSignal(message);
1166
1427
  }
@@ -1212,7 +1473,15 @@ var Swarm = class {
1212
1473
  return peer;
1213
1474
  }
1214
1475
  async _destroyPeer(peerId) {
1215
- (0, import_tiny_invariant4.default)(this._peers.has(peerId));
1476
+ (0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
1477
+ F: __dxlog_file4,
1478
+ L: 302,
1479
+ S: this,
1480
+ A: [
1481
+ "this._peers.has(peerId)",
1482
+ ""
1483
+ ]
1484
+ });
1216
1485
  await this._peers.get(peerId).destroy();
1217
1486
  this._peers.delete(peerId);
1218
1487
  }
@@ -1233,7 +1502,7 @@ var Swarm = class {
1233
1502
  } catch (err) {
1234
1503
  (0, import_log4.log)("initiation error", err, {
1235
1504
  F: __dxlog_file4,
1236
- L: 329,
1505
+ L: 328,
1237
1506
  S: this,
1238
1507
  C: (f, a) => f(...a)
1239
1508
  });
@@ -1261,7 +1530,7 @@ var Swarm = class {
1261
1530
  remoteId
1262
1531
  }, {
1263
1532
  F: __dxlog_file4,
1264
- L: 356,
1533
+ L: 355,
1265
1534
  S: this,
1266
1535
  C: (f, a) => f(...a)
1267
1536
  });
@@ -1278,7 +1547,7 @@ var Swarm = class {
1278
1547
  remoteId
1279
1548
  }, {
1280
1549
  F: __dxlog_file4,
1281
- L: 370,
1550
+ L: 369,
1282
1551
  S: this,
1283
1552
  C: (f, a) => f(...a)
1284
1553
  });
@@ -1288,7 +1557,7 @@ var Swarm = class {
1288
1557
  remoteId
1289
1558
  }, {
1290
1559
  F: __dxlog_file4,
1291
- L: 373,
1560
+ L: 372,
1292
1561
  S: this,
1293
1562
  C: (f, a) => f(...a)
1294
1563
  });
@@ -1398,6 +1667,7 @@ var SwarmMapper = class {
1398
1667
  var import_async5 = require("@dxos/async");
1399
1668
  var import_context5 = require("@dxos/context");
1400
1669
  var import_errors3 = require("@dxos/errors");
1670
+ var import_invariant5 = require("@dxos/invariant");
1401
1671
  var import_keys6 = require("@dxos/keys");
1402
1672
  var import_log6 = require("@dxos/log");
1403
1673
  var import_util4 = require("@dxos/util");
@@ -1421,9 +1691,9 @@ var ConnectionLimiter = class {
1421
1691
  * @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
1422
1692
  */
1423
1693
  async connecting(sessionId) {
1424
- (0, import_log6.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
1694
+ (0, import_invariant5.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
1425
1695
  F: __dxlog_file6,
1426
- L: 47,
1696
+ L: 48,
1427
1697
  S: this,
1428
1698
  A: [
1429
1699
  "!this._waitingPromises.has(sessionId)",
@@ -1434,7 +1704,7 @@ var ConnectionLimiter = class {
1434
1704
  sessionId
1435
1705
  }, {
1436
1706
  F: __dxlog_file6,
1437
- L: 48,
1707
+ L: 49,
1438
1708
  S: this,
1439
1709
  C: (f, a) => f(...a)
1440
1710
  });
@@ -1449,7 +1719,7 @@ var ConnectionLimiter = class {
1449
1719
  sessionId
1450
1720
  }, {
1451
1721
  F: __dxlog_file6,
1452
- L: 56,
1722
+ L: 57,
1453
1723
  S: this,
1454
1724
  C: (f, a) => f(...a)
1455
1725
  });
@@ -1462,7 +1732,7 @@ var ConnectionLimiter = class {
1462
1732
  sessionId
1463
1733
  }, {
1464
1734
  F: __dxlog_file6,
1465
- L: 63,
1735
+ L: 64,
1466
1736
  S: this,
1467
1737
  C: (f, a) => f(...a)
1468
1738
  });
@@ -1542,8 +1812,8 @@ var ConnectionLog = class {
1542
1812
  };
1543
1813
 
1544
1814
  // packages/core/mesh/network-manager/src/network-manager.ts
1545
- var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
1546
1815
  var import_async7 = require("@dxos/async");
1816
+ var import_invariant6 = require("@dxos/invariant");
1547
1817
  var import_keys8 = require("@dxos/keys");
1548
1818
  var import_log7 = require("@dxos/log");
1549
1819
  var import_messaging = require("@dxos/messaging");
@@ -1602,7 +1872,7 @@ var NetworkManager = class {
1602
1872
  id: this._instanceId
1603
1873
  }), {
1604
1874
  F: __dxlog_file7,
1605
- L: 131,
1875
+ L: 130,
1606
1876
  S: this,
1607
1877
  C: (f, a) => f(...a)
1608
1878
  });
@@ -1612,7 +1882,7 @@ var NetworkManager = class {
1612
1882
  id: this._instanceId
1613
1883
  }), {
1614
1884
  F: __dxlog_file7,
1615
- L: 134,
1885
+ L: 133,
1616
1886
  S: this,
1617
1887
  C: (f, a) => f(...a)
1618
1888
  });
@@ -1622,7 +1892,7 @@ var NetworkManager = class {
1622
1892
  await this.leaveSwarm(topic).catch((err) => {
1623
1893
  (0, import_log7.log)(err, void 0, {
1624
1894
  F: __dxlog_file7,
1625
- L: 140,
1895
+ L: 139,
1626
1896
  S: this,
1627
1897
  C: (f, a) => f(...a)
1628
1898
  });
@@ -1636,10 +1906,42 @@ var NetworkManager = class {
1636
1906
  */
1637
1907
  async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
1638
1908
  var _a;
1639
- (0, import_tiny_invariant5.default)(import_keys8.PublicKey.isPublicKey(topic));
1640
- (0, import_tiny_invariant5.default)(import_keys8.PublicKey.isPublicKey(peerId));
1641
- (0, import_tiny_invariant5.default)(topology);
1642
- (0, import_tiny_invariant5.default)(typeof protocol === "function");
1909
+ (0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(topic), void 0, {
1910
+ F: __dxlog_file7,
1911
+ L: 157,
1912
+ S: this,
1913
+ A: [
1914
+ "PublicKey.isPublicKey(topic)",
1915
+ ""
1916
+ ]
1917
+ });
1918
+ (0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(peerId), void 0, {
1919
+ F: __dxlog_file7,
1920
+ L: 158,
1921
+ S: this,
1922
+ A: [
1923
+ "PublicKey.isPublicKey(peerId)",
1924
+ ""
1925
+ ]
1926
+ });
1927
+ (0, import_invariant6.invariant)(topology, void 0, {
1928
+ F: __dxlog_file7,
1929
+ L: 159,
1930
+ S: this,
1931
+ A: [
1932
+ "topology",
1933
+ ""
1934
+ ]
1935
+ });
1936
+ (0, import_invariant6.invariant)(typeof protocol === "function", void 0, {
1937
+ F: __dxlog_file7,
1938
+ L: 160,
1939
+ S: this,
1940
+ A: [
1941
+ "typeof protocol === 'function'",
1942
+ ""
1943
+ ]
1944
+ });
1643
1945
  if (this._swarms.has(topic)) {
1644
1946
  throw new Error(`Already connected to swarm: ${import_keys8.PublicKey.from(topic)}`);
1645
1947
  }
@@ -1649,7 +1951,7 @@ var NetworkManager = class {
1649
1951
  topology: topology.toString()
1650
1952
  }, {
1651
1953
  F: __dxlog_file7,
1652
- L: 166,
1954
+ L: 165,
1653
1955
  S: this,
1654
1956
  C: (f, a) => f(...a)
1655
1957
  });
@@ -1659,7 +1961,7 @@ var NetworkManager = class {
1659
1961
  error
1660
1962
  }, {
1661
1963
  F: __dxlog_file7,
1662
- L: 179,
1964
+ L: 178,
1663
1965
  S: this,
1664
1966
  C: (f, a) => f(...a)
1665
1967
  });
@@ -1672,7 +1974,7 @@ var NetworkManager = class {
1672
1974
  peerId
1673
1975
  }).catch((error) => import_log7.log.catch(error, void 0, {
1674
1976
  F: __dxlog_file7,
1675
- L: 188,
1977
+ L: 187,
1676
1978
  S: this,
1677
1979
  C: (f, a) => f(...a)
1678
1980
  }));
@@ -1683,7 +1985,7 @@ var NetworkManager = class {
1683
1985
  count: this._swarms.size
1684
1986
  }, {
1685
1987
  F: __dxlog_file7,
1686
- L: 192,
1988
+ L: 191,
1687
1989
  S: this,
1688
1990
  C: (f, a) => f(...a)
1689
1991
  });
@@ -1703,7 +2005,7 @@ var NetworkManager = class {
1703
2005
  topic: import_keys8.PublicKey.from(topic)
1704
2006
  }, {
1705
2007
  F: __dxlog_file7,
1706
- L: 208,
2008
+ L: 207,
1707
2009
  S: this,
1708
2010
  C: (f, a) => f(...a)
1709
2011
  });
@@ -1724,7 +2026,7 @@ var NetworkManager = class {
1724
2026
  count: this._swarms.size
1725
2027
  }, {
1726
2028
  F: __dxlog_file7,
1727
- L: 222,
2029
+ L: 221,
1728
2030
  S: this,
1729
2031
  C: (f, a) => f(...a)
1730
2032
  });
@@ -1758,17 +2060,34 @@ var NetworkManager = class {
1758
2060
  };
1759
2061
 
1760
2062
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
1761
- var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
2063
+ var import_invariant7 = require("@dxos/invariant");
2064
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
1762
2065
  var FullyConnectedTopology = class {
1763
2066
  toString() {
1764
2067
  return "FullyConnectedTopology";
1765
2068
  }
1766
2069
  init(controller) {
1767
- (0, import_tiny_invariant6.default)(!this._controller, "Already initialized");
2070
+ (0, import_invariant7.invariant)(!this._controller, "Already initialized", {
2071
+ F: __dxlog_file8,
2072
+ L: 18,
2073
+ S: this,
2074
+ A: [
2075
+ "!this._controller",
2076
+ "'Already initialized'"
2077
+ ]
2078
+ });
1768
2079
  this._controller = controller;
1769
2080
  }
1770
2081
  update() {
1771
- (0, import_tiny_invariant6.default)(this._controller, "Not initialized");
2082
+ (0, import_invariant7.invariant)(this._controller, "Not initialized", {
2083
+ F: __dxlog_file8,
2084
+ L: 23,
2085
+ S: this,
2086
+ A: [
2087
+ "this._controller",
2088
+ "'Not initialized'"
2089
+ ]
2090
+ });
1772
2091
  const { candidates: discovered } = this._controller.getState();
1773
2092
  for (const peer of discovered) {
1774
2093
  this._controller.connect(peer);
@@ -1782,10 +2101,10 @@ var FullyConnectedTopology = class {
1782
2101
  };
1783
2102
 
1784
2103
  // packages/core/mesh/network-manager/src/topology/mmst-topology.ts
1785
- var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
1786
2104
  var import_xor_distance = __toESM(require("xor-distance"));
2105
+ var import_invariant8 = require("@dxos/invariant");
1787
2106
  var import_log8 = require("@dxos/log");
1788
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2107
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
1789
2108
  var MMSTTopology = class {
1790
2109
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
1791
2110
  this._sampleCollected = false;
@@ -1794,15 +2113,31 @@ var MMSTTopology = class {
1794
2113
  this._sampleSize = sampleSize;
1795
2114
  }
1796
2115
  init(controller) {
1797
- (0, import_tiny_invariant7.default)(!this._controller, "Already initialized");
2116
+ (0, import_invariant8.invariant)(!this._controller, "Already initialized", {
2117
+ F: __dxlog_file9,
2118
+ L: 46,
2119
+ S: this,
2120
+ A: [
2121
+ "!this._controller",
2122
+ "'Already initialized'"
2123
+ ]
2124
+ });
1798
2125
  this._controller = controller;
1799
2126
  }
1800
2127
  update() {
1801
- (0, import_tiny_invariant7.default)(this._controller, "Not initialized");
2128
+ (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2129
+ F: __dxlog_file9,
2130
+ L: 51,
2131
+ S: this,
2132
+ A: [
2133
+ "this._controller",
2134
+ "'Not initialized'"
2135
+ ]
2136
+ });
1802
2137
  const { connected, candidates } = this._controller.getState();
1803
2138
  if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
1804
2139
  (0, import_log8.log)("Running the algorithm.", void 0, {
1805
- F: __dxlog_file8,
2140
+ F: __dxlog_file9,
1806
2141
  L: 55,
1807
2142
  S: this,
1808
2143
  C: (f, a) => f(...a)
@@ -1812,11 +2147,19 @@ var MMSTTopology = class {
1812
2147
  }
1813
2148
  }
1814
2149
  async onOffer(peer) {
1815
- (0, import_tiny_invariant7.default)(this._controller, "Not initialized");
2150
+ (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2151
+ F: __dxlog_file9,
2152
+ L: 62,
2153
+ S: this,
2154
+ A: [
2155
+ "this._controller",
2156
+ "'Not initialized'"
2157
+ ]
2158
+ });
1816
2159
  const { connected } = this._controller.getState();
1817
2160
  const accept = connected.length < this._maxPeers;
1818
2161
  (0, import_log8.log)(`Offer ${peer} accept=${accept}`, void 0, {
1819
- F: __dxlog_file8,
2162
+ F: __dxlog_file9,
1820
2163
  L: 65,
1821
2164
  S: this,
1822
2165
  C: (f, a) => f(...a)
@@ -1826,13 +2169,21 @@ var MMSTTopology = class {
1826
2169
  async destroy() {
1827
2170
  }
1828
2171
  _runAlgorithm() {
1829
- (0, import_tiny_invariant7.default)(this._controller, "Not initialized");
2172
+ (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2173
+ F: __dxlog_file9,
2174
+ L: 74,
2175
+ S: this,
2176
+ A: [
2177
+ "this._controller",
2178
+ "'Not initialized'"
2179
+ ]
2180
+ });
1830
2181
  const { connected, candidates, ownPeerId } = this._controller.getState();
1831
2182
  if (connected.length > this._maxPeers) {
1832
2183
  const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
1833
2184
  for (const peer of sorted) {
1834
2185
  (0, import_log8.log)(`Disconnect ${peer}.`, void 0, {
1835
- F: __dxlog_file8,
2186
+ F: __dxlog_file9,
1836
2187
  L: 83,
1837
2188
  S: this,
1838
2189
  C: (f, a) => f(...a)
@@ -1844,7 +2195,7 @@ var MMSTTopology = class {
1844
2195
  const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
1845
2196
  for (const peer of sorted) {
1846
2197
  (0, import_log8.log)(`Connect ${peer}.`, void 0, {
1847
- F: __dxlog_file8,
2198
+ F: __dxlog_file9,
1848
2199
  L: 91,
1849
2200
  S: this,
1850
2201
  C: (f, a) => f(...a)
@@ -1860,9 +2211,9 @@ var MMSTTopology = class {
1860
2211
  var sortByXorDistance = (keys, reference) => keys.sort((a, b) => import_xor_distance.default.gt((0, import_xor_distance.default)(a.asBuffer(), reference.asBuffer()), (0, import_xor_distance.default)(b.asBuffer(), reference.asBuffer())));
1861
2212
 
1862
2213
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
1863
- var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
2214
+ var import_invariant9 = require("@dxos/invariant");
1864
2215
  var import_log9 = require("@dxos/log");
1865
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2216
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
1866
2217
  var StarTopology = class {
1867
2218
  // prettier-ignore
1868
2219
  constructor(_centralPeer) {
@@ -1872,16 +2223,32 @@ var StarTopology = class {
1872
2223
  return `StarTopology(${this._centralPeer.truncate()})`;
1873
2224
  }
1874
2225
  init(controller) {
1875
- (0, import_tiny_invariant8.default)(!this._controller, "Already initialized.");
2226
+ (0, import_invariant9.invariant)(!this._controller, "Already initialized.", {
2227
+ F: __dxlog_file10,
2228
+ L: 24,
2229
+ S: this,
2230
+ A: [
2231
+ "!this._controller",
2232
+ "'Already initialized.'"
2233
+ ]
2234
+ });
1876
2235
  this._controller = controller;
1877
2236
  }
1878
2237
  update() {
1879
- (0, import_tiny_invariant8.default)(this._controller, "Not initialized.");
2238
+ (0, import_invariant9.invariant)(this._controller, "Not initialized.", {
2239
+ F: __dxlog_file10,
2240
+ L: 29,
2241
+ S: this,
2242
+ A: [
2243
+ "this._controller",
2244
+ "'Not initialized.'"
2245
+ ]
2246
+ });
1880
2247
  const { candidates, connected, ownPeerId } = this._controller.getState();
1881
2248
  if (!ownPeerId.equals(this._centralPeer)) {
1882
2249
  (0, import_log9.log)("leaf peer dropping all connections apart from central peer.", void 0, {
1883
- F: __dxlog_file9,
1884
- L: 33,
2250
+ F: __dxlog_file10,
2251
+ L: 32,
1885
2252
  S: this,
1886
2253
  C: (f, a) => f(...a)
1887
2254
  });
@@ -1890,8 +2257,8 @@ var StarTopology = class {
1890
2257
  (0, import_log9.log)("dropping connection", {
1891
2258
  peer
1892
2259
  }, {
1893
- F: __dxlog_file9,
1894
- L: 38,
2260
+ F: __dxlog_file10,
2261
+ L: 37,
1895
2262
  S: this,
1896
2263
  C: (f, a) => f(...a)
1897
2264
  });
@@ -1904,8 +2271,8 @@ var StarTopology = class {
1904
2271
  (0, import_log9.log)("connecting to peer", {
1905
2272
  peer
1906
2273
  }, {
1907
- F: __dxlog_file9,
1908
- L: 47,
2274
+ F: __dxlog_file10,
2275
+ L: 46,
1909
2276
  S: this,
1910
2277
  C: (f, a) => f(...a)
1911
2278
  });
@@ -1914,15 +2281,23 @@ var StarTopology = class {
1914
2281
  }
1915
2282
  }
1916
2283
  async onOffer(peer) {
1917
- (0, import_tiny_invariant8.default)(this._controller, "Not initialized.");
2284
+ (0, import_invariant9.invariant)(this._controller, "Not initialized.", {
2285
+ F: __dxlog_file10,
2286
+ L: 53,
2287
+ S: this,
2288
+ A: [
2289
+ "this._controller",
2290
+ "'Not initialized.'"
2291
+ ]
2292
+ });
1918
2293
  const { ownPeerId } = this._controller.getState();
1919
2294
  (0, import_log9.log)("offer", {
1920
2295
  peer,
1921
2296
  isCentral: peer.equals(this._centralPeer),
1922
2297
  isSelfCentral: ownPeerId.equals(this._centralPeer)
1923
2298
  }, {
1924
- F: __dxlog_file9,
1925
- L: 56,
2299
+ F: __dxlog_file10,
2300
+ L: 55,
1926
2301
  S: this,
1927
2302
  C: (f, a) => f(...a)
1928
2303
  });
@@ -1934,9 +2309,9 @@ var StarTopology = class {
1934
2309
 
1935
2310
  // packages/core/mesh/network-manager/src/transport/memory-transport.ts
1936
2311
  var import_node_stream = require("node:stream");
1937
- var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
1938
2312
  var import_async8 = require("@dxos/async");
1939
2313
  var import_debug4 = require("@dxos/debug");
2314
+ var import_invariant10 = require("@dxos/invariant");
1940
2315
  var import_keys9 = require("@dxos/keys");
1941
2316
  var import_log10 = require("@dxos/log");
1942
2317
  var import_util7 = require("@dxos/util");
@@ -1950,7 +2325,7 @@ function _ts_decorate4(decorators, target, key, desc) {
1950
2325
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1951
2326
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1952
2327
  }
1953
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2328
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
1954
2329
  var MEMORY_TRANSPORT_DELAY = 1;
1955
2330
  var createStreamDelay = (delay) => {
1956
2331
  return new import_node_stream.Transform({
@@ -1976,17 +2351,25 @@ var _MemoryTransport = class {
1976
2351
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1977
2352
  this._destroyed = false;
1978
2353
  (0, import_log10.log)("creating", void 0, {
1979
- F: __dxlog_file10,
2354
+ F: __dxlog_file11,
1980
2355
  L: 64,
1981
2356
  S: this,
1982
2357
  C: (f, a) => f(...a)
1983
2358
  });
1984
- (0, import_tiny_invariant9.default)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
2359
+ (0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2360
+ F: __dxlog_file11,
2361
+ L: 66,
2362
+ S: this,
2363
+ A: [
2364
+ "!MemoryTransport._connections.has(this._instanceId)",
2365
+ "'Duplicate memory connection'"
2366
+ ]
2367
+ });
1985
2368
  _MemoryTransport._connections.set(this._instanceId, this);
1986
2369
  if (this.options.initiator) {
1987
2370
  setTimeout(async () => {
1988
2371
  (0, import_log10.log)("sending signal", void 0, {
1989
- F: __dxlog_file10,
2372
+ F: __dxlog_file11,
1990
2373
  L: 73,
1991
2374
  S: this,
1992
2375
  C: (f, a) => f(...a)
@@ -2015,11 +2398,19 @@ var _MemoryTransport = class {
2015
2398
  this.closed.emit();
2016
2399
  return;
2017
2400
  }
2018
- (0, import_tiny_invariant9.default)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`);
2401
+ (0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
2402
+ F: __dxlog_file11,
2403
+ L: 99,
2404
+ S: this,
2405
+ A: [
2406
+ "!this._remoteConnection._remoteConnection",
2407
+ "`Remote already connected: ${this._remoteInstanceId}`"
2408
+ ]
2409
+ });
2019
2410
  this._remoteConnection._remoteConnection = this;
2020
2411
  this._remoteConnection._remoteInstanceId = this._instanceId;
2021
2412
  (0, import_log10.log)("connected", void 0, {
2022
- F: __dxlog_file10,
2413
+ F: __dxlog_file11,
2023
2414
  L: 103,
2024
2415
  S: this,
2025
2416
  C: (f, a) => f(...a)
@@ -2037,7 +2428,7 @@ var _MemoryTransport = class {
2037
2428
  }
2038
2429
  async destroy() {
2039
2430
  (0, import_log10.log)("closing", void 0, {
2040
- F: __dxlog_file10,
2431
+ F: __dxlog_file11,
2041
2432
  L: 124,
2042
2433
  S: this,
2043
2434
  C: (f, a) => f(...a)
@@ -2046,7 +2437,7 @@ var _MemoryTransport = class {
2046
2437
  _MemoryTransport._connections.delete(this._instanceId);
2047
2438
  if (this._remoteConnection) {
2048
2439
  (0, import_log10.log)("closing", void 0, {
2049
- F: __dxlog_file10,
2440
+ F: __dxlog_file11,
2050
2441
  L: 129,
2051
2442
  S: this,
2052
2443
  C: (f, a) => f(...a)
@@ -2059,7 +2450,7 @@ var _MemoryTransport = class {
2059
2450
  this._remoteConnection._remoteConnection = void 0;
2060
2451
  this._remoteConnection = void 0;
2061
2452
  (0, import_log10.log)("closed", void 0, {
2062
- F: __dxlog_file10,
2453
+ F: __dxlog_file11,
2063
2454
  L: 147,
2064
2455
  S: this,
2065
2456
  C: (f, a) => f(...a)
@@ -2067,7 +2458,7 @@ var _MemoryTransport = class {
2067
2458
  }
2068
2459
  this.closed.emit();
2069
2460
  (0, import_log10.log)("closed", void 0, {
2070
- F: __dxlog_file10,
2461
+ F: __dxlog_file11,
2071
2462
  L: 151,
2072
2463
  S: this,
2073
2464
  C: (f, a) => f(...a)
@@ -2077,7 +2468,7 @@ var _MemoryTransport = class {
2077
2468
  (0, import_log10.log)("received signal", {
2078
2469
  payload
2079
2470
  }, {
2080
- F: __dxlog_file10,
2471
+ F: __dxlog_file11,
2081
2472
  L: 155,
2082
2473
  S: this,
2083
2474
  C: (f, a) => f(...a)
@@ -2104,9 +2495,9 @@ _ts_decorate4([
2104
2495
 
2105
2496
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
2106
2497
  var import_simple_peer = __toESM(require("simple-peer"));
2107
- var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
2108
2498
  var import_async9 = require("@dxos/async");
2109
2499
  var import_debug5 = require("@dxos/debug");
2500
+ var import_invariant11 = require("@dxos/invariant");
2110
2501
  var import_keys10 = require("@dxos/keys");
2111
2502
  var import_log11 = require("@dxos/log");
2112
2503
  var import_protocols5 = require("@dxos/protocols");
@@ -2119,7 +2510,7 @@ try {
2119
2510
  }
2120
2511
 
2121
2512
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
2122
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
2513
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
2123
2514
  var WebRTCTransport = class {
2124
2515
  constructor(params) {
2125
2516
  var _a;
@@ -2132,13 +2523,13 @@ var WebRTCTransport = class {
2132
2523
  import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
2133
2524
  id: this._instanceId
2134
2525
  }), {
2135
- F: __dxlog_file11,
2526
+ F: __dxlog_file12,
2136
2527
  L: 39,
2137
2528
  S: this,
2138
2529
  C: (f, a) => f(...a)
2139
2530
  });
2140
2531
  (0, import_log11.log)("created connection", params, {
2141
- F: __dxlog_file11,
2532
+ F: __dxlog_file12,
2142
2533
  L: 40,
2143
2534
  S: this,
2144
2535
  C: (f, a) => f(...a)
@@ -2150,7 +2541,7 @@ var WebRTCTransport = class {
2150
2541
  });
2151
2542
  this._peer.on("signal", async (data) => {
2152
2543
  (0, import_log11.log)("signal", data, {
2153
- F: __dxlog_file11,
2544
+ F: __dxlog_file12,
2154
2545
  L: 48,
2155
2546
  S: this,
2156
2547
  C: (f, a) => f(...a)
@@ -2163,7 +2554,7 @@ var WebRTCTransport = class {
2163
2554
  });
2164
2555
  this._peer.on("connect", () => {
2165
2556
  (0, import_log11.log)("connected", void 0, {
2166
- F: __dxlog_file11,
2557
+ F: __dxlog_file12,
2167
2558
  L: 53,
2168
2559
  S: this,
2169
2560
  C: (f, a) => f(...a)
@@ -2173,7 +2564,7 @@ var WebRTCTransport = class {
2173
2564
  });
2174
2565
  this._peer.on("close", async () => {
2175
2566
  (0, import_log11.log)("closed", void 0, {
2176
- F: __dxlog_file11,
2567
+ F: __dxlog_file12,
2177
2568
  L: 59,
2178
2569
  S: this,
2179
2570
  C: (f, a) => f(...a)
@@ -2191,7 +2582,7 @@ var WebRTCTransport = class {
2191
2582
  config: this.params.webrtcConfig,
2192
2583
  stats
2193
2584
  }, {
2194
- F: __dxlog_file11,
2585
+ F: __dxlog_file12,
2195
2586
  L: 71,
2196
2587
  S: this,
2197
2588
  C: (f, a) => f(...a)
@@ -2205,7 +2596,7 @@ var WebRTCTransport = class {
2205
2596
  import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
2206
2597
  id: this._instanceId
2207
2598
  }), {
2208
- F: __dxlog_file11,
2599
+ F: __dxlog_file12,
2209
2600
  L: 81,
2210
2601
  S: this,
2211
2602
  C: (f, a) => f(...a)
@@ -2213,7 +2604,7 @@ var WebRTCTransport = class {
2213
2604
  }
2214
2605
  async destroy() {
2215
2606
  (0, import_log11.log)("closing...", void 0, {
2216
- F: __dxlog_file11,
2607
+ F: __dxlog_file12,
2217
2608
  L: 85,
2218
2609
  S: this,
2219
2610
  C: (f, a) => f(...a)
@@ -2223,7 +2614,7 @@ var WebRTCTransport = class {
2223
2614
  this._peer.destroy();
2224
2615
  this.closed.emit();
2225
2616
  (0, import_log11.log)("closed", void 0, {
2226
- F: __dxlog_file11,
2617
+ F: __dxlog_file12,
2227
2618
  L: 90,
2228
2619
  S: this,
2229
2620
  C: (f, a) => f(...a)
@@ -2233,7 +2624,15 @@ var WebRTCTransport = class {
2233
2624
  if (this._closed) {
2234
2625
  return;
2235
2626
  }
2236
- (0, import_tiny_invariant10.default)(signal.payload.data, "Signal message must contain signal data.");
2627
+ (0, import_invariant11.invariant)(signal.payload.data, "Signal message must contain signal data.", {
2628
+ F: __dxlog_file12,
2629
+ L: 98,
2630
+ S: this,
2631
+ A: [
2632
+ "signal.payload.data",
2633
+ "'Signal message must contain signal data.'"
2634
+ ]
2635
+ });
2237
2636
  this._peer.signal(signal.payload.data);
2238
2637
  }
2239
2638
  async _disconnectStreams() {
@@ -2250,13 +2649,13 @@ var createWebRTCTransportFactory = (webrtcConfig) => ({
2250
2649
 
2251
2650
  // packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
2252
2651
  var import_node_stream2 = require("node:stream");
2253
- var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
2254
2652
  var import_codec_protobuf = require("@dxos/codec-protobuf");
2653
+ var import_invariant12 = require("@dxos/invariant");
2255
2654
  var import_keys11 = require("@dxos/keys");
2256
2655
  var import_log12 = require("@dxos/log");
2257
2656
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
2258
2657
  var import_util8 = require("@dxos/util");
2259
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
2658
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
2260
2659
  var WebRTCTransportService = class {
2261
2660
  // prettier-ignore
2262
2661
  constructor(_webrtcConfig) {
@@ -2267,6 +2666,13 @@ var WebRTCTransportService = class {
2267
2666
  const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
2268
2667
  const duplex = new import_node_stream2.Duplex({
2269
2668
  read: () => {
2669
+ const callbacks = [
2670
+ ...transportState.writeCallbacks
2671
+ ];
2672
+ transportState.writeCallbacks.length = 0;
2673
+ for (const cb of callbacks) {
2674
+ cb();
2675
+ }
2270
2676
  },
2271
2677
  write: function(chunk, _, callback) {
2272
2678
  next({
@@ -2318,21 +2724,45 @@ var WebRTCTransportService = class {
2318
2724
  });
2319
2725
  close();
2320
2726
  });
2321
- ready();
2322
- this.transports.set(request.proxyId, {
2727
+ const transportState = {
2323
2728
  transport,
2324
- stream: duplex
2325
- });
2729
+ stream: duplex,
2730
+ writeCallbacks: []
2731
+ };
2732
+ ready();
2733
+ this.transports.set(request.proxyId, transportState);
2326
2734
  });
2327
2735
  return rpcStream;
2328
2736
  }
2329
2737
  async sendSignal({ proxyId, signal }) {
2330
- (0, import_tiny_invariant11.default)(this.transports.has(proxyId));
2738
+ (0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
2739
+ F: __dxlog_file13,
2740
+ L: 113,
2741
+ S: this,
2742
+ A: [
2743
+ "this.transports.has(proxyId)",
2744
+ ""
2745
+ ]
2746
+ });
2331
2747
  await this.transports.get(proxyId).transport.signal(signal);
2332
2748
  }
2333
2749
  async sendData({ proxyId, payload }) {
2334
- (0, import_tiny_invariant11.default)(this.transports.has(proxyId));
2335
- await this.transports.get(proxyId).stream.push(payload);
2750
+ (0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
2751
+ F: __dxlog_file13,
2752
+ L: 118,
2753
+ S: this,
2754
+ A: [
2755
+ "this.transports.has(proxyId)",
2756
+ ""
2757
+ ]
2758
+ });
2759
+ const state = this.transports.get(proxyId);
2760
+ const bufferHasSpace = state.stream.push(payload);
2761
+ if (!bufferHasSpace) {
2762
+ await new Promise((resolve) => {
2763
+ state.writeCallbacks.push(resolve);
2764
+ });
2765
+ }
2336
2766
  }
2337
2767
  async close({ proxyId }) {
2338
2768
  var _a, _b;
@@ -2340,8 +2770,8 @@ var WebRTCTransportService = class {
2340
2770
  await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
2341
2771
  this.transports.delete(proxyId);
2342
2772
  (0, import_log12.log)("Closed.", void 0, {
2343
- F: __dxlog_file12,
2344
- L: 109,
2773
+ F: __dxlog_file13,
2774
+ L: 132,
2345
2775
  S: this,
2346
2776
  C: (f, a) => f(...a)
2347
2777
  });
@@ -2349,15 +2779,16 @@ var WebRTCTransportService = class {
2349
2779
  };
2350
2780
 
2351
2781
  // packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
2352
- var import_tiny_invariant12 = __toESM(require("tiny-invariant"));
2782
+ var import_node_stream3 = require("node:stream");
2353
2783
  var import_async10 = require("@dxos/async");
2354
2784
  var import_context6 = require("@dxos/context");
2355
2785
  var import_debug6 = require("@dxos/debug");
2786
+ var import_invariant13 = require("@dxos/invariant");
2356
2787
  var import_keys12 = require("@dxos/keys");
2357
2788
  var import_log13 = require("@dxos/log");
2358
2789
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
2359
2790
  var import_util9 = require("@dxos/util");
2360
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
2791
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
2361
2792
  var WebRTCTransportProxy = class {
2362
2793
  // prettier-ignore
2363
2794
  constructor(_params) {
@@ -2375,8 +2806,8 @@ var WebRTCTransportProxy = class {
2375
2806
  this._serviceStream.waitUntilReady().then(() => {
2376
2807
  this._serviceStream.subscribe(async (event) => {
2377
2808
  (0, import_log13.log)("WebRTCTransportProxy: event", event, {
2378
- F: __dxlog_file13,
2379
- L: 50,
2809
+ F: __dxlog_file14,
2810
+ L: 51,
2380
2811
  S: this,
2381
2812
  C: (f, a) => f(...a)
2382
2813
  });
@@ -2388,28 +2819,24 @@ var WebRTCTransportProxy = class {
2388
2819
  await this._handleSignal(event.signal);
2389
2820
  }
2390
2821
  });
2391
- const dataListener = async (data) => {
2392
- try {
2393
- await this._params.bridgeService.sendData({
2822
+ this._params.stream.pipe(new import_node_stream3.Writable({
2823
+ write: (chunk, _, callback) => {
2824
+ this._params.bridgeService.sendData({
2394
2825
  proxyId: this._proxyId,
2395
- payload: data
2396
- });
2397
- } catch (err) {
2398
- import_log13.log.catch(err, void 0, {
2399
- F: __dxlog_file13,
2400
- L: 67,
2401
- S: this,
2402
- C: (f, a) => f(...a)
2826
+ payload: chunk
2827
+ }).then(() => callback(), (err) => {
2828
+ import_log13.log.catch(err, void 0, {
2829
+ F: __dxlog_file14,
2830
+ L: 69,
2831
+ S: this,
2832
+ C: (f, a) => f(...a)
2833
+ });
2403
2834
  });
2404
2835
  }
2405
- };
2406
- this._params.stream.on("data", dataListener);
2407
- this._ctx.onDispose(() => {
2408
- this._params.stream.off("data", dataListener);
2409
- });
2836
+ }));
2410
2837
  }, (error) => import_log13.log.catch(error, void 0, {
2411
- F: __dxlog_file13,
2412
- L: 73,
2838
+ F: __dxlog_file14,
2839
+ L: 75,
2413
2840
  S: this,
2414
2841
  C: (f, a) => f(...a)
2415
2842
  }));
@@ -2454,8 +2881,8 @@ var WebRTCTransportProxy = class {
2454
2881
  });
2455
2882
  } catch (err) {
2456
2883
  import_log13.log.catch(err, void 0, {
2457
- F: __dxlog_file13,
2458
- L: 124,
2884
+ F: __dxlog_file14,
2885
+ L: 126,
2459
2886
  S: this,
2460
2887
  C: (f, a) => f(...a)
2461
2888
  });
@@ -2489,7 +2916,15 @@ var WebRTCTransportProxyFactory = class {
2489
2916
  return this;
2490
2917
  }
2491
2918
  createTransport(options) {
2492
- (0, import_tiny_invariant12.default)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections");
2919
+ (0, import_invariant13.invariant)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections", {
2920
+ F: __dxlog_file14,
2921
+ L: 163,
2922
+ S: this,
2923
+ A: [
2924
+ "this._bridgeService",
2925
+ "'WebRTCTransportProxyFactory is not ready to open connections'"
2926
+ ]
2927
+ });
2493
2928
  const transport = new WebRTCTransportProxy({
2494
2929
  ...options,
2495
2930
  bridgeService: this._bridgeService