@dxos/network-manager 0.1.56-main.e47dfd1 → 0.1.56-main.e79d64a

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 (53) hide show
  1. package/dist/lib/browser/{chunk-5R7TDXUU.mjs → chunk-WQ3YXGWP.mjs} +702 -276
  2. package/dist/lib/browser/chunk-WQ3YXGWP.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 +23 -16
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +700 -274
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +648 -271
  11. package/dist/lib/node/testing/index.cjs.map +3 -3
  12. package/dist/types/src/connection-log.d.ts.map +1 -1
  13. package/dist/types/src/network-manager.d.ts.map +1 -1
  14. package/dist/types/src/signal/swarm-messenger.d.ts +1 -1
  15. package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
  16. package/dist/types/src/swarm/connection-limiter.d.ts +1 -1
  17. package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
  18. package/dist/types/src/swarm/connection.d.ts +2 -1
  19. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  20. package/dist/types/src/swarm/peer.d.ts +1 -1
  21. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  22. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  23. package/dist/types/src/testing/test-builder.d.ts +4 -3
  24. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  25. package/dist/types/src/testing/test-wire-protocol.d.ts +13 -2
  26. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
  27. package/dist/types/src/topology/fully-connected-topology.d.ts.map +1 -1
  28. package/dist/types/src/topology/star-topology.d.ts.map +1 -1
  29. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  30. package/dist/types/src/transport/webrtc-transport-proxy.d.ts +1 -1
  31. package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
  32. package/dist/types/src/transport/webrtc-transport-service.d.ts.map +1 -1
  33. package/dist/types/src/transport/webrtc-transport.d.ts +3 -3
  34. package/dist/types/src/transport/webrtc-transport.d.ts.map +1 -1
  35. package/package.json +18 -18
  36. package/src/connection-log.ts +2 -0
  37. package/src/network-manager.ts +1 -2
  38. package/src/signal/swarm-messenger.ts +3 -4
  39. package/src/swarm/connection-limiter.ts +3 -2
  40. package/src/swarm/connection.ts +29 -6
  41. package/src/swarm/peer.ts +32 -8
  42. package/src/swarm/swarm.ts +6 -7
  43. package/src/testing/test-builder.ts +9 -5
  44. package/src/testing/test-wire-protocol.ts +22 -2
  45. package/src/tests/memory-transport.test.ts +1 -1
  46. package/src/topology/fully-connected-topology.ts +1 -2
  47. package/src/topology/mmst-topology.ts +1 -1
  48. package/src/topology/star-topology.ts +1 -2
  49. package/src/transport/memory-transport.ts +1 -1
  50. package/src/transport/webrtc-transport-proxy.ts +18 -16
  51. package/src/transport/webrtc-transport-service.ts +31 -8
  52. package/src/transport/webrtc-transport.ts +21 -7
  53. 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: 96,
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: 121,
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: 122,
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: 123,
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: 140,
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: 144,
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,
@@ -187,6 +227,9 @@ var Connection = class {
187
227
  this.close().catch((err) => this.errors.raise(err));
188
228
  });
189
229
  this._transport.errors.handle((err) => {
230
+ if (!this.closeReason) {
231
+ this.closeReason = err?.message;
232
+ }
190
233
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
191
234
  this.errors.raise(err);
192
235
  }
@@ -199,13 +242,15 @@ var Connection = class {
199
242
  id: this._instanceId
200
243
  }), {
201
244
  F: __dxlog_file,
202
- L: 158,
245
+ L: 176,
203
246
  S: this,
204
247
  C: (f, a) => f(...a)
205
248
  });
206
249
  }
207
- async close() {
208
- var _a;
250
+ async close(err) {
251
+ if (!this.closeReason) {
252
+ this.closeReason = err?.message;
253
+ }
209
254
  if (this._state === ConnectionState.CLOSED) {
210
255
  return;
211
256
  }
@@ -215,26 +260,26 @@ var Connection = class {
215
260
  peerId: this.ownId
216
261
  }, {
217
262
  F: __dxlog_file,
218
- L: 170,
263
+ L: 191,
219
264
  S: this,
220
265
  C: (f, a) => f(...a)
221
266
  });
222
267
  try {
223
268
  await this._protocol.destroy();
224
- } catch (err) {
225
- import_log.log.catch(err, void 0, {
269
+ } catch (err2) {
270
+ import_log.log.catch(err2, void 0, {
226
271
  F: __dxlog_file,
227
- L: 176,
272
+ L: 197,
228
273
  S: this,
229
274
  C: (f, a) => f(...a)
230
275
  });
231
276
  }
232
277
  try {
233
- await ((_a = this._transport) == null ? void 0 : _a.destroy());
234
- } catch (err) {
235
- import_log.log.catch(err, void 0, {
278
+ await this._transport?.destroy();
279
+ } catch (err2) {
280
+ import_log.log.catch(err2, void 0, {
236
281
  F: __dxlog_file,
237
- L: 183,
282
+ L: 204,
238
283
  S: this,
239
284
  C: (f, a) => f(...a)
240
285
  });
@@ -243,7 +288,7 @@ var Connection = class {
243
288
  peerId: this.ownId
244
289
  }, {
245
290
  F: __dxlog_file,
246
- L: 186,
291
+ L: 207,
247
292
  S: this,
248
293
  C: (f, a) => f(...a)
249
294
  });
@@ -258,8 +303,10 @@ var Connection = class {
258
303
  return;
259
304
  }
260
305
  try {
261
- await (0, import_context.cancelWithContext)(this._ctx, (0, import_async.sleep)(this._signallingDelay));
262
- this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
306
+ if (process.env.NODE_ENV !== "test") {
307
+ await (0, import_context.cancelWithContext)(this._ctx, (0, import_async.sleep)(this._signallingDelay));
308
+ this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
309
+ }
263
310
  const signals = [
264
311
  ...this._outgoingSignalBuffer
265
312
  ];
@@ -283,7 +330,7 @@ var Connection = class {
283
330
  err
284
331
  }, {
285
332
  F: __dxlog_file,
286
- L: 220,
333
+ L: 243,
287
334
  S: this,
288
335
  C: (f, a) => f(...a)
289
336
  });
@@ -294,21 +341,52 @@ var Connection = class {
294
341
  * Receive a signal from the remote peer.
295
342
  */
296
343
  async signal(msg) {
297
- var _a, _b, _c;
298
- (0, import_tiny_invariant.default)(msg.sessionId);
344
+ (0, import_invariant.invariant)(msg.sessionId, void 0, {
345
+ F: __dxlog_file,
346
+ L: 252,
347
+ S: this,
348
+ A: [
349
+ "msg.sessionId",
350
+ ""
351
+ ]
352
+ });
299
353
  if (!msg.sessionId.equals(this.sessionId)) {
300
354
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
301
355
  F: __dxlog_file,
302
- L: 231,
356
+ L: 254,
303
357
  S: this,
304
358
  C: (f, a) => f(...a)
305
359
  });
306
360
  return;
307
361
  }
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));
311
- const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
362
+ (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
363
+ F: __dxlog_file,
364
+ L: 257,
365
+ S: this,
366
+ A: [
367
+ "msg.data.signal || msg.data.signalBatch",
368
+ ""
369
+ ]
370
+ });
371
+ (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
372
+ F: __dxlog_file,
373
+ L: 258,
374
+ S: this,
375
+ A: [
376
+ "msg.author?.equals(this.remoteId)",
377
+ ""
378
+ ]
379
+ });
380
+ (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
381
+ F: __dxlog_file,
382
+ L: 259,
383
+ S: this,
384
+ A: [
385
+ "msg.recipient?.equals(this.ownId)",
386
+ ""
387
+ ]
388
+ });
389
+ const signals = msg.data.signalBatch ? msg.data.signalBatch.signals ?? [] : [
312
390
  msg.data.signal
313
391
  ];
314
392
  for (const signal of signals) {
@@ -322,20 +400,28 @@ var Connection = class {
322
400
  msg: msg.data
323
401
  }, {
324
402
  F: __dxlog_file,
325
- L: 245,
403
+ L: 268,
326
404
  S: this,
327
405
  C: (f, a) => f(...a)
328
406
  });
329
407
  this._incomingSignalBuffer.push(signal);
330
408
  } else {
331
- (0, import_tiny_invariant.default)(this._transport, "Connection not ready to accept signals.");
409
+ (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
410
+ F: __dxlog_file,
411
+ L: 271,
412
+ S: this,
413
+ A: [
414
+ "this._transport",
415
+ "'Connection not ready to accept signals.'"
416
+ ]
417
+ });
332
418
  (0, import_log.log)("received signal", {
333
419
  peerId: this.ownId,
334
420
  remoteId: this.remoteId,
335
421
  msg: msg.data
336
422
  }, {
337
423
  F: __dxlog_file,
338
- L: 249,
424
+ L: 272,
339
425
  S: this,
340
426
  C: (f, a) => f(...a)
341
427
  });
@@ -350,11 +436,19 @@ var Connection = class {
350
436
  peerId: this.ownId
351
437
  }, {
352
438
  F: __dxlog_file,
353
- L: 256,
439
+ L: 279,
354
440
  S: this,
355
441
  C: (f, a) => f(...a)
356
442
  });
357
- (0, import_tiny_invariant.default)(state !== this._state, "Already in this state.");
443
+ (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
444
+ F: __dxlog_file,
445
+ L: 280,
446
+ S: this,
447
+ A: [
448
+ "state !== this._state",
449
+ "'Already in this state.'"
450
+ ]
451
+ });
358
452
  this._state = state;
359
453
  this.stateChanged.emit(state);
360
454
  }
@@ -364,18 +458,18 @@ _ts_decorate([
364
458
  ], Connection.prototype, "close", null);
365
459
 
366
460
  // packages/core/mesh/network-manager/src/swarm/swarm.ts
367
- var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
368
461
  var import_async3 = require("@dxos/async");
369
462
  var import_context4 = require("@dxos/context");
370
463
  var import_debug2 = require("@dxos/debug");
464
+ var import_invariant4 = require("@dxos/invariant");
371
465
  var import_keys4 = require("@dxos/keys");
372
466
  var import_log4 = require("@dxos/log");
373
467
  var import_protocols3 = require("@dxos/protocols");
374
468
  var import_util2 = require("@dxos/util");
375
469
 
376
470
  // packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
377
- var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
378
471
  var import_context2 = require("@dxos/context");
472
+ var import_invariant2 = require("@dxos/invariant");
379
473
  var import_keys2 = require("@dxos/keys");
380
474
  var import_log2 = require("@dxos/log");
381
475
  var import_protocols2 = require("@dxos/protocols");
@@ -392,7 +486,6 @@ var SwarmMessenger = class {
392
486
  this._topic = topic;
393
487
  }
394
488
  async receiveMessage({ author, recipient, payload }) {
395
- var _a, _b, _c, _d;
396
489
  if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
397
490
  return;
398
491
  }
@@ -406,25 +499,25 @@ var SwarmMessenger = class {
406
499
  msg: message
407
500
  }, {
408
501
  F: __dxlog_file2,
409
- L: 70,
502
+ L: 69,
410
503
  S: this,
411
504
  C: (f, a) => f(...a)
412
505
  });
413
- if ((_a = message.data) == null ? void 0 : _a.offer) {
506
+ if (message.data?.offer) {
414
507
  await this._handleOffer({
415
508
  author,
416
509
  recipient,
417
510
  message
418
511
  });
419
- } else if ((_b = message.data) == null ? void 0 : _b.answer) {
512
+ } else if (message.data?.answer) {
420
513
  await this._resolveAnswers(message);
421
- } else if ((_c = message.data) == null ? void 0 : _c.signal) {
514
+ } else if (message.data?.signal) {
422
515
  await this._handleSignal({
423
516
  author,
424
517
  recipient,
425
518
  message
426
519
  });
427
- } else if ((_d = message.data) == null ? void 0 : _d.signalBatch) {
520
+ } else if (message.data?.signalBatch) {
428
521
  await this._handleSignal({
429
522
  author,
430
523
  recipient,
@@ -435,15 +528,22 @@ var SwarmMessenger = class {
435
528
  message
436
529
  }, {
437
530
  F: __dxlog_file2,
438
- L: 81,
531
+ L: 80,
439
532
  S: this,
440
533
  C: (f, a) => f(...a)
441
534
  });
442
535
  }
443
536
  }
444
537
  async signal(message) {
445
- 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");
538
+ (0, import_invariant2.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
539
+ F: __dxlog_file2,
540
+ L: 85,
541
+ S: this,
542
+ A: [
543
+ "message.data?.signal || message.data?.signalBatch",
544
+ "'Invalid message'"
545
+ ]
546
+ });
447
547
  await this._sendReliableMessage({
448
548
  author: message.author,
449
549
  recipient: message.recipient,
@@ -467,11 +567,10 @@ var SwarmMessenger = class {
467
567
  });
468
568
  }
469
569
  async _sendReliableMessage({ author, recipient, message }) {
470
- var _a;
471
570
  const networkMessage = {
472
571
  ...message,
473
572
  // Setting unique message_id if it not specified yet.
474
- messageId: (_a = message.messageId) != null ? _a : import_keys2.PublicKey.random()
573
+ messageId: message.messageId ?? import_keys2.PublicKey.random()
475
574
  };
476
575
  (0, import_log2.log)("sending", {
477
576
  from: author,
@@ -479,7 +578,7 @@ var SwarmMessenger = class {
479
578
  msg: networkMessage
480
579
  }, {
481
580
  F: __dxlog_file2,
482
- L: 124,
581
+ L: 123,
483
582
  S: this,
484
583
  C: (f, a) => f(...a)
485
584
  });
@@ -493,17 +592,32 @@ var SwarmMessenger = class {
493
592
  });
494
593
  }
495
594
  async _resolveAnswers(message) {
496
- 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");
595
+ (0, import_invariant2.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
596
+ F: __dxlog_file2,
597
+ L: 135,
598
+ S: this,
599
+ A: [
600
+ "message.data?.answer?.offerMessageId",
601
+ "'No offerMessageId'"
602
+ ]
603
+ });
498
604
  const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
499
605
  if (offerRecord) {
500
606
  this._offerRecords.delete(message.data.answer.offerMessageId);
501
- (0, import_tiny_invariant2.default)((_c = message.data) == null ? void 0 : _c.answer, "No answer");
607
+ (0, import_invariant2.invariant)(message.data?.answer, "No answer", {
608
+ F: __dxlog_file2,
609
+ L: 139,
610
+ S: this,
611
+ A: [
612
+ "message.data?.answer",
613
+ "'No answer'"
614
+ ]
615
+ });
502
616
  (0, import_log2.log)("resolving", {
503
617
  answer: message.data.answer
504
618
  }, {
505
619
  F: __dxlog_file2,
506
- L: 141,
620
+ L: 140,
507
621
  S: this,
508
622
  C: (f, a) => f(...a)
509
623
  });
@@ -511,7 +625,15 @@ var SwarmMessenger = class {
511
625
  }
512
626
  }
513
627
  async _handleOffer({ author, recipient, message }) {
514
- (0, import_tiny_invariant2.default)(message.data.offer, "No offer");
628
+ (0, import_invariant2.invariant)(message.data.offer, "No offer", {
629
+ F: __dxlog_file2,
630
+ L: 154,
631
+ S: this,
632
+ A: [
633
+ "message.data.offer",
634
+ "'No offer'"
635
+ ]
636
+ });
515
637
  const offerMessage = {
516
638
  author,
517
639
  recipient,
@@ -539,15 +661,31 @@ var SwarmMessenger = class {
539
661
  err
540
662
  }, {
541
663
  F: __dxlog_file2,
542
- L: 175,
664
+ L: 174,
543
665
  S: this,
544
666
  C: (f, a) => f(...a)
545
667
  });
546
668
  }
547
669
  }
548
670
  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");
671
+ (0, import_invariant2.invariant)(message.messageId, void 0, {
672
+ F: __dxlog_file2,
673
+ L: 187,
674
+ S: this,
675
+ A: [
676
+ "message.messageId",
677
+ ""
678
+ ]
679
+ });
680
+ (0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
681
+ F: __dxlog_file2,
682
+ L: 188,
683
+ S: this,
684
+ A: [
685
+ "message.data.signal || message.data.signalBatch",
686
+ "'Invalid message'"
687
+ ]
688
+ });
551
689
  const signalMessage = {
552
690
  author,
553
691
  recipient,
@@ -562,10 +700,10 @@ var SwarmMessenger = class {
562
700
  };
563
701
 
564
702
  // packages/core/mesh/network-manager/src/swarm/peer.ts
565
- var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
566
703
  var import_async2 = require("@dxos/async");
567
704
  var import_context3 = require("@dxos/context");
568
705
  var import_errors2 = require("@dxos/errors");
706
+ var import_invariant3 = require("@dxos/invariant");
569
707
  var import_keys3 = require("@dxos/keys");
570
708
  var import_log3 = require("@dxos/log");
571
709
  function _ts_decorate2(decorators, target, key, desc) {
@@ -581,6 +719,7 @@ function _ts_decorate2(decorators, target, key, desc) {
581
719
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
582
720
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
583
721
  var Peer = class {
722
+ // TODO(burdon): Convert to map?
584
723
  constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
585
724
  this.id = id;
586
725
  this.topic = topic;
@@ -600,7 +739,6 @@ var Peer = class {
600
739
  * Respond to remote offer.
601
740
  */
602
741
  async onOffer(message) {
603
- var _a;
604
742
  const remoteId = message.author;
605
743
  if (this.connection || this.initiating) {
606
744
  if (remoteId.toHex() < this.localPeerId.toHex()) {
@@ -608,15 +746,15 @@ var Peer = class {
608
746
  localPeerId: this.id,
609
747
  topic: this.topic,
610
748
  remotePeerId: this.localPeerId,
611
- sessionId: (_a = this.connection) == null ? void 0 : _a.sessionId
749
+ sessionId: this.connection?.sessionId
612
750
  }, {
613
751
  F: __dxlog_file3,
614
- L: 107,
752
+ L: 108,
615
753
  S: this,
616
754
  C: (f, a) => f(...a)
617
755
  });
618
756
  if (this.connection) {
619
- await this.closeConnection();
757
+ await this.closeConnection(new Error("Connection displaced by remote initiator."));
620
758
  }
621
759
  } else {
622
760
  return {
@@ -626,7 +764,15 @@ var Peer = class {
626
764
  }
627
765
  if (await this._callbacks.onOffer(remoteId)) {
628
766
  if (!this.connection) {
629
- (0, import_tiny_invariant3.default)(message.sessionId);
767
+ (0, import_invariant3.invariant)(message.sessionId, void 0, {
768
+ F: __dxlog_file3,
769
+ L: 128,
770
+ S: this,
771
+ A: [
772
+ "message.sessionId",
773
+ ""
774
+ ]
775
+ });
630
776
  const connection = this._createConnection(false, message.sessionId);
631
777
  try {
632
778
  await this._connectionLimiter.connecting(message.sessionId);
@@ -640,12 +786,12 @@ var Peer = class {
640
786
  err
641
787
  }, {
642
788
  F: __dxlog_file3,
643
- L: 135,
789
+ L: 136,
644
790
  S: this,
645
791
  C: (f, a) => f(...a)
646
792
  });
647
793
  }
648
- await this.closeConnection();
794
+ await this.closeConnection(err);
649
795
  }
650
796
  return {
651
797
  accept: true
@@ -660,8 +806,24 @@ var Peer = class {
660
806
  * Initiate a connection to the remote peer.
661
807
  */
662
808
  async initiateConnection() {
663
- (0, import_tiny_invariant3.default)(!this.initiating, "Initiation in progress.");
664
- (0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
809
+ (0, import_invariant3.invariant)(!this.initiating, "Initiation in progress.", {
810
+ F: __dxlog_file3,
811
+ L: 153,
812
+ S: this,
813
+ A: [
814
+ "!this.initiating",
815
+ "'Initiation in progress.'"
816
+ ]
817
+ });
818
+ (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
819
+ F: __dxlog_file3,
820
+ L: 154,
821
+ S: this,
822
+ A: [
823
+ "!this.connection",
824
+ "'Already connected.'"
825
+ ]
826
+ });
665
827
  const sessionId = import_keys3.PublicKey.random();
666
828
  (0, import_log3.log)("initiating...", {
667
829
  id: this.id,
@@ -670,7 +832,7 @@ var Peer = class {
670
832
  sessionId
671
833
  }, {
672
834
  F: __dxlog_file3,
673
- L: 155,
835
+ L: 156,
674
836
  S: this,
675
837
  C: (f, a) => f(...a)
676
838
  });
@@ -694,14 +856,14 @@ var Peer = class {
694
856
  remoteId: this.id
695
857
  }, {
696
858
  F: __dxlog_file3,
697
- L: 170,
859
+ L: 171,
698
860
  S: this,
699
861
  C: (f, a) => f(...a)
700
862
  });
701
863
  if (connection.state !== ConnectionState.INITIAL) {
702
864
  (0, import_log3.log)("ignoring response", void 0, {
703
865
  F: __dxlog_file3,
704
- L: 172,
866
+ L: 173,
705
867
  S: this,
706
868
  C: (f, a) => f(...a)
707
869
  });
@@ -721,11 +883,11 @@ var Peer = class {
721
883
  remoteId: this.id
722
884
  }, {
723
885
  F: __dxlog_file3,
724
- L: 183,
886
+ L: 184,
725
887
  S: this,
726
888
  C: (f, a) => f(...a)
727
889
  });
728
- await this.closeConnection();
890
+ await this.closeConnection(err);
729
891
  throw err;
730
892
  } finally {
731
893
  this.initiating = false;
@@ -736,7 +898,6 @@ var Peer = class {
736
898
  * Either we're initiating a connection or creating one in response to an offer from the other peer.
737
899
  */
738
900
  _createConnection(initiator, sessionId) {
739
- var _a;
740
901
  (0, import_log3.log)("creating connection", {
741
902
  topic: this.topic,
742
903
  peerId: this.localPeerId,
@@ -745,11 +906,19 @@ var Peer = class {
745
906
  sessionId
746
907
  }, {
747
908
  F: __dxlog_file3,
748
- L: 197,
909
+ L: 198,
749
910
  S: this,
750
911
  C: (f, a) => f(...a)
751
912
  });
752
- (0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
913
+ (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
914
+ F: __dxlog_file3,
915
+ L: 205,
916
+ S: this,
917
+ A: [
918
+ "!this.connection",
919
+ "'Already connected.'"
920
+ ]
921
+ });
753
922
  const connection = new Connection(
754
923
  this.topic,
755
924
  this.localPeerId,
@@ -767,7 +936,7 @@ var Peer = class {
767
936
  this._transportFactory
768
937
  );
769
938
  this._callbacks.onInitiated(connection);
770
- void ((_a = this._connectionCtx) == null ? void 0 : _a.dispose());
939
+ void this._connectionCtx?.dispose();
771
940
  this._connectionCtx = this._ctx.derive();
772
941
  connection.stateChanged.on((state) => {
773
942
  switch (state) {
@@ -776,6 +945,18 @@ var Peer = class {
776
945
  this._lastConnectionTime = Date.now();
777
946
  this._callbacks.onConnected();
778
947
  this._connectionLimiter.doneConnecting(sessionId);
948
+ import_log3.log.trace("dxos.mesh.connection.connected", {
949
+ topic: this.topic,
950
+ localPeerId: this.localPeerId,
951
+ remotePeerId: this.id,
952
+ sessionId,
953
+ initiator
954
+ }, {
955
+ F: __dxlog_file3,
956
+ L: 231,
957
+ S: this,
958
+ C: (f, a) => f(...a)
959
+ });
779
960
  break;
780
961
  }
781
962
  case ConnectionState.CLOSED: {
@@ -786,11 +967,31 @@ var Peer = class {
786
967
  initiator
787
968
  }, {
788
969
  F: __dxlog_file3,
789
- L: 234,
970
+ L: 242,
971
+ S: this,
972
+ C: (f, a) => f(...a)
973
+ });
974
+ (0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
975
+ F: __dxlog_file3,
976
+ L: 243,
977
+ S: this,
978
+ A: [
979
+ "this.connection === connection",
980
+ "'Connection mismatch (race condition).'"
981
+ ]
982
+ });
983
+ import_log3.log.trace("dxos.mesh.connection.closed", {
984
+ topic: this.topic,
985
+ localPeerId: this.localPeerId,
986
+ remotePeerId: this.id,
987
+ sessionId,
988
+ initiator
989
+ }, {
990
+ F: __dxlog_file3,
991
+ L: 245,
790
992
  S: this,
791
993
  C: (f, a) => f(...a)
792
994
  });
793
- (0, import_tiny_invariant3.default)(this.connection === connection, "Connection mismatch (race condition).");
794
995
  if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
795
996
  this._availableAfter = 0;
796
997
  } else {
@@ -817,16 +1018,29 @@ var Peer = class {
817
1018
  err
818
1019
  }, {
819
1020
  F: __dxlog_file3,
820
- L: 263,
1021
+ L: 279,
821
1022
  S: this,
822
1023
  C: (f, a) => f(...a)
823
1024
  });
824
- void this.closeConnection();
1025
+ import_log3.log.trace("dxos.mesh.connection.error", {
1026
+ topic: this.topic,
1027
+ localPeerId: this.localPeerId,
1028
+ remotePeerId: this.id,
1029
+ sessionId,
1030
+ initiator,
1031
+ err
1032
+ }, {
1033
+ F: __dxlog_file3,
1034
+ L: 280,
1035
+ S: this,
1036
+ C: (f, a) => f(...a)
1037
+ });
1038
+ void this.closeConnection(err);
825
1039
  });
826
1040
  this.connection = connection;
827
1041
  return connection;
828
1042
  }
829
- async closeConnection() {
1043
+ async closeConnection(err) {
830
1044
  if (!this.connection) {
831
1045
  return;
832
1046
  }
@@ -836,17 +1050,17 @@ var Peer = class {
836
1050
  sessionId: connection.sessionId
837
1051
  }, {
838
1052
  F: __dxlog_file3,
839
- L: 279,
1053
+ L: 303,
840
1054
  S: this,
841
1055
  C: (f, a) => f(...a)
842
1056
  });
843
- await connection.close();
1057
+ await connection.close(err);
844
1058
  (0, import_log3.log)("closed", {
845
1059
  peerId: this.id,
846
1060
  sessionId: connection.sessionId
847
1061
  }, {
848
1062
  F: __dxlog_file3,
849
- L: 285,
1063
+ L: 309,
850
1064
  S: this,
851
1065
  C: (f, a) => f(...a)
852
1066
  });
@@ -857,7 +1071,7 @@ var Peer = class {
857
1071
  message
858
1072
  }, {
859
1073
  F: __dxlog_file3,
860
- L: 290,
1074
+ L: 314,
861
1075
  S: this,
862
1076
  C: (f, a) => f(...a)
863
1077
  });
@@ -866,18 +1080,17 @@ var Peer = class {
866
1080
  await this.connection.signal(message);
867
1081
  }
868
1082
  async destroy() {
869
- var _a;
870
1083
  await this._ctx.dispose();
871
1084
  (0, import_log3.log)("Destroying peer", {
872
1085
  peerId: this.id,
873
1086
  topic: this.topic
874
1087
  }, {
875
1088
  F: __dxlog_file3,
876
- L: 300,
1089
+ L: 324,
877
1090
  S: this,
878
1091
  C: (f, a) => f(...a)
879
1092
  });
880
- await ((_a = this == null ? void 0 : this.connection) == null ? void 0 : _a.close());
1093
+ await this?.connection?.close();
881
1094
  }
882
1095
  };
883
1096
  _ts_decorate2([
@@ -922,9 +1135,9 @@ var Swarm = class {
922
1135
  this._transportFactory = _transportFactory;
923
1136
  this._label = _label;
924
1137
  this._connectionLimiter = _connectionLimiter;
925
- this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
926
1138
  this._ctx = new import_context4.Context();
927
1139
  this._listeningHandle = void 0;
1140
+ this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
928
1141
  this._instanceId = import_keys4.PublicKey.random().toHex();
929
1142
  this.connectionAdded = new import_async3.Event();
930
1143
  this.disconnected = new import_async3.Event();
@@ -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
  }));
@@ -999,27 +1220,34 @@ var Swarm = class {
999
1220
  });
1000
1221
  }
1001
1222
  async destroy() {
1002
- var _a;
1003
1223
  (0, import_log4.log)("destroying...", void 0, {
1004
1224
  F: __dxlog_file4,
1005
- L: 141,
1225
+ L: 140,
1006
1226
  S: this,
1007
1227
  C: (f, a) => f(...a)
1008
1228
  });
1009
- await ((_a = this._listeningHandle) == null ? void 0 : _a.unsubscribe());
1229
+ await this._listeningHandle?.unsubscribe();
1010
1230
  this._listeningHandle = void 0;
1011
1231
  await this._ctx.dispose();
1012
1232
  await this._topology.destroy();
1013
1233
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
1014
1234
  (0, import_log4.log)("destroyed", void 0, {
1015
1235
  F: __dxlog_file4,
1016
- L: 148,
1236
+ L: 147,
1017
1237
  S: this,
1018
1238
  C: (f, a) => f(...a)
1019
1239
  });
1020
1240
  }
1021
1241
  async setTopology(topology) {
1022
- (0, import_tiny_invariant4.default)(!this._ctx.disposed, "Swarm is offline");
1242
+ (0, import_invariant4.invariant)(!this._ctx.disposed, "Swarm is offline", {
1243
+ F: __dxlog_file4,
1244
+ L: 151,
1245
+ S: this,
1246
+ A: [
1247
+ "!this._ctx.disposed",
1248
+ "'Swarm is offline'"
1249
+ ]
1250
+ });
1023
1251
  if (topology === this._topology) {
1024
1252
  return;
1025
1253
  }
@@ -1028,7 +1256,7 @@ var Swarm = class {
1028
1256
  topology: getClassName(topology)
1029
1257
  }, {
1030
1258
  F: __dxlog_file4,
1031
- L: 156,
1259
+ L: 155,
1032
1260
  S: this,
1033
1261
  C: (f, a) => f(...a)
1034
1262
  });
@@ -1038,19 +1266,18 @@ var Swarm = class {
1038
1266
  this._topology.update();
1039
1267
  }
1040
1268
  onSwarmEvent(swarmEvent) {
1041
- var _a;
1042
1269
  (0, import_log4.log)("swarm event", {
1043
1270
  swarmEvent
1044
1271
  }, {
1045
1272
  F: __dxlog_file4,
1046
- L: 169,
1273
+ L: 168,
1047
1274
  S: this,
1048
1275
  C: (f, a) => f(...a)
1049
1276
  });
1050
1277
  if (this._ctx.disposed) {
1051
1278
  (0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
1052
1279
  F: __dxlog_file4,
1053
- L: 172,
1280
+ L: 171,
1054
1281
  S: this,
1055
1282
  C: (f, a) => f(...a)
1056
1283
  });
@@ -1062,7 +1289,7 @@ var Swarm = class {
1062
1289
  peerId
1063
1290
  }, {
1064
1291
  F: __dxlog_file4,
1065
- L: 178,
1292
+ L: 177,
1066
1293
  S: this,
1067
1294
  C: (f, a) => f(...a)
1068
1295
  });
@@ -1074,10 +1301,10 @@ var Swarm = class {
1074
1301
  const peer = this._peers.get(import_keys4.PublicKey.from(swarmEvent.peerLeft.peer));
1075
1302
  if (peer) {
1076
1303
  peer.advertizing = false;
1077
- if (((_a = peer.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
1304
+ if (peer.connection?.state !== ConnectionState.CONNECTED) {
1078
1305
  void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
1079
1306
  F: __dxlog_file4,
1080
- L: 189,
1307
+ L: 188,
1081
1308
  S: this,
1082
1309
  C: (f, a) => f(...a)
1083
1310
  }));
@@ -1087,19 +1314,18 @@ var Swarm = class {
1087
1314
  this._topology.update();
1088
1315
  }
1089
1316
  async onOffer(message) {
1090
- var _a, _b;
1091
1317
  (0, import_log4.log)("offer", {
1092
1318
  message
1093
1319
  }, {
1094
1320
  F: __dxlog_file4,
1095
- L: 199,
1321
+ L: 198,
1096
1322
  S: this,
1097
1323
  C: (f, a) => f(...a)
1098
1324
  });
1099
1325
  if (this._ctx.disposed) {
1100
1326
  (0, import_log4.log)("ignored for disposed swarm", void 0, {
1101
1327
  F: __dxlog_file4,
1102
- L: 201,
1328
+ L: 200,
1103
1329
  S: this,
1104
1330
  C: (f, a) => f(...a)
1105
1331
  });
@@ -1107,13 +1333,21 @@ var Swarm = class {
1107
1333
  accept: false
1108
1334
  };
1109
1335
  }
1110
- (0, import_tiny_invariant4.default)(message.author);
1111
- if (!((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId))) {
1336
+ (0, import_invariant4.invariant)(message.author, void 0, {
1337
+ F: __dxlog_file4,
1338
+ L: 205,
1339
+ S: this,
1340
+ A: [
1341
+ "message.author",
1342
+ ""
1343
+ ]
1344
+ });
1345
+ if (!message.recipient?.equals(this._ownPeerId)) {
1112
1346
  (0, import_log4.log)("rejecting offer with incorrect peerId", {
1113
1347
  message
1114
1348
  }, {
1115
1349
  F: __dxlog_file4,
1116
- L: 208,
1350
+ L: 207,
1117
1351
  S: this,
1118
1352
  C: (f, a) => f(...a)
1119
1353
  });
@@ -1121,12 +1355,12 @@ var Swarm = class {
1121
1355
  accept: false
1122
1356
  };
1123
1357
  }
1124
- if (!((_b = message.topic) == null ? void 0 : _b.equals(this._topic))) {
1358
+ if (!message.topic?.equals(this._topic)) {
1125
1359
  (0, import_log4.log)("rejecting offer with incorrect topic", {
1126
1360
  message
1127
1361
  }, {
1128
1362
  F: __dxlog_file4,
1129
- L: 212,
1363
+ L: 211,
1130
1364
  S: this,
1131
1365
  C: (f, a) => f(...a)
1132
1366
  });
@@ -1140,27 +1374,50 @@ var Swarm = class {
1140
1374
  return answer;
1141
1375
  }
1142
1376
  async onSignal(message) {
1143
- var _a, _b;
1144
1377
  (0, import_log4.log)("signal", {
1145
1378
  message
1146
1379
  }, {
1147
1380
  F: __dxlog_file4,
1148
- L: 223,
1381
+ L: 222,
1149
1382
  S: this,
1150
1383
  C: (f, a) => f(...a)
1151
1384
  });
1152
1385
  if (this._ctx.disposed) {
1153
1386
  import_log4.log.info("ignored for offline swarm", void 0, {
1154
1387
  F: __dxlog_file4,
1155
- L: 225,
1388
+ L: 224,
1156
1389
  S: this,
1157
1390
  C: (f, a) => f(...a)
1158
1391
  });
1159
1392
  return;
1160
1393
  }
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);
1394
+ (0, import_invariant4.invariant)(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1395
+ F: __dxlog_file4,
1396
+ L: 227,
1397
+ S: this,
1398
+ A: [
1399
+ "message.recipient?.equals(this._ownPeerId)",
1400
+ "`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
1401
+ ]
1402
+ });
1403
+ (0, import_invariant4.invariant)(message.topic?.equals(this._topic), void 0, {
1404
+ F: __dxlog_file4,
1405
+ L: 231,
1406
+ S: this,
1407
+ A: [
1408
+ "message.topic?.equals(this._topic)",
1409
+ ""
1410
+ ]
1411
+ });
1412
+ (0, import_invariant4.invariant)(message.author, void 0, {
1413
+ F: __dxlog_file4,
1414
+ L: 232,
1415
+ S: this,
1416
+ A: [
1417
+ "message.author",
1418
+ ""
1419
+ ]
1420
+ });
1164
1421
  const peer = this._getOrCreatePeer(message.author);
1165
1422
  await peer.onSignal(message);
1166
1423
  }
@@ -1212,7 +1469,15 @@ var Swarm = class {
1212
1469
  return peer;
1213
1470
  }
1214
1471
  async _destroyPeer(peerId) {
1215
- (0, import_tiny_invariant4.default)(this._peers.has(peerId));
1472
+ (0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
1473
+ F: __dxlog_file4,
1474
+ L: 302,
1475
+ S: this,
1476
+ A: [
1477
+ "this._peers.has(peerId)",
1478
+ ""
1479
+ ]
1480
+ });
1216
1481
  await this._peers.get(peerId).destroy();
1217
1482
  this._peers.delete(peerId);
1218
1483
  }
@@ -1233,7 +1498,7 @@ var Swarm = class {
1233
1498
  } catch (err) {
1234
1499
  (0, import_log4.log)("initiation error", err, {
1235
1500
  F: __dxlog_file4,
1236
- L: 329,
1501
+ L: 328,
1237
1502
  S: this,
1238
1503
  C: (f, a) => f(...a)
1239
1504
  });
@@ -1261,7 +1526,7 @@ var Swarm = class {
1261
1526
  remoteId
1262
1527
  }, {
1263
1528
  F: __dxlog_file4,
1264
- L: 356,
1529
+ L: 355,
1265
1530
  S: this,
1266
1531
  C: (f, a) => f(...a)
1267
1532
  });
@@ -1278,7 +1543,7 @@ var Swarm = class {
1278
1543
  remoteId
1279
1544
  }, {
1280
1545
  F: __dxlog_file4,
1281
- L: 370,
1546
+ L: 369,
1282
1547
  S: this,
1283
1548
  C: (f, a) => f(...a)
1284
1549
  });
@@ -1288,7 +1553,7 @@ var Swarm = class {
1288
1553
  remoteId
1289
1554
  }, {
1290
1555
  F: __dxlog_file4,
1291
- L: 373,
1556
+ L: 372,
1292
1557
  S: this,
1293
1558
  C: (f, a) => f(...a)
1294
1559
  });
@@ -1347,8 +1612,7 @@ var SwarmMapper = class {
1347
1612
  }));
1348
1613
  }));
1349
1614
  this._subscriptions.add(_swarm.disconnected.on((peerId) => {
1350
- var _a;
1351
- (_a = this._connectionSubscriptions.get(peerId)) == null ? void 0 : _a();
1615
+ this._connectionSubscriptions.get(peerId)?.();
1352
1616
  this._connectionSubscriptions.delete(peerId);
1353
1617
  this._update();
1354
1618
  }));
@@ -1398,11 +1662,12 @@ var SwarmMapper = class {
1398
1662
  var import_async5 = require("@dxos/async");
1399
1663
  var import_context5 = require("@dxos/context");
1400
1664
  var import_errors3 = require("@dxos/errors");
1665
+ var import_invariant5 = require("@dxos/invariant");
1401
1666
  var import_keys6 = require("@dxos/keys");
1402
1667
  var import_log6 = require("@dxos/log");
1403
1668
  var import_util4 = require("@dxos/util");
1404
1669
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1405
- var MAX_CONCURRENT_INITIATING_CONNECTIONS = 3;
1670
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
1406
1671
  var ConnectionLimiter = class {
1407
1672
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
1408
1673
  this._ctx = new import_context5.Context();
@@ -1421,9 +1686,9 @@ var ConnectionLimiter = class {
1421
1686
  * @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
1422
1687
  */
1423
1688
  async connecting(sessionId) {
1424
- (0, import_log6.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
1689
+ (0, import_invariant5.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
1425
1690
  F: __dxlog_file6,
1426
- L: 47,
1691
+ L: 48,
1427
1692
  S: this,
1428
1693
  A: [
1429
1694
  "!this._waitingPromises.has(sessionId)",
@@ -1434,7 +1699,7 @@ var ConnectionLimiter = class {
1434
1699
  sessionId
1435
1700
  }, {
1436
1701
  F: __dxlog_file6,
1437
- L: 48,
1702
+ L: 49,
1438
1703
  S: this,
1439
1704
  C: (f, a) => f(...a)
1440
1705
  });
@@ -1449,7 +1714,7 @@ var ConnectionLimiter = class {
1449
1714
  sessionId
1450
1715
  }, {
1451
1716
  F: __dxlog_file6,
1452
- L: 56,
1717
+ L: 57,
1453
1718
  S: this,
1454
1719
  C: (f, a) => f(...a)
1455
1720
  });
@@ -1462,7 +1727,7 @@ var ConnectionLimiter = class {
1462
1727
  sessionId
1463
1728
  }, {
1464
1729
  F: __dxlog_file6,
1465
- L: 63,
1730
+ L: 64,
1466
1731
  S: this,
1467
1732
  C: (f, a) => f(...a)
1468
1733
  });
@@ -1493,8 +1758,7 @@ var ConnectionLog = class {
1493
1758
  this.update = new import_async6.Event();
1494
1759
  }
1495
1760
  getSwarmInfo(swarmId) {
1496
- var _a;
1497
- return (_a = this._swarms.get(swarmId)) != null ? _a : (0, import_debug3.raise)(new Error(`Swarm not found: ${swarmId}`));
1761
+ return this._swarms.get(swarmId) ?? (0, import_debug3.raise)(new Error(`Swarm not found: ${swarmId}`));
1498
1762
  }
1499
1763
  get swarms() {
1500
1764
  return Array.from(this._swarms.values());
@@ -1510,9 +1774,9 @@ var ConnectionLog = class {
1510
1774
  this._swarms.set(import_keys7.PublicKey.from(swarm._instanceId), info);
1511
1775
  this.update.emit();
1512
1776
  swarm.connectionAdded.on((connection) => {
1513
- var _a, _b;
1514
1777
  const connectionInfo = {
1515
1778
  state: ConnectionState.INITIAL,
1779
+ closeReason: connection.closeReason,
1516
1780
  remotePeerId: connection.remoteId,
1517
1781
  sessionId: connection.sessionId,
1518
1782
  transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
@@ -1523,13 +1787,14 @@ var ConnectionLog = class {
1523
1787
  this.update.emit();
1524
1788
  connection.stateChanged.on((state) => {
1525
1789
  connectionInfo.state = state;
1790
+ connectionInfo.closeReason = connection.closeReason;
1526
1791
  connectionInfo.events.push({
1527
1792
  type: EventType.CONNECTION_STATE_CHANGED,
1528
1793
  newState: state
1529
1794
  });
1530
1795
  this.update.emit();
1531
1796
  });
1532
- (_b = (_a = connection.protocol) == null ? void 0 : _a.stats) == null ? void 0 : _b.on((stats) => {
1797
+ connection.protocol?.stats?.on((stats) => {
1533
1798
  connectionInfo.streams = stats.channels;
1534
1799
  this.update.emit();
1535
1800
  });
@@ -1542,8 +1807,8 @@ var ConnectionLog = class {
1542
1807
  };
1543
1808
 
1544
1809
  // packages/core/mesh/network-manager/src/network-manager.ts
1545
- var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
1546
1810
  var import_async7 = require("@dxos/async");
1811
+ var import_invariant6 = require("@dxos/invariant");
1547
1812
  var import_keys8 = require("@dxos/keys");
1548
1813
  var import_log7 = require("@dxos/log");
1549
1814
  var import_messaging = require("@dxos/messaging");
@@ -1564,10 +1829,7 @@ var NetworkManager = class {
1564
1829
  this._instanceId = import_keys8.PublicKey.random().toHex();
1565
1830
  this._transportFactory = transportFactory;
1566
1831
  this._signalManager = signalManager;
1567
- this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => {
1568
- var _a;
1569
- return (_a = this._swarms.get(topic)) == null ? void 0 : _a.onSwarmEvent(event);
1570
- });
1832
+ this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => this._swarms.get(topic)?.onSwarmEvent(event));
1571
1833
  this._messenger = new import_messaging.Messenger({
1572
1834
  signalManager: this._signalManager
1573
1835
  });
@@ -1602,7 +1864,7 @@ var NetworkManager = class {
1602
1864
  id: this._instanceId
1603
1865
  }), {
1604
1866
  F: __dxlog_file7,
1605
- L: 131,
1867
+ L: 130,
1606
1868
  S: this,
1607
1869
  C: (f, a) => f(...a)
1608
1870
  });
@@ -1612,7 +1874,7 @@ var NetworkManager = class {
1612
1874
  id: this._instanceId
1613
1875
  }), {
1614
1876
  F: __dxlog_file7,
1615
- L: 134,
1877
+ L: 133,
1616
1878
  S: this,
1617
1879
  C: (f, a) => f(...a)
1618
1880
  });
@@ -1622,7 +1884,7 @@ var NetworkManager = class {
1622
1884
  await this.leaveSwarm(topic).catch((err) => {
1623
1885
  (0, import_log7.log)(err, void 0, {
1624
1886
  F: __dxlog_file7,
1625
- L: 140,
1887
+ L: 139,
1626
1888
  S: this,
1627
1889
  C: (f, a) => f(...a)
1628
1890
  });
@@ -1635,11 +1897,42 @@ var NetworkManager = class {
1635
1897
  * Join the swarm.
1636
1898
  */
1637
1899
  async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
1638
- 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");
1900
+ (0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(topic), void 0, {
1901
+ F: __dxlog_file7,
1902
+ L: 157,
1903
+ S: this,
1904
+ A: [
1905
+ "PublicKey.isPublicKey(topic)",
1906
+ ""
1907
+ ]
1908
+ });
1909
+ (0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(peerId), void 0, {
1910
+ F: __dxlog_file7,
1911
+ L: 158,
1912
+ S: this,
1913
+ A: [
1914
+ "PublicKey.isPublicKey(peerId)",
1915
+ ""
1916
+ ]
1917
+ });
1918
+ (0, import_invariant6.invariant)(topology, void 0, {
1919
+ F: __dxlog_file7,
1920
+ L: 159,
1921
+ S: this,
1922
+ A: [
1923
+ "topology",
1924
+ ""
1925
+ ]
1926
+ });
1927
+ (0, import_invariant6.invariant)(typeof protocol === "function", void 0, {
1928
+ F: __dxlog_file7,
1929
+ L: 160,
1930
+ S: this,
1931
+ A: [
1932
+ "typeof protocol === 'function'",
1933
+ ""
1934
+ ]
1935
+ });
1643
1936
  if (this._swarms.has(topic)) {
1644
1937
  throw new Error(`Already connected to swarm: ${import_keys8.PublicKey.from(topic)}`);
1645
1938
  }
@@ -1649,7 +1942,7 @@ var NetworkManager = class {
1649
1942
  topology: topology.toString()
1650
1943
  }, {
1651
1944
  F: __dxlog_file7,
1652
- L: 166,
1945
+ L: 165,
1653
1946
  S: this,
1654
1947
  C: (f, a) => f(...a)
1655
1948
  });
@@ -1659,7 +1952,7 @@ var NetworkManager = class {
1659
1952
  error
1660
1953
  }, {
1661
1954
  F: __dxlog_file7,
1662
- L: 179,
1955
+ L: 178,
1663
1956
  S: this,
1664
1957
  C: (f, a) => f(...a)
1665
1958
  });
@@ -1672,18 +1965,18 @@ var NetworkManager = class {
1672
1965
  peerId
1673
1966
  }).catch((error) => import_log7.log.catch(error, void 0, {
1674
1967
  F: __dxlog_file7,
1675
- L: 188,
1968
+ L: 187,
1676
1969
  S: this,
1677
1970
  C: (f, a) => f(...a)
1678
1971
  }));
1679
1972
  this.topicsUpdated.emit();
1680
- (_a = this._connectionLog) == null ? void 0 : _a.joinedSwarm(swarm);
1973
+ this._connectionLog?.joinedSwarm(swarm);
1681
1974
  (0, import_log7.log)("joined", {
1682
1975
  topic: import_keys8.PublicKey.from(topic),
1683
1976
  count: this._swarms.size
1684
1977
  }, {
1685
1978
  F: __dxlog_file7,
1686
- L: 192,
1979
+ L: 191,
1687
1980
  S: this,
1688
1981
  C: (f, a) => f(...a)
1689
1982
  });
@@ -1695,7 +1988,6 @@ var NetworkManager = class {
1695
1988
  * Close the connection.
1696
1989
  */
1697
1990
  async leaveSwarm(topic) {
1698
- var _a;
1699
1991
  if (!this._swarms.has(topic)) {
1700
1992
  return;
1701
1993
  }
@@ -1703,7 +1995,7 @@ var NetworkManager = class {
1703
1995
  topic: import_keys8.PublicKey.from(topic)
1704
1996
  }, {
1705
1997
  F: __dxlog_file7,
1706
- L: 208,
1998
+ L: 207,
1707
1999
  S: this,
1708
2000
  C: (f, a) => f(...a)
1709
2001
  });
@@ -1715,7 +2007,7 @@ var NetworkManager = class {
1715
2007
  const map = this._mappers.get(topic);
1716
2008
  map.destroy();
1717
2009
  this._mappers.delete(topic);
1718
- (_a = this._connectionLog) == null ? void 0 : _a.leftSwarm(swarm);
2010
+ this._connectionLog?.leftSwarm(swarm);
1719
2011
  await swarm.destroy();
1720
2012
  this._swarms.delete(topic);
1721
2013
  await this.topicsUpdated.emit();
@@ -1724,7 +2016,7 @@ var NetworkManager = class {
1724
2016
  count: this._swarms.size
1725
2017
  }, {
1726
2018
  F: __dxlog_file7,
1727
- L: 222,
2019
+ L: 221,
1728
2020
  S: this,
1729
2021
  C: (f, a) => f(...a)
1730
2022
  });
@@ -1758,17 +2050,34 @@ var NetworkManager = class {
1758
2050
  };
1759
2051
 
1760
2052
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
1761
- var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
2053
+ var import_invariant7 = require("@dxos/invariant");
2054
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
1762
2055
  var FullyConnectedTopology = class {
1763
2056
  toString() {
1764
2057
  return "FullyConnectedTopology";
1765
2058
  }
1766
2059
  init(controller) {
1767
- (0, import_tiny_invariant6.default)(!this._controller, "Already initialized");
2060
+ (0, import_invariant7.invariant)(!this._controller, "Already initialized", {
2061
+ F: __dxlog_file8,
2062
+ L: 18,
2063
+ S: this,
2064
+ A: [
2065
+ "!this._controller",
2066
+ "'Already initialized'"
2067
+ ]
2068
+ });
1768
2069
  this._controller = controller;
1769
2070
  }
1770
2071
  update() {
1771
- (0, import_tiny_invariant6.default)(this._controller, "Not initialized");
2072
+ (0, import_invariant7.invariant)(this._controller, "Not initialized", {
2073
+ F: __dxlog_file8,
2074
+ L: 23,
2075
+ S: this,
2076
+ A: [
2077
+ "this._controller",
2078
+ "'Not initialized'"
2079
+ ]
2080
+ });
1772
2081
  const { candidates: discovered } = this._controller.getState();
1773
2082
  for (const peer of discovered) {
1774
2083
  this._controller.connect(peer);
@@ -1782,10 +2091,10 @@ var FullyConnectedTopology = class {
1782
2091
  };
1783
2092
 
1784
2093
  // packages/core/mesh/network-manager/src/topology/mmst-topology.ts
1785
- var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
1786
2094
  var import_xor_distance = __toESM(require("xor-distance"));
2095
+ var import_invariant8 = require("@dxos/invariant");
1787
2096
  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";
2097
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
1789
2098
  var MMSTTopology = class {
1790
2099
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
1791
2100
  this._sampleCollected = false;
@@ -1794,15 +2103,31 @@ var MMSTTopology = class {
1794
2103
  this._sampleSize = sampleSize;
1795
2104
  }
1796
2105
  init(controller) {
1797
- (0, import_tiny_invariant7.default)(!this._controller, "Already initialized");
2106
+ (0, import_invariant8.invariant)(!this._controller, "Already initialized", {
2107
+ F: __dxlog_file9,
2108
+ L: 46,
2109
+ S: this,
2110
+ A: [
2111
+ "!this._controller",
2112
+ "'Already initialized'"
2113
+ ]
2114
+ });
1798
2115
  this._controller = controller;
1799
2116
  }
1800
2117
  update() {
1801
- (0, import_tiny_invariant7.default)(this._controller, "Not initialized");
2118
+ (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2119
+ F: __dxlog_file9,
2120
+ L: 51,
2121
+ S: this,
2122
+ A: [
2123
+ "this._controller",
2124
+ "'Not initialized'"
2125
+ ]
2126
+ });
1802
2127
  const { connected, candidates } = this._controller.getState();
1803
2128
  if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
1804
2129
  (0, import_log8.log)("Running the algorithm.", void 0, {
1805
- F: __dxlog_file8,
2130
+ F: __dxlog_file9,
1806
2131
  L: 55,
1807
2132
  S: this,
1808
2133
  C: (f, a) => f(...a)
@@ -1812,11 +2137,19 @@ var MMSTTopology = class {
1812
2137
  }
1813
2138
  }
1814
2139
  async onOffer(peer) {
1815
- (0, import_tiny_invariant7.default)(this._controller, "Not initialized");
2140
+ (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2141
+ F: __dxlog_file9,
2142
+ L: 62,
2143
+ S: this,
2144
+ A: [
2145
+ "this._controller",
2146
+ "'Not initialized'"
2147
+ ]
2148
+ });
1816
2149
  const { connected } = this._controller.getState();
1817
2150
  const accept = connected.length < this._maxPeers;
1818
2151
  (0, import_log8.log)(`Offer ${peer} accept=${accept}`, void 0, {
1819
- F: __dxlog_file8,
2152
+ F: __dxlog_file9,
1820
2153
  L: 65,
1821
2154
  S: this,
1822
2155
  C: (f, a) => f(...a)
@@ -1826,13 +2159,21 @@ var MMSTTopology = class {
1826
2159
  async destroy() {
1827
2160
  }
1828
2161
  _runAlgorithm() {
1829
- (0, import_tiny_invariant7.default)(this._controller, "Not initialized");
2162
+ (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2163
+ F: __dxlog_file9,
2164
+ L: 74,
2165
+ S: this,
2166
+ A: [
2167
+ "this._controller",
2168
+ "'Not initialized'"
2169
+ ]
2170
+ });
1830
2171
  const { connected, candidates, ownPeerId } = this._controller.getState();
1831
2172
  if (connected.length > this._maxPeers) {
1832
2173
  const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
1833
2174
  for (const peer of sorted) {
1834
2175
  (0, import_log8.log)(`Disconnect ${peer}.`, void 0, {
1835
- F: __dxlog_file8,
2176
+ F: __dxlog_file9,
1836
2177
  L: 83,
1837
2178
  S: this,
1838
2179
  C: (f, a) => f(...a)
@@ -1844,7 +2185,7 @@ var MMSTTopology = class {
1844
2185
  const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
1845
2186
  for (const peer of sorted) {
1846
2187
  (0, import_log8.log)(`Connect ${peer}.`, void 0, {
1847
- F: __dxlog_file8,
2188
+ F: __dxlog_file9,
1848
2189
  L: 91,
1849
2190
  S: this,
1850
2191
  C: (f, a) => f(...a)
@@ -1860,9 +2201,9 @@ var MMSTTopology = class {
1860
2201
  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
2202
 
1862
2203
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
1863
- var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
2204
+ var import_invariant9 = require("@dxos/invariant");
1864
2205
  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";
2206
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
1866
2207
  var StarTopology = class {
1867
2208
  // prettier-ignore
1868
2209
  constructor(_centralPeer) {
@@ -1872,16 +2213,32 @@ var StarTopology = class {
1872
2213
  return `StarTopology(${this._centralPeer.truncate()})`;
1873
2214
  }
1874
2215
  init(controller) {
1875
- (0, import_tiny_invariant8.default)(!this._controller, "Already initialized.");
2216
+ (0, import_invariant9.invariant)(!this._controller, "Already initialized.", {
2217
+ F: __dxlog_file10,
2218
+ L: 24,
2219
+ S: this,
2220
+ A: [
2221
+ "!this._controller",
2222
+ "'Already initialized.'"
2223
+ ]
2224
+ });
1876
2225
  this._controller = controller;
1877
2226
  }
1878
2227
  update() {
1879
- (0, import_tiny_invariant8.default)(this._controller, "Not initialized.");
2228
+ (0, import_invariant9.invariant)(this._controller, "Not initialized.", {
2229
+ F: __dxlog_file10,
2230
+ L: 29,
2231
+ S: this,
2232
+ A: [
2233
+ "this._controller",
2234
+ "'Not initialized.'"
2235
+ ]
2236
+ });
1880
2237
  const { candidates, connected, ownPeerId } = this._controller.getState();
1881
2238
  if (!ownPeerId.equals(this._centralPeer)) {
1882
2239
  (0, import_log9.log)("leaf peer dropping all connections apart from central peer.", void 0, {
1883
- F: __dxlog_file9,
1884
- L: 33,
2240
+ F: __dxlog_file10,
2241
+ L: 32,
1885
2242
  S: this,
1886
2243
  C: (f, a) => f(...a)
1887
2244
  });
@@ -1890,8 +2247,8 @@ var StarTopology = class {
1890
2247
  (0, import_log9.log)("dropping connection", {
1891
2248
  peer
1892
2249
  }, {
1893
- F: __dxlog_file9,
1894
- L: 38,
2250
+ F: __dxlog_file10,
2251
+ L: 37,
1895
2252
  S: this,
1896
2253
  C: (f, a) => f(...a)
1897
2254
  });
@@ -1904,8 +2261,8 @@ var StarTopology = class {
1904
2261
  (0, import_log9.log)("connecting to peer", {
1905
2262
  peer
1906
2263
  }, {
1907
- F: __dxlog_file9,
1908
- L: 47,
2264
+ F: __dxlog_file10,
2265
+ L: 46,
1909
2266
  S: this,
1910
2267
  C: (f, a) => f(...a)
1911
2268
  });
@@ -1914,15 +2271,23 @@ var StarTopology = class {
1914
2271
  }
1915
2272
  }
1916
2273
  async onOffer(peer) {
1917
- (0, import_tiny_invariant8.default)(this._controller, "Not initialized.");
2274
+ (0, import_invariant9.invariant)(this._controller, "Not initialized.", {
2275
+ F: __dxlog_file10,
2276
+ L: 53,
2277
+ S: this,
2278
+ A: [
2279
+ "this._controller",
2280
+ "'Not initialized.'"
2281
+ ]
2282
+ });
1918
2283
  const { ownPeerId } = this._controller.getState();
1919
2284
  (0, import_log9.log)("offer", {
1920
2285
  peer,
1921
2286
  isCentral: peer.equals(this._centralPeer),
1922
2287
  isSelfCentral: ownPeerId.equals(this._centralPeer)
1923
2288
  }, {
1924
- F: __dxlog_file9,
1925
- L: 56,
2289
+ F: __dxlog_file10,
2290
+ L: 55,
1926
2291
  S: this,
1927
2292
  C: (f, a) => f(...a)
1928
2293
  });
@@ -1934,9 +2299,9 @@ var StarTopology = class {
1934
2299
 
1935
2300
  // packages/core/mesh/network-manager/src/transport/memory-transport.ts
1936
2301
  var import_node_stream = require("node:stream");
1937
- var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
1938
2302
  var import_async8 = require("@dxos/async");
1939
2303
  var import_debug4 = require("@dxos/debug");
2304
+ var import_invariant10 = require("@dxos/invariant");
1940
2305
  var import_keys9 = require("@dxos/keys");
1941
2306
  var import_log10 = require("@dxos/log");
1942
2307
  var import_util7 = require("@dxos/util");
@@ -1950,7 +2315,7 @@ function _ts_decorate4(decorators, target, key, desc) {
1950
2315
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1951
2316
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1952
2317
  }
1953
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2318
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
1954
2319
  var MEMORY_TRANSPORT_DELAY = 1;
1955
2320
  var createStreamDelay = (delay) => {
1956
2321
  return new import_node_stream.Transform({
@@ -1963,9 +2328,12 @@ var createStreamDelay = (delay) => {
1963
2328
  var MemoryTransportFactory = {
1964
2329
  createTransport: (params) => new MemoryTransport(params)
1965
2330
  };
1966
- var _MemoryTransport = class {
2331
+ var MemoryTransport = class _MemoryTransport {
2332
+ static {
2333
+ // TODO(burdon): Remove static properties (inject context into constructor).
2334
+ this._connections = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
2335
+ }
1967
2336
  constructor(options) {
1968
- var _a;
1969
2337
  this.options = options;
1970
2338
  this.closed = new import_async8.Event();
1971
2339
  this.connected = new import_async8.Event();
@@ -1976,17 +2344,25 @@ var _MemoryTransport = class {
1976
2344
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1977
2345
  this._destroyed = false;
1978
2346
  (0, import_log10.log)("creating", void 0, {
1979
- F: __dxlog_file10,
2347
+ F: __dxlog_file11,
1980
2348
  L: 64,
1981
2349
  S: this,
1982
2350
  C: (f, a) => f(...a)
1983
2351
  });
1984
- (0, import_tiny_invariant9.default)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
2352
+ (0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2353
+ F: __dxlog_file11,
2354
+ L: 66,
2355
+ S: this,
2356
+ A: [
2357
+ "!MemoryTransport._connections.has(this._instanceId)",
2358
+ "'Duplicate memory connection'"
2359
+ ]
2360
+ });
1985
2361
  _MemoryTransport._connections.set(this._instanceId, this);
1986
2362
  if (this.options.initiator) {
1987
2363
  setTimeout(async () => {
1988
2364
  (0, import_log10.log)("sending signal", void 0, {
1989
- F: __dxlog_file10,
2365
+ F: __dxlog_file11,
1990
2366
  L: 73,
1991
2367
  S: this,
1992
2368
  C: (f, a) => f(...a)
@@ -2003,7 +2379,7 @@ var _MemoryTransport = class {
2003
2379
  });
2004
2380
  } else {
2005
2381
  this._remote.wait({
2006
- timeout: (_a = this.options.timeout) != null ? _a : 1e3
2382
+ timeout: this.options.timeout ?? 1e3
2007
2383
  }).then((remoteId) => {
2008
2384
  if (this._destroyed) {
2009
2385
  return;
@@ -2015,11 +2391,19 @@ var _MemoryTransport = class {
2015
2391
  this.closed.emit();
2016
2392
  return;
2017
2393
  }
2018
- (0, import_tiny_invariant9.default)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`);
2394
+ (0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
2395
+ F: __dxlog_file11,
2396
+ L: 99,
2397
+ S: this,
2398
+ A: [
2399
+ "!this._remoteConnection._remoteConnection",
2400
+ "`Remote already connected: ${this._remoteInstanceId}`"
2401
+ ]
2402
+ });
2019
2403
  this._remoteConnection._remoteConnection = this;
2020
2404
  this._remoteConnection._remoteInstanceId = this._instanceId;
2021
2405
  (0, import_log10.log)("connected", void 0, {
2022
- F: __dxlog_file10,
2406
+ F: __dxlog_file11,
2023
2407
  L: 103,
2024
2408
  S: this,
2025
2409
  C: (f, a) => f(...a)
@@ -2037,7 +2421,7 @@ var _MemoryTransport = class {
2037
2421
  }
2038
2422
  async destroy() {
2039
2423
  (0, import_log10.log)("closing", void 0, {
2040
- F: __dxlog_file10,
2424
+ F: __dxlog_file11,
2041
2425
  L: 124,
2042
2426
  S: this,
2043
2427
  C: (f, a) => f(...a)
@@ -2046,7 +2430,7 @@ var _MemoryTransport = class {
2046
2430
  _MemoryTransport._connections.delete(this._instanceId);
2047
2431
  if (this._remoteConnection) {
2048
2432
  (0, import_log10.log)("closing", void 0, {
2049
- F: __dxlog_file10,
2433
+ F: __dxlog_file11,
2050
2434
  L: 129,
2051
2435
  S: this,
2052
2436
  C: (f, a) => f(...a)
@@ -2059,7 +2443,7 @@ var _MemoryTransport = class {
2059
2443
  this._remoteConnection._remoteConnection = void 0;
2060
2444
  this._remoteConnection = void 0;
2061
2445
  (0, import_log10.log)("closed", void 0, {
2062
- F: __dxlog_file10,
2446
+ F: __dxlog_file11,
2063
2447
  L: 147,
2064
2448
  S: this,
2065
2449
  C: (f, a) => f(...a)
@@ -2067,7 +2451,7 @@ var _MemoryTransport = class {
2067
2451
  }
2068
2452
  this.closed.emit();
2069
2453
  (0, import_log10.log)("closed", void 0, {
2070
- F: __dxlog_file10,
2454
+ F: __dxlog_file11,
2071
2455
  L: 151,
2072
2456
  S: this,
2073
2457
  C: (f, a) => f(...a)
@@ -2077,12 +2461,12 @@ var _MemoryTransport = class {
2077
2461
  (0, import_log10.log)("received signal", {
2078
2462
  payload
2079
2463
  }, {
2080
- F: __dxlog_file10,
2464
+ F: __dxlog_file11,
2081
2465
  L: 155,
2082
2466
  S: this,
2083
2467
  C: (f, a) => f(...a)
2084
2468
  });
2085
- if (!(payload == null ? void 0 : payload.transportId)) {
2469
+ if (!payload?.transportId) {
2086
2470
  return;
2087
2471
  }
2088
2472
  const transportId = payload.transportId;
@@ -2092,9 +2476,6 @@ var _MemoryTransport = class {
2092
2476
  }
2093
2477
  }
2094
2478
  };
2095
- var MemoryTransport = _MemoryTransport;
2096
- // TODO(burdon): Remove static properties (inject context into constructor).
2097
- MemoryTransport._connections = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
2098
2479
  _ts_decorate4([
2099
2480
  import_log10.logInfo
2100
2481
  ], MemoryTransport.prototype, "_instanceId", void 0);
@@ -2104,9 +2485,9 @@ _ts_decorate4([
2104
2485
 
2105
2486
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
2106
2487
  var import_simple_peer = __toESM(require("simple-peer"));
2107
- var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
2108
2488
  var import_async9 = require("@dxos/async");
2109
2489
  var import_debug5 = require("@dxos/debug");
2490
+ var import_invariant11 = require("@dxos/invariant");
2110
2491
  var import_keys10 = require("@dxos/keys");
2111
2492
  var import_log11 = require("@dxos/log");
2112
2493
  var import_protocols5 = require("@dxos/protocols");
@@ -2115,43 +2496,47 @@ var import_protocols5 = require("@dxos/protocols");
2115
2496
  var wrtc = null;
2116
2497
  try {
2117
2498
  wrtc = require("@koush/wrtc");
2118
- } catch (e) {
2499
+ } catch {
2119
2500
  }
2120
2501
 
2121
2502
  // 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";
2503
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
2123
2504
  var WebRTCTransport = class {
2124
2505
  constructor(params) {
2125
- var _a;
2126
2506
  this.params = params;
2507
+ this._instanceId = import_keys10.PublicKey.random().toHex();
2127
2508
  this._closed = false;
2128
2509
  this.closed = new import_async9.Event();
2129
2510
  this.connected = new import_async9.Event();
2130
2511
  this.errors = new import_debug5.ErrorStream();
2131
- this._instanceId = import_keys10.PublicKey.random().toHex();
2132
2512
  import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
2133
2513
  id: this._instanceId
2134
2514
  }), {
2135
- F: __dxlog_file11,
2136
- L: 39,
2515
+ F: __dxlog_file12,
2516
+ L: 44,
2137
2517
  S: this,
2138
2518
  C: (f, a) => f(...a)
2139
2519
  });
2140
2520
  (0, import_log11.log)("created connection", params, {
2141
- F: __dxlog_file11,
2142
- L: 40,
2521
+ F: __dxlog_file12,
2522
+ L: 45,
2143
2523
  S: this,
2144
2524
  C: (f, a) => f(...a)
2145
2525
  });
2146
2526
  this._peer = new import_simple_peer.default({
2147
2527
  initiator: this.params.initiator,
2148
- wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : (_a = wrtc) != null ? _a : (0, import_debug5.raise)(new Error("wrtc not available")),
2149
- config: this.params.webrtcConfig
2528
+ config: this.params.webrtcConfig,
2529
+ // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createDataChannel
2530
+ channelConfig: {
2531
+ protocol: "dxos.mesh"
2532
+ },
2533
+ // Custom WebRTC implementation (for Node); otherwise get-browser-rtc.
2534
+ wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : wrtc ?? (0, import_debug5.raise)(new Error("wrtc not available"))
2150
2535
  });
2151
2536
  this._peer.on("signal", async (data) => {
2152
2537
  (0, import_log11.log)("signal", data, {
2153
- F: __dxlog_file11,
2154
- L: 48,
2538
+ F: __dxlog_file12,
2539
+ L: 62,
2155
2540
  S: this,
2156
2541
  C: (f, a) => f(...a)
2157
2542
  });
@@ -2163,8 +2548,8 @@ var WebRTCTransport = class {
2163
2548
  });
2164
2549
  this._peer.on("connect", () => {
2165
2550
  (0, import_log11.log)("connected", void 0, {
2166
- F: __dxlog_file11,
2167
- L: 53,
2551
+ F: __dxlog_file12,
2552
+ L: 67,
2168
2553
  S: this,
2169
2554
  C: (f, a) => f(...a)
2170
2555
  });
@@ -2173,8 +2558,8 @@ var WebRTCTransport = class {
2173
2558
  });
2174
2559
  this._peer.on("close", async () => {
2175
2560
  (0, import_log11.log)("closed", void 0, {
2176
- F: __dxlog_file11,
2177
- L: 59,
2561
+ F: __dxlog_file12,
2562
+ L: 73,
2178
2563
  S: this,
2179
2564
  C: (f, a) => f(...a)
2180
2565
  });
@@ -2182,39 +2567,38 @@ var WebRTCTransport = class {
2182
2567
  this.closed.emit();
2183
2568
  });
2184
2569
  this._peer.on("error", async (err) => {
2185
- var _a2;
2186
2570
  this.errors.raise(err);
2187
2571
  try {
2188
- if (typeof ((_a2 = this._peer) == null ? void 0 : _a2._pc.getStats) === "function") {
2572
+ if (typeof this._peer?._pc.getStats === "function") {
2189
2573
  this._peer._pc.getStats().then((stats) => {
2190
2574
  import_log11.log.warn("report after webrtc error", {
2191
2575
  config: this.params.webrtcConfig,
2192
2576
  stats
2193
2577
  }, {
2194
- F: __dxlog_file11,
2195
- L: 71,
2578
+ F: __dxlog_file12,
2579
+ L: 85,
2196
2580
  S: this,
2197
2581
  C: (f, a) => f(...a)
2198
2582
  });
2199
2583
  });
2200
2584
  }
2201
- } catch (e) {
2585
+ } catch {
2202
2586
  }
2203
2587
  await this.destroy();
2204
2588
  });
2205
2589
  import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
2206
2590
  id: this._instanceId
2207
2591
  }), {
2208
- F: __dxlog_file11,
2209
- L: 81,
2592
+ F: __dxlog_file12,
2593
+ L: 95,
2210
2594
  S: this,
2211
2595
  C: (f, a) => f(...a)
2212
2596
  });
2213
2597
  }
2214
2598
  async destroy() {
2215
2599
  (0, import_log11.log)("closing...", void 0, {
2216
- F: __dxlog_file11,
2217
- L: 85,
2600
+ F: __dxlog_file12,
2601
+ L: 99,
2218
2602
  S: this,
2219
2603
  C: (f, a) => f(...a)
2220
2604
  });
@@ -2223,8 +2607,8 @@ var WebRTCTransport = class {
2223
2607
  this._peer.destroy();
2224
2608
  this.closed.emit();
2225
2609
  (0, import_log11.log)("closed", void 0, {
2226
- F: __dxlog_file11,
2227
- L: 90,
2610
+ F: __dxlog_file12,
2611
+ L: 104,
2228
2612
  S: this,
2229
2613
  C: (f, a) => f(...a)
2230
2614
  });
@@ -2233,12 +2617,19 @@ var WebRTCTransport = class {
2233
2617
  if (this._closed) {
2234
2618
  return;
2235
2619
  }
2236
- (0, import_tiny_invariant10.default)(signal.payload.data, "Signal message must contain signal data.");
2620
+ (0, import_invariant11.invariant)(signal.payload.data, "Signal message must contain signal data.", {
2621
+ F: __dxlog_file12,
2622
+ L: 112,
2623
+ S: this,
2624
+ A: [
2625
+ "signal.payload.data",
2626
+ "'Signal message must contain signal data.'"
2627
+ ]
2628
+ });
2237
2629
  this._peer.signal(signal.payload.data);
2238
2630
  }
2239
2631
  async _disconnectStreams() {
2240
- var _a, _b, _c, _d;
2241
- (_d = (_c = (_b = (_a = this.params.stream).unpipe) == null ? void 0 : _b.call(_a, this._peer)) == null ? void 0 : _c.unpipe) == null ? void 0 : _d.call(_c, this.params.stream);
2632
+ this.params.stream.unpipe?.(this._peer)?.unpipe?.(this.params.stream);
2242
2633
  }
2243
2634
  };
2244
2635
  var createWebRTCTransportFactory = (webrtcConfig) => ({
@@ -2250,13 +2641,13 @@ var createWebRTCTransportFactory = (webrtcConfig) => ({
2250
2641
 
2251
2642
  // packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
2252
2643
  var import_node_stream2 = require("node:stream");
2253
- var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
2254
2644
  var import_codec_protobuf = require("@dxos/codec-protobuf");
2645
+ var import_invariant12 = require("@dxos/invariant");
2255
2646
  var import_keys11 = require("@dxos/keys");
2256
2647
  var import_log12 = require("@dxos/log");
2257
2648
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
2258
2649
  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";
2650
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
2260
2651
  var WebRTCTransportService = class {
2261
2652
  // prettier-ignore
2262
2653
  constructor(_webrtcConfig) {
@@ -2267,6 +2658,13 @@ var WebRTCTransportService = class {
2267
2658
  const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
2268
2659
  const duplex = new import_node_stream2.Duplex({
2269
2660
  read: () => {
2661
+ const callbacks = [
2662
+ ...transportState.writeCallbacks
2663
+ ];
2664
+ transportState.writeCallbacks.length = 0;
2665
+ for (const cb of callbacks) {
2666
+ cb();
2667
+ }
2270
2668
  },
2271
2669
  write: function(chunk, _, callback) {
2272
2670
  next({
@@ -2318,30 +2716,53 @@ var WebRTCTransportService = class {
2318
2716
  });
2319
2717
  close();
2320
2718
  });
2321
- ready();
2322
- this.transports.set(request.proxyId, {
2719
+ const transportState = {
2323
2720
  transport,
2324
- stream: duplex
2325
- });
2721
+ stream: duplex,
2722
+ writeCallbacks: []
2723
+ };
2724
+ ready();
2725
+ this.transports.set(request.proxyId, transportState);
2326
2726
  });
2327
2727
  return rpcStream;
2328
2728
  }
2329
2729
  async sendSignal({ proxyId, signal }) {
2330
- (0, import_tiny_invariant11.default)(this.transports.has(proxyId));
2730
+ (0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
2731
+ F: __dxlog_file13,
2732
+ L: 113,
2733
+ S: this,
2734
+ A: [
2735
+ "this.transports.has(proxyId)",
2736
+ ""
2737
+ ]
2738
+ });
2331
2739
  await this.transports.get(proxyId).transport.signal(signal);
2332
2740
  }
2333
2741
  async sendData({ proxyId, payload }) {
2334
- (0, import_tiny_invariant11.default)(this.transports.has(proxyId));
2335
- await this.transports.get(proxyId).stream.push(payload);
2742
+ (0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
2743
+ F: __dxlog_file13,
2744
+ L: 118,
2745
+ S: this,
2746
+ A: [
2747
+ "this.transports.has(proxyId)",
2748
+ ""
2749
+ ]
2750
+ });
2751
+ const state = this.transports.get(proxyId);
2752
+ const bufferHasSpace = state.stream.push(payload);
2753
+ if (!bufferHasSpace) {
2754
+ await new Promise((resolve) => {
2755
+ state.writeCallbacks.push(resolve);
2756
+ });
2757
+ }
2336
2758
  }
2337
2759
  async close({ proxyId }) {
2338
- var _a, _b;
2339
- await ((_a = this.transports.get(proxyId)) == null ? void 0 : _a.transport.destroy());
2340
- await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
2760
+ await this.transports.get(proxyId)?.transport.destroy();
2761
+ await this.transports.get(proxyId)?.stream.end();
2341
2762
  this.transports.delete(proxyId);
2342
2763
  (0, import_log12.log)("Closed.", void 0, {
2343
- F: __dxlog_file12,
2344
- L: 109,
2764
+ F: __dxlog_file13,
2765
+ L: 132,
2345
2766
  S: this,
2346
2767
  C: (f, a) => f(...a)
2347
2768
  });
@@ -2349,15 +2770,16 @@ var WebRTCTransportService = class {
2349
2770
  };
2350
2771
 
2351
2772
  // packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
2352
- var import_tiny_invariant12 = __toESM(require("tiny-invariant"));
2773
+ var import_node_stream3 = require("node:stream");
2353
2774
  var import_async10 = require("@dxos/async");
2354
2775
  var import_context6 = require("@dxos/context");
2355
2776
  var import_debug6 = require("@dxos/debug");
2777
+ var import_invariant13 = require("@dxos/invariant");
2356
2778
  var import_keys12 = require("@dxos/keys");
2357
2779
  var import_log13 = require("@dxos/log");
2358
2780
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
2359
2781
  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";
2782
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
2361
2783
  var WebRTCTransportProxy = class {
2362
2784
  // prettier-ignore
2363
2785
  constructor(_params) {
@@ -2365,9 +2787,9 @@ var WebRTCTransportProxy = class {
2365
2787
  this._proxyId = import_keys12.PublicKey.random();
2366
2788
  this._ctx = new import_context6.Context();
2367
2789
  this.closed = new import_async10.Event();
2368
- this._closed = false;
2369
2790
  this.connected = new import_async10.Event();
2370
2791
  this.errors = new import_debug6.ErrorStream();
2792
+ this._closed = false;
2371
2793
  this._serviceStream = this._params.bridgeService.open({
2372
2794
  proxyId: this._proxyId,
2373
2795
  initiator: this._params.initiator
@@ -2375,8 +2797,8 @@ var WebRTCTransportProxy = class {
2375
2797
  this._serviceStream.waitUntilReady().then(() => {
2376
2798
  this._serviceStream.subscribe(async (event) => {
2377
2799
  (0, import_log13.log)("WebRTCTransportProxy: event", event, {
2378
- F: __dxlog_file13,
2379
- L: 50,
2800
+ F: __dxlog_file14,
2801
+ L: 51,
2380
2802
  S: this,
2381
2803
  C: (f, a) => f(...a)
2382
2804
  });
@@ -2388,28 +2810,24 @@ var WebRTCTransportProxy = class {
2388
2810
  await this._handleSignal(event.signal);
2389
2811
  }
2390
2812
  });
2391
- const dataListener = async (data) => {
2392
- try {
2393
- await this._params.bridgeService.sendData({
2813
+ this._params.stream.pipe(new import_node_stream3.Writable({
2814
+ write: (chunk, _, callback) => {
2815
+ this._params.bridgeService.sendData({
2394
2816
  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)
2817
+ payload: chunk
2818
+ }).then(() => callback(), (err) => {
2819
+ import_log13.log.catch(err, void 0, {
2820
+ F: __dxlog_file14,
2821
+ L: 69,
2822
+ S: this,
2823
+ C: (f, a) => f(...a)
2824
+ });
2403
2825
  });
2404
2826
  }
2405
- };
2406
- this._params.stream.on("data", dataListener);
2407
- this._ctx.onDispose(() => {
2408
- this._params.stream.off("data", dataListener);
2409
- });
2827
+ }));
2410
2828
  }, (error) => import_log13.log.catch(error, void 0, {
2411
- F: __dxlog_file13,
2412
- L: 73,
2829
+ F: __dxlog_file14,
2830
+ L: 75,
2413
2831
  S: this,
2414
2832
  C: (f, a) => f(...a)
2415
2833
  }));
@@ -2447,15 +2865,15 @@ var WebRTCTransportProxy = class {
2447
2865
  if (this._closed) {
2448
2866
  return;
2449
2867
  }
2450
- this._serviceStream.close();
2868
+ await this._serviceStream.close();
2451
2869
  try {
2452
2870
  await this._params.bridgeService.close({
2453
2871
  proxyId: this._proxyId
2454
2872
  });
2455
2873
  } catch (err) {
2456
2874
  import_log13.log.catch(err, void 0, {
2457
- F: __dxlog_file13,
2458
- L: 124,
2875
+ F: __dxlog_file14,
2876
+ L: 126,
2459
2877
  S: this,
2460
2878
  C: (f, a) => f(...a)
2461
2879
  });
@@ -2468,7 +2886,7 @@ var WebRTCTransportProxy = class {
2468
2886
  */
2469
2887
  // TODO(burdon): Option on close method.
2470
2888
  forceClose() {
2471
- this._serviceStream.close();
2889
+ void this._serviceStream.close();
2472
2890
  this.closed.emit();
2473
2891
  this._closed = true;
2474
2892
  }
@@ -2489,7 +2907,15 @@ var WebRTCTransportProxyFactory = class {
2489
2907
  return this;
2490
2908
  }
2491
2909
  createTransport(options) {
2492
- (0, import_tiny_invariant12.default)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections");
2910
+ (0, import_invariant13.invariant)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections", {
2911
+ F: __dxlog_file14,
2912
+ L: 163,
2913
+ S: this,
2914
+ A: [
2915
+ "this._bridgeService",
2916
+ "'WebRTCTransportProxyFactory is not ready to open connections'"
2917
+ ]
2918
+ });
2493
2919
  const transport = new WebRTCTransportProxy({
2494
2920
  ...options,
2495
2921
  bridgeService: this._bridgeService