@dxos/network-manager 0.4.10-main.fd4f2a3 → 0.4.10-next.71cec10

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 (45) hide show
  1. package/dist/lib/browser/{chunk-OIR45T43.mjs → chunk-SOVZDG44.mjs} +464 -425
  2. package/dist/lib/browser/chunk-SOVZDG44.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/{chunk-HUPX2JGP.cjs → chunk-BMZFS4HT.cjs} +480 -440
  7. package/dist/lib/node/chunk-BMZFS4HT.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +27 -27
  9. package/dist/lib/node/index.cjs.map +1 -1
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +18 -18
  12. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  13. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  14. package/dist/types/src/transport/libdatachannel-transport.d.ts +20 -19
  15. package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
  16. package/dist/types/src/transport/memory-transport.d.ts +17 -10
  17. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  18. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts +7 -9
  19. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  20. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
  21. package/dist/types/src/transport/simplepeer-transport.d.ts +9 -11
  22. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  23. package/dist/types/src/transport/tcp-transport.browser.d.ts +7 -2
  24. package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -1
  25. package/dist/types/src/transport/tcp-transport.d.ts +6 -4
  26. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -1
  27. package/dist/types/src/transport/transport.d.ts +18 -12
  28. package/dist/types/src/transport/transport.d.ts.map +1 -1
  29. package/package.json +17 -17
  30. package/src/swarm/connection.ts +7 -5
  31. package/src/swarm/peer.ts +3 -4
  32. package/src/transport/libdatachannel-transport.test.ts +14 -9
  33. package/src/transport/libdatachannel-transport.ts +226 -204
  34. package/src/transport/memory-transport.test.ts +10 -7
  35. package/src/transport/memory-transport.ts +49 -42
  36. package/src/transport/simplepeer-transport-proxy-test.ts +13 -8
  37. package/src/transport/simplepeer-transport-proxy.ts +48 -49
  38. package/src/transport/simplepeer-transport-service.ts +5 -2
  39. package/src/transport/simplepeer-transport.test.ts +9 -5
  40. package/src/transport/simplepeer-transport.ts +25 -25
  41. package/src/transport/tcp-transport.browser.ts +10 -5
  42. package/src/transport/tcp-transport.ts +31 -22
  43. package/src/transport/transport.ts +25 -14
  44. package/dist/lib/browser/chunk-OIR45T43.mjs.map +0 -7
  45. package/dist/lib/node/chunk-HUPX2JGP.cjs.map +0 -7
@@ -167,6 +167,7 @@ var Connection = class {
167
167
  sendSignal: async (signal) => this._sendSignal(signal),
168
168
  sessionId: this.sessionId
169
169
  });
170
+ await this._transport.open();
170
171
  this._transport.connected.once(async () => {
171
172
  this._changeState("CONNECTED");
172
173
  await this.connectedTimeoutContext.dispose();
@@ -177,7 +178,7 @@ var Connection = class {
177
178
  this._transport = void 0;
178
179
  log("abort triggered by transport close", void 0, {
179
180
  F: __dxlog_file,
180
- L: 216,
181
+ L: 218,
181
182
  S: this,
182
183
  C: (f, a) => f(...a)
183
184
  });
@@ -188,7 +189,7 @@ var Connection = class {
188
189
  err
189
190
  }, {
190
191
  F: __dxlog_file,
191
- L: 221,
192
+ L: 223,
192
193
  S: this,
193
194
  C: (f, a) => f(...a)
194
195
  });
@@ -198,7 +199,7 @@ var Connection = class {
198
199
  if (err instanceof ConnectionResetError) {
199
200
  log.info("aborting due to transport ConnectionResetError", void 0, {
200
201
  F: __dxlog_file,
201
- L: 228,
202
+ L: 230,
202
203
  S: this,
203
204
  C: (f, a) => f(...a)
204
205
  });
@@ -206,7 +207,7 @@ var Connection = class {
206
207
  } else if (err instanceof ConnectivityError) {
207
208
  log.info("aborting due to transport ConnectivityError", void 0, {
208
209
  F: __dxlog_file,
209
- L: 231,
210
+ L: 233,
210
211
  S: this,
211
212
  C: (f, a) => f(...a)
212
213
  });
@@ -216,7 +217,7 @@ var Connection = class {
216
217
  err
217
218
  }, {
218
219
  F: __dxlog_file,
219
- L: 234,
220
+ L: 236,
220
221
  S: this,
221
222
  C: (f, a) => f(...a)
222
223
  });
@@ -227,14 +228,14 @@ var Connection = class {
227
228
  }
228
229
  });
229
230
  for (const signal of this._incomingSignalBuffer) {
230
- void this._transport.signal(signal);
231
+ void this._transport.onSignal(signal);
231
232
  }
232
233
  this._incomingSignalBuffer = [];
233
234
  log.trace("dxos.mesh.connection.open-connection", trace.end({
234
235
  id: this._instanceId
235
236
  }), {
236
237
  F: __dxlog_file,
237
- L: 250,
238
+ L: 252,
238
239
  S: this,
239
240
  C: (f, a) => f(...a)
240
241
  });
@@ -244,14 +245,14 @@ var Connection = class {
244
245
  err
245
246
  }, {
246
247
  F: __dxlog_file,
247
- L: 257,
248
+ L: 259,
248
249
  S: this,
249
250
  C: (f, a) => f(...a)
250
251
  });
251
252
  if (this._state === "CLOSED" || this._state === "ABORTED") {
252
253
  log(`abort ignored: already ${this._state}`, this.closeReason, {
253
254
  F: __dxlog_file,
254
- L: 259,
255
+ L: 261,
255
256
  S: this,
256
257
  C: (f, a) => f(...a)
257
258
  });
@@ -266,7 +267,7 @@ var Connection = class {
266
267
  try {
267
268
  log("aborting protocol... ", void 0, {
268
269
  F: __dxlog_file,
269
- L: 273,
270
+ L: 275,
270
271
  S: this,
271
272
  C: (f, a) => f(...a)
272
273
  });
@@ -274,17 +275,17 @@ var Connection = class {
274
275
  } catch (err2) {
275
276
  log.catch(err2, void 0, {
276
277
  F: __dxlog_file,
277
- L: 276,
278
+ L: 278,
278
279
  S: this,
279
280
  C: (f, a) => f(...a)
280
281
  });
281
282
  }
282
283
  try {
283
- await this._transport?.destroy();
284
+ await this._transport?.close();
284
285
  } catch (err2) {
285
286
  log.catch(err2, void 0, {
286
287
  F: __dxlog_file,
287
- L: 283,
288
+ L: 285,
288
289
  S: this,
289
290
  C: (f, a) => f(...a)
290
291
  });
@@ -294,7 +295,7 @@ var Connection = class {
294
295
  } catch (err2) {
295
296
  log.catch(err2, void 0, {
296
297
  F: __dxlog_file,
297
- L: 289,
298
+ L: 291,
298
299
  S: this,
299
300
  C: (f, a) => f(...a)
300
301
  });
@@ -318,7 +319,7 @@ var Connection = class {
318
319
  peerId: this.ownId
319
320
  }, {
320
321
  F: __dxlog_file,
321
- L: 314,
322
+ L: 316,
322
323
  S: this,
323
324
  C: (f, a) => f(...a)
324
325
  });
@@ -328,17 +329,17 @@ var Connection = class {
328
329
  } catch (err2) {
329
330
  log.catch(err2, void 0, {
330
331
  F: __dxlog_file,
331
- L: 321,
332
+ L: 323,
332
333
  S: this,
333
334
  C: (f, a) => f(...a)
334
335
  });
335
336
  }
336
337
  try {
337
- await this._transport?.destroy();
338
+ await this._transport?.close();
338
339
  } catch (err2) {
339
340
  log.catch(err2, void 0, {
340
341
  F: __dxlog_file,
341
- L: 328,
342
+ L: 330,
342
343
  S: this,
343
344
  C: (f, a) => f(...a)
344
345
  });
@@ -346,7 +347,7 @@ var Connection = class {
346
347
  } else {
347
348
  log.info(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
348
349
  F: __dxlog_file,
349
- L: 331,
350
+ L: 333,
350
351
  S: this,
351
352
  C: (f, a) => f(...a)
352
353
  });
@@ -355,17 +356,17 @@ var Connection = class {
355
356
  } catch (err2) {
356
357
  log.catch(err2, void 0, {
357
358
  F: __dxlog_file,
358
- L: 335,
359
+ L: 337,
359
360
  S: this,
360
361
  C: (f, a) => f(...a)
361
362
  });
362
363
  }
363
364
  try {
364
- await this._transport?.destroy();
365
+ await this._transport?.close();
365
366
  } catch (err2) {
366
367
  log.catch(err2, void 0, {
367
368
  F: __dxlog_file,
368
- L: 340,
369
+ L: 342,
369
370
  S: this,
370
371
  C: (f, a) => f(...a)
371
372
  });
@@ -375,7 +376,7 @@ var Connection = class {
375
376
  peerId: this.ownId
376
377
  }, {
377
378
  F: __dxlog_file,
378
- L: 344,
379
+ L: 346,
379
380
  S: this,
380
381
  C: (f, a) => f(...a)
381
382
  });
@@ -418,7 +419,7 @@ var Connection = class {
418
419
  err
419
420
  }, {
420
421
  F: __dxlog_file,
421
- L: 382,
422
+ L: 384,
422
423
  S: this,
423
424
  C: (f, a) => f(...a)
424
425
  });
@@ -431,7 +432,7 @@ var Connection = class {
431
432
  async signal(msg) {
432
433
  invariant(msg.sessionId, void 0, {
433
434
  F: __dxlog_file,
434
- L: 391,
435
+ L: 393,
435
436
  S: this,
436
437
  A: [
437
438
  "msg.sessionId",
@@ -441,7 +442,7 @@ var Connection = class {
441
442
  if (!msg.sessionId.equals(this.sessionId)) {
442
443
  log("dropping signal for incorrect session id", void 0, {
443
444
  F: __dxlog_file,
444
- L: 393,
445
+ L: 395,
445
446
  S: this,
446
447
  C: (f, a) => f(...a)
447
448
  });
@@ -449,7 +450,7 @@ var Connection = class {
449
450
  }
450
451
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
451
452
  F: __dxlog_file,
452
- L: 396,
453
+ L: 398,
453
454
  S: this,
454
455
  A: [
455
456
  "msg.data.signal || msg.data.signalBatch",
@@ -458,7 +459,7 @@ var Connection = class {
458
459
  });
459
460
  invariant(msg.author?.equals(this.remoteId), void 0, {
460
461
  F: __dxlog_file,
461
- L: 397,
462
+ L: 399,
462
463
  S: this,
463
464
  A: [
464
465
  "msg.author?.equals(this.remoteId)",
@@ -467,7 +468,7 @@ var Connection = class {
467
468
  });
468
469
  invariant(msg.recipient?.equals(this.ownId), void 0, {
469
470
  F: __dxlog_file,
470
- L: 398,
471
+ L: 400,
471
472
  S: this,
472
473
  A: [
473
474
  "msg.recipient?.equals(this.ownId)",
@@ -491,7 +492,7 @@ var Connection = class {
491
492
  msg: msg.data
492
493
  }, {
493
494
  F: __dxlog_file,
494
- L: 407,
495
+ L: 409,
495
496
  S: this,
496
497
  C: (f, a) => f(...a)
497
498
  });
@@ -499,7 +500,7 @@ var Connection = class {
499
500
  } else {
500
501
  invariant(this._transport, "Connection not ready to accept signals.", {
501
502
  F: __dxlog_file,
502
- L: 410,
503
+ L: 412,
503
504
  S: this,
504
505
  A: [
505
506
  "this._transport",
@@ -512,11 +513,11 @@ var Connection = class {
512
513
  msg: msg.data
513
514
  }, {
514
515
  F: __dxlog_file,
515
- L: 411,
516
+ L: 413,
516
517
  S: this,
517
518
  C: (f, a) => f(...a)
518
519
  });
519
- await this._transport.signal(signal);
520
+ await this._transport.onSignal(signal);
520
521
  }
521
522
  }
522
523
  }
@@ -530,13 +531,13 @@ var Connection = class {
530
531
  peerId: this.ownId
531
532
  }, {
532
533
  F: __dxlog_file,
533
- L: 422,
534
+ L: 424,
534
535
  S: this,
535
536
  C: (f, a) => f(...a)
536
537
  });
537
538
  invariant(state !== this._state, "Already in this state.", {
538
539
  F: __dxlog_file,
539
- L: 423,
540
+ L: 425,
540
541
  S: this,
541
542
  A: [
542
543
  "state !== this._state",
@@ -841,7 +842,6 @@ var ConnectionDisplacedError = class extends SystemError {
841
842
  };
842
843
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
843
844
  var Peer = class {
844
- // TODO(burdon): Convert to map?
845
845
  constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
846
846
  this.id = id;
847
847
  this.topic = topic;
@@ -870,7 +870,7 @@ var Peer = class {
870
870
  ].includes(this.connection.state)) {
871
871
  log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
872
872
  F: __dxlog_file3,
873
- L: 115,
873
+ L: 114,
874
874
  S: this,
875
875
  C: (f, a) => f(...a)
876
876
  });
@@ -887,7 +887,7 @@ var Peer = class {
887
887
  sessionId: this.connection?.sessionId
888
888
  }, {
889
889
  F: __dxlog_file3,
890
- L: 124,
890
+ L: 123,
891
891
  S: this,
892
892
  C: (f, a) => f(...a)
893
893
  });
@@ -904,7 +904,7 @@ var Peer = class {
904
904
  if (!this.connection) {
905
905
  invariant3(message.sessionId, void 0, {
906
906
  F: __dxlog_file3,
907
- L: 144,
907
+ L: 143,
908
908
  S: this,
909
909
  A: [
910
910
  "message.sessionId",
@@ -925,7 +925,7 @@ var Peer = class {
925
925
  err
926
926
  }, {
927
927
  F: __dxlog_file3,
928
- L: 154,
928
+ L: 153,
929
929
  S: this,
930
930
  C: (f, a) => f(...a)
931
931
  });
@@ -947,7 +947,7 @@ var Peer = class {
947
947
  async initiateConnection() {
948
948
  invariant3(!this.initiating, "Initiation in progress.", {
949
949
  F: __dxlog_file3,
950
- L: 171,
950
+ L: 170,
951
951
  S: this,
952
952
  A: [
953
953
  "!this.initiating",
@@ -956,7 +956,7 @@ var Peer = class {
956
956
  });
957
957
  invariant3(!this.connection, "Already connected.", {
958
958
  F: __dxlog_file3,
959
- L: 172,
959
+ L: 171,
960
960
  S: this,
961
961
  A: [
962
962
  "!this.connection",
@@ -971,7 +971,7 @@ var Peer = class {
971
971
  sessionId
972
972
  }, {
973
973
  F: __dxlog_file3,
974
- L: 174,
974
+ L: 173,
975
975
  S: this,
976
976
  C: (f, a) => f(...a)
977
977
  });
@@ -997,14 +997,14 @@ var Peer = class {
997
997
  remoteId: this.id
998
998
  }, {
999
999
  F: __dxlog_file3,
1000
- L: 191,
1000
+ L: 190,
1001
1001
  S: this,
1002
1002
  C: (f, a) => f(...a)
1003
1003
  });
1004
1004
  if (connection.state !== ConnectionState.INITIAL) {
1005
1005
  log3("ignoring response", void 0, {
1006
1006
  F: __dxlog_file3,
1007
- L: 193,
1007
+ L: 192,
1008
1008
  S: this,
1009
1009
  C: (f, a) => f(...a)
1010
1010
  });
@@ -1018,7 +1018,7 @@ var Peer = class {
1018
1018
  remoteId: this.id
1019
1019
  }, {
1020
1020
  F: __dxlog_file3,
1021
- L: 197,
1021
+ L: 196,
1022
1022
  S: this,
1023
1023
  C: (f, a) => f(...a)
1024
1024
  });
@@ -1040,7 +1040,7 @@ var Peer = class {
1040
1040
  remoteId: this.id
1041
1041
  }, {
1042
1042
  F: __dxlog_file3,
1043
- L: 210,
1043
+ L: 209,
1044
1044
  S: this,
1045
1045
  C: (f, a) => f(...a)
1046
1046
  });
@@ -1052,7 +1052,7 @@ var Peer = class {
1052
1052
  try {
1053
1053
  log3("opening connection as initiator", void 0, {
1054
1054
  F: __dxlog_file3,
1055
- L: 223,
1055
+ L: 222,
1056
1056
  S: this,
1057
1057
  C: (f, a) => f(...a)
1058
1058
  });
@@ -1066,7 +1066,7 @@ var Peer = class {
1066
1066
  remoteId: this.id
1067
1067
  }, {
1068
1068
  F: __dxlog_file3,
1069
- L: 227,
1069
+ L: 226,
1070
1070
  S: this,
1071
1071
  C: (f, a) => f(...a)
1072
1072
  });
@@ -1074,7 +1074,7 @@ var Peer = class {
1074
1074
  err
1075
1075
  }, {
1076
1076
  F: __dxlog_file3,
1077
- L: 234,
1077
+ L: 233,
1078
1078
  S: this,
1079
1079
  C: (f, a) => f(...a)
1080
1080
  });
@@ -1097,13 +1097,13 @@ var Peer = class {
1097
1097
  sessionId
1098
1098
  }, {
1099
1099
  F: __dxlog_file3,
1100
- L: 248,
1100
+ L: 247,
1101
1101
  S: this,
1102
1102
  C: (f, a) => f(...a)
1103
1103
  });
1104
1104
  invariant3(!this.connection, "Already connected.", {
1105
1105
  F: __dxlog_file3,
1106
- L: 255,
1106
+ L: 254,
1107
1107
  S: this,
1108
1108
  A: [
1109
1109
  "!this.connection",
@@ -1139,7 +1139,7 @@ var Peer = class {
1139
1139
  initiator
1140
1140
  }, {
1141
1141
  F: __dxlog_file3,
1142
- L: 274,
1142
+ L: 273,
1143
1143
  S: this,
1144
1144
  C: (f, a) => f(...a)
1145
1145
  });
@@ -1152,14 +1152,14 @@ var Peer = class {
1152
1152
  initiator
1153
1153
  }, {
1154
1154
  F: __dxlog_file3,
1155
- L: 283,
1155
+ L: 282,
1156
1156
  S: this,
1157
1157
  C: (f, a) => f(...a)
1158
1158
  });
1159
1159
  this._connectionLimiter.doneConnecting(sessionId);
1160
1160
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1161
1161
  F: __dxlog_file3,
1162
- L: 288,
1162
+ L: 287,
1163
1163
  S: this,
1164
1164
  A: [
1165
1165
  "this.connection === connection",
@@ -1174,7 +1174,7 @@ var Peer = class {
1174
1174
  initiator
1175
1175
  }, {
1176
1176
  F: __dxlog_file3,
1177
- L: 290,
1177
+ L: 289,
1178
1178
  S: this,
1179
1179
  C: (f, a) => f(...a)
1180
1180
  });
@@ -1209,7 +1209,7 @@ var Peer = class {
1209
1209
  err
1210
1210
  }, {
1211
1211
  F: __dxlog_file3,
1212
- L: 330,
1212
+ L: 329,
1213
1213
  S: this,
1214
1214
  C: (f, a) => f(...a)
1215
1215
  });
@@ -1222,7 +1222,7 @@ var Peer = class {
1222
1222
  err
1223
1223
  }, {
1224
1224
  F: __dxlog_file3,
1225
- L: 337,
1225
+ L: 336,
1226
1226
  S: this,
1227
1227
  C: (f, a) => f(...a)
1228
1228
  });
@@ -1241,7 +1241,7 @@ var Peer = class {
1241
1241
  sessionId: connection.sessionId
1242
1242
  }, {
1243
1243
  F: __dxlog_file3,
1244
- L: 362,
1244
+ L: 361,
1245
1245
  S: this,
1246
1246
  C: (f, a) => f(...a)
1247
1247
  });
@@ -1251,7 +1251,7 @@ var Peer = class {
1251
1251
  sessionId: connection.sessionId
1252
1252
  }, {
1253
1253
  F: __dxlog_file3,
1254
- L: 368,
1254
+ L: 367,
1255
1255
  S: this,
1256
1256
  C: (f, a) => f(...a)
1257
1257
  });
@@ -1262,7 +1262,7 @@ var Peer = class {
1262
1262
  message
1263
1263
  }, {
1264
1264
  F: __dxlog_file3,
1265
- L: 373,
1265
+ L: 372,
1266
1266
  S: this,
1267
1267
  C: (f, a) => f(...a)
1268
1268
  });
@@ -1277,7 +1277,7 @@ var Peer = class {
1277
1277
  topic: this.topic
1278
1278
  }, {
1279
1279
  F: __dxlog_file3,
1280
- L: 383,
1280
+ L: 382,
1281
1281
  S: this,
1282
1282
  C: (f, a) => f(...a)
1283
1283
  });
@@ -2619,32 +2619,26 @@ var createStreamDelay = (delay) => {
2619
2619
  });
2620
2620
  };
2621
2621
  var MemoryTransportFactory = {
2622
- createTransport: (params) => new MemoryTransport(params)
2622
+ createTransport: (options) => new MemoryTransport(options)
2623
2623
  };
2624
2624
  var MemoryTransport = class _MemoryTransport {
2625
2625
  static {
2626
2626
  // TODO(burdon): Remove static properties (inject context into constructor).
2627
2627
  this._connections = new ComplexMap7(PublicKey9.hash);
2628
2628
  }
2629
- constructor(options) {
2630
- this.options = options;
2631
- this.closed = new Event7();
2632
- this.connected = new Event7();
2633
- this.errors = new ErrorStream3();
2629
+ constructor(_options) {
2630
+ this._options = _options;
2634
2631
  this._instanceId = PublicKey9.random();
2635
2632
  this._remote = new Trigger();
2636
2633
  this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2637
2634
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2638
- this._destroyed = false;
2639
- log10("creating", void 0, {
2640
- F: __dxlog_file11,
2641
- L: 64,
2642
- S: this,
2643
- C: (f, a) => f(...a)
2644
- });
2635
+ this._closed = false;
2636
+ this.closed = new Event7();
2637
+ this.connected = new Event7();
2638
+ this.errors = new ErrorStream3();
2645
2639
  invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2646
2640
  F: __dxlog_file11,
2647
- L: 66,
2641
+ L: 64,
2648
2642
  S: this,
2649
2643
  A: [
2650
2644
  "!MemoryTransport._connections.has(this._instanceId)",
@@ -2652,41 +2646,52 @@ var MemoryTransport = class _MemoryTransport {
2652
2646
  ]
2653
2647
  });
2654
2648
  _MemoryTransport._connections.set(this._instanceId, this);
2655
- if (this.options.initiator) {
2656
- setTimeout(async () => {
2657
- log10("sending signal", void 0, {
2658
- F: __dxlog_file11,
2659
- L: 73,
2660
- S: this,
2661
- C: (f, a) => f(...a)
2662
- });
2663
- void this.options.sendSignal({
2649
+ }
2650
+ get isOpen() {
2651
+ return !this._closed;
2652
+ }
2653
+ async open() {
2654
+ log10("opening...", void 0, {
2655
+ F: __dxlog_file11,
2656
+ L: 74,
2657
+ S: this,
2658
+ C: (f, a) => f(...a)
2659
+ });
2660
+ if (this._options.initiator) {
2661
+ log10("sending signal", void 0, {
2662
+ F: __dxlog_file11,
2663
+ L: 78,
2664
+ S: this,
2665
+ C: (f, a) => f(...a)
2666
+ });
2667
+ try {
2668
+ await this._options.sendSignal({
2664
2669
  payload: {
2665
2670
  transportId: this._instanceId.toHex()
2666
2671
  }
2667
- }).catch((err) => {
2668
- if (!this._destroyed) {
2669
- this.errors.raise(err);
2670
- }
2671
2672
  });
2672
- });
2673
+ } catch (err) {
2674
+ if (!this._closed) {
2675
+ this.errors.raise(toError(err));
2676
+ }
2677
+ }
2673
2678
  } else {
2674
2679
  this._remote.wait({
2675
- timeout: this.options.timeout ?? 1e3
2680
+ timeout: this._options.timeout ?? 1e3
2676
2681
  }).then((remoteId) => {
2677
- if (this._destroyed) {
2682
+ if (this._closed) {
2678
2683
  return;
2679
2684
  }
2680
2685
  this._remoteInstanceId = remoteId;
2681
2686
  this._remoteConnection = _MemoryTransport._connections.get(this._remoteInstanceId);
2682
2687
  if (!this._remoteConnection) {
2683
- this._destroyed = true;
2688
+ this._closed = true;
2684
2689
  this.closed.emit();
2685
2690
  return;
2686
2691
  }
2687
2692
  invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
2688
2693
  F: __dxlog_file11,
2689
- L: 99,
2694
+ L: 104,
2690
2695
  S: this,
2691
2696
  A: [
2692
2697
  "!this._remoteConnection._remoteConnection",
@@ -2697,68 +2702,56 @@ var MemoryTransport = class _MemoryTransport {
2697
2702
  this._remoteConnection._remoteInstanceId = this._instanceId;
2698
2703
  log10("connected", void 0, {
2699
2704
  F: __dxlog_file11,
2700
- L: 103,
2705
+ L: 108,
2701
2706
  S: this,
2702
2707
  C: (f, a) => f(...a)
2703
2708
  });
2704
- this.options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection.options.stream).pipe(this._incomingDelay).pipe(this.options.stream);
2709
+ this._options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection._options.stream).pipe(this._incomingDelay).pipe(this._options.stream);
2705
2710
  this.connected.emit();
2706
2711
  this._remoteConnection.connected.emit();
2707
2712
  }).catch((err) => {
2708
- if (this._destroyed) {
2713
+ if (this._closed) {
2709
2714
  return;
2710
2715
  }
2711
2716
  this.errors.raise(err);
2712
2717
  });
2713
2718
  }
2714
2719
  }
2715
- async destroy() {
2716
- log10("closing", void 0, {
2720
+ async close() {
2721
+ log10("closing...", void 0, {
2717
2722
  F: __dxlog_file11,
2718
- L: 124,
2723
+ L: 129,
2719
2724
  S: this,
2720
2725
  C: (f, a) => f(...a)
2721
2726
  });
2722
- this._destroyed = true;
2727
+ this._closed = true;
2723
2728
  _MemoryTransport._connections.delete(this._instanceId);
2724
2729
  if (this._remoteConnection) {
2725
- log10("closing", void 0, {
2726
- F: __dxlog_file11,
2727
- L: 129,
2728
- S: this,
2729
- C: (f, a) => f(...a)
2730
- });
2731
- this._remoteConnection._destroyed = true;
2730
+ this._remoteConnection._closed = true;
2732
2731
  _MemoryTransport._connections.delete(this._remoteInstanceId);
2733
- this.options.stream.unpipe(this._incomingDelay);
2734
- this._incomingDelay.unpipe(this._remoteConnection.options.stream);
2735
- this._remoteConnection.options.stream.unpipe(this._outgoingDelay);
2736
- this._outgoingDelay.unpipe(this.options.stream);
2737
- this.options.stream.unpipe(this._outgoingDelay);
2732
+ this._options.stream.unpipe(this._incomingDelay);
2733
+ this._incomingDelay.unpipe(this._remoteConnection._options.stream);
2734
+ this._remoteConnection._options.stream.unpipe(this._outgoingDelay);
2735
+ this._outgoingDelay.unpipe(this._options.stream);
2736
+ this._options.stream.unpipe(this._outgoingDelay);
2738
2737
  this._remoteConnection.closed.emit();
2739
2738
  this._remoteConnection._remoteConnection = void 0;
2740
2739
  this._remoteConnection = void 0;
2741
- log10("closed", void 0, {
2742
- F: __dxlog_file11,
2743
- L: 150,
2744
- S: this,
2745
- C: (f, a) => f(...a)
2746
- });
2747
2740
  }
2748
2741
  this.closed.emit();
2749
2742
  log10("closed", void 0, {
2750
2743
  F: __dxlog_file11,
2751
- L: 154,
2744
+ L: 157,
2752
2745
  S: this,
2753
2746
  C: (f, a) => f(...a)
2754
2747
  });
2755
2748
  }
2756
- signal({ payload }) {
2749
+ async onSignal({ payload }) {
2757
2750
  log10("received signal", {
2758
2751
  payload
2759
2752
  }, {
2760
2753
  F: __dxlog_file11,
2761
- L: 158,
2754
+ L: 161,
2762
2755
  S: this,
2763
2756
  C: (f, a) => f(...a)
2764
2757
  });
@@ -2789,13 +2782,14 @@ _ts_decorate4([
2789
2782
  _ts_decorate4([
2790
2783
  logInfo3
2791
2784
  ], MemoryTransport.prototype, "_remoteInstanceId", void 0);
2785
+ var toError = (err) => err instanceof Error ? err : new Error(String(err));
2792
2786
 
2793
2787
  // packages/core/mesh/network-manager/src/transport/transport.ts
2794
2788
  var TransportKind;
2795
2789
  (function(TransportKind2) {
2796
2790
  TransportKind2["SIMPLE_PEER"] = "SIMPLE_PEER";
2797
- TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
2798
2791
  TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
2792
+ TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
2799
2793
  TransportKind2["MEMORY"] = "MEMORY";
2800
2794
  TransportKind2["TCP"] = "TCP";
2801
2795
  })(TransportKind || (TransportKind = {}));
@@ -2818,12 +2812,21 @@ try {
2818
2812
 
2819
2813
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2820
2814
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2815
+ var createSimplePeerTransportFactory = (webrtcConfig) => ({
2816
+ createTransport: (options) => new SimplePeerTransport({
2817
+ ...options,
2818
+ webrtcConfig
2819
+ })
2820
+ });
2821
2821
  var SimplePeerTransport = class {
2822
+ get isOpen() {
2823
+ return this._piped && !this._closed;
2824
+ }
2822
2825
  /**
2823
2826
  * @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
2824
2827
  */
2825
- constructor(params) {
2826
- this.params = params;
2828
+ constructor(_params) {
2829
+ this._params = _params;
2827
2830
  this._closed = false;
2828
2831
  this._piped = false;
2829
2832
  this.closed = new Event8();
@@ -2834,30 +2837,30 @@ var SimplePeerTransport = class {
2834
2837
  id: this._instanceId
2835
2838
  }), {
2836
2839
  F: __dxlog_file12,
2837
- L: 44,
2840
+ L: 50,
2838
2841
  S: this,
2839
2842
  C: (f, a) => f(...a)
2840
2843
  });
2841
- log11("created connection", params, {
2844
+ log11("created connection", _params, {
2842
2845
  F: __dxlog_file12,
2843
- L: 45,
2846
+ L: 51,
2844
2847
  S: this,
2845
2848
  C: (f, a) => f(...a)
2846
2849
  });
2847
2850
  this._peer = new SimplePeerConstructor({
2848
2851
  channelName: "dxos.mesh.transport",
2849
- initiator: this.params.initiator,
2852
+ initiator: this._params.initiator,
2850
2853
  wrtc: SimplePeerConstructor.WEBRTC_SUPPORT ? void 0 : wrtc ?? raise2(new Error("wrtc not available")),
2851
- config: this.params.webrtcConfig
2854
+ config: this._params.webrtcConfig
2852
2855
  });
2853
2856
  this._peer.on("signal", async (data) => {
2854
2857
  log11("signal", data, {
2855
2858
  F: __dxlog_file12,
2856
- L: 54,
2859
+ L: 60,
2857
2860
  S: this,
2858
2861
  C: (f, a) => f(...a)
2859
2862
  });
2860
- await this.params.sendSignal({
2863
+ await this._params.sendSignal({
2861
2864
  payload: {
2862
2865
  data
2863
2866
  }
@@ -2866,22 +2869,22 @@ var SimplePeerTransport = class {
2866
2869
  this._peer.on("connect", () => {
2867
2870
  log11("connected", void 0, {
2868
2871
  F: __dxlog_file12,
2869
- L: 59,
2872
+ L: 65,
2870
2873
  S: this,
2871
2874
  C: (f, a) => f(...a)
2872
2875
  });
2873
- this.params.stream.pipe(this._peer).pipe(this.params.stream);
2876
+ this._params.stream.pipe(this._peer).pipe(this._params.stream);
2874
2877
  this._piped = true;
2875
2878
  this.connected.emit();
2876
2879
  });
2877
2880
  this._peer.on("close", async () => {
2878
2881
  log11("closed", void 0, {
2879
2882
  F: __dxlog_file12,
2880
- L: 66,
2883
+ L: 72,
2881
2884
  S: this,
2882
2885
  C: (f, a) => f(...a)
2883
2886
  });
2884
- await this.destroy();
2887
+ await this.close();
2885
2888
  });
2886
2889
  this._peer.on("error", async (err) => {
2887
2890
  if (typeof RTCError !== "undefined" && err instanceof RTCError) {
@@ -2892,7 +2895,7 @@ var SimplePeerTransport = class {
2892
2895
  err
2893
2896
  }, {
2894
2897
  F: __dxlog_file12,
2895
- L: 77,
2898
+ L: 83,
2896
2899
  S: this,
2897
2900
  C: (f, a) => f(...a)
2898
2901
  });
@@ -2901,7 +2904,7 @@ var SimplePeerTransport = class {
2901
2904
  } else if ("code" in err) {
2902
2905
  log11.info("simple-peer error", err, {
2903
2906
  F: __dxlog_file12,
2904
- L: 82,
2907
+ L: 88,
2905
2908
  S: this,
2906
2909
  C: (f, a) => f(...a)
2907
2910
  });
@@ -2931,7 +2934,7 @@ var SimplePeerTransport = class {
2931
2934
  } else {
2932
2935
  log11.info("unknown peer connection error", err, {
2933
2936
  F: __dxlog_file12,
2934
- L: 108,
2937
+ L: 114,
2935
2938
  S: this,
2936
2939
  C: (f, a) => f(...a)
2937
2940
  });
@@ -2941,11 +2944,11 @@ var SimplePeerTransport = class {
2941
2944
  if (typeof this._peer?._pc?.getStats === "function") {
2942
2945
  this._peer._pc.getStats().then((stats) => {
2943
2946
  log11.info("report after webrtc error", {
2944
- config: this.params.webrtcConfig,
2947
+ config: this._params.webrtcConfig,
2945
2948
  stats: Object.fromEntries(stats.entries())
2946
2949
  }, {
2947
2950
  F: __dxlog_file12,
2948
- L: 116,
2951
+ L: 122,
2949
2952
  S: this,
2950
2953
  C: (f, a) => f(...a)
2951
2954
  });
@@ -2954,18 +2957,18 @@ var SimplePeerTransport = class {
2954
2957
  } catch (err2) {
2955
2958
  log11.catch(err2, void 0, {
2956
2959
  F: __dxlog_file12,
2957
- L: 123,
2960
+ L: 129,
2958
2961
  S: this,
2959
2962
  C: (f, a) => f(...a)
2960
2963
  });
2961
2964
  }
2962
- await this.destroy();
2965
+ await this.close();
2963
2966
  });
2964
2967
  log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.end({
2965
2968
  id: this._instanceId
2966
2969
  }), {
2967
2970
  F: __dxlog_file12,
2968
- L: 129,
2971
+ L: 135,
2969
2972
  S: this,
2970
2973
  C: (f, a) => f(...a)
2971
2974
  });
@@ -3023,10 +3026,12 @@ var SimplePeerTransport = class {
3023
3026
  }
3024
3027
  return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
3025
3028
  }
3026
- async destroy() {
3029
+ async open() {
3030
+ }
3031
+ async close() {
3027
3032
  log11("closing...", void 0, {
3028
3033
  F: __dxlog_file12,
3029
- L: 192,
3034
+ L: 200,
3030
3035
  S: this,
3031
3036
  C: (f, a) => f(...a)
3032
3037
  });
@@ -3039,12 +3044,12 @@ var SimplePeerTransport = class {
3039
3044
  this.closed.emit();
3040
3045
  log11("closed", void 0, {
3041
3046
  F: __dxlog_file12,
3042
- L: 200,
3047
+ L: 208,
3043
3048
  S: this,
3044
3049
  C: (f, a) => f(...a)
3045
3050
  });
3046
3051
  }
3047
- signal(signal) {
3052
+ async onSignal(signal) {
3048
3053
  if (this._closed) {
3049
3054
  return;
3050
3055
  }
@@ -3053,16 +3058,10 @@ var SimplePeerTransport = class {
3053
3058
  }
3054
3059
  _disconnectStreams() {
3055
3060
  if (this._piped) {
3056
- this.params.stream.unpipe?.(this._peer)?.unpipe?.(this.params.stream);
3061
+ this._params.stream.unpipe?.(this._peer)?.unpipe?.(this._params.stream);
3057
3062
  }
3058
3063
  }
3059
3064
  };
3060
- var createSimplePeerTransportFactory = (webrtcConfig) => ({
3061
- createTransport: (params) => new SimplePeerTransport({
3062
- ...params,
3063
- webrtcConfig
3064
- })
3065
- });
3066
3065
 
3067
3066
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts
3068
3067
  import { Duplex } from "@dxos/node-std/stream";
@@ -3111,6 +3110,7 @@ var SimplePeerTransportService = class {
3111
3110
  });
3112
3111
  }
3113
3112
  });
3113
+ void transport.open();
3114
3114
  next({
3115
3115
  connection: {
3116
3116
  state: ConnectionState3.CONNECTING
@@ -3154,19 +3154,19 @@ var SimplePeerTransportService = class {
3154
3154
  async sendSignal({ proxyId, signal }) {
3155
3155
  invariant12(this.transports.has(proxyId), void 0, {
3156
3156
  F: __dxlog_file13,
3157
- L: 116,
3157
+ L: 119,
3158
3158
  S: this,
3159
3159
  A: [
3160
3160
  "this.transports.has(proxyId)",
3161
3161
  ""
3162
3162
  ]
3163
3163
  });
3164
- await this.transports.get(proxyId).transport.signal(signal);
3164
+ await this.transports.get(proxyId).transport.onSignal(signal);
3165
3165
  }
3166
3166
  async getDetails({ proxyId }) {
3167
3167
  invariant12(this.transports.has(proxyId), void 0, {
3168
3168
  F: __dxlog_file13,
3169
- L: 121,
3169
+ L: 124,
3170
3170
  S: this,
3171
3171
  A: [
3172
3172
  "this.transports.has(proxyId)",
@@ -3180,7 +3180,7 @@ var SimplePeerTransportService = class {
3180
3180
  async getStats({ proxyId }) {
3181
3181
  invariant12(this.transports.has(proxyId), void 0, {
3182
3182
  F: __dxlog_file13,
3183
- L: 126,
3183
+ L: 129,
3184
3184
  S: this,
3185
3185
  A: [
3186
3186
  "this.transports.has(proxyId)",
@@ -3195,14 +3195,14 @@ var SimplePeerTransportService = class {
3195
3195
  if (this.transports.get(proxyId)?.state !== "OPEN") {
3196
3196
  log12.debug("transport is closed", void 0, {
3197
3197
  F: __dxlog_file13,
3198
- L: 132,
3198
+ L: 135,
3199
3199
  S: this,
3200
3200
  C: (f, a) => f(...a)
3201
3201
  });
3202
3202
  }
3203
3203
  invariant12(this.transports.has(proxyId), void 0, {
3204
3204
  F: __dxlog_file13,
3205
- L: 134,
3205
+ L: 137,
3206
3206
  S: this,
3207
3207
  A: [
3208
3208
  "this.transports.has(proxyId)",
@@ -3218,14 +3218,14 @@ var SimplePeerTransportService = class {
3218
3218
  }
3219
3219
  }
3220
3220
  async close({ proxyId }) {
3221
- await this.transports.get(proxyId)?.transport.destroy();
3221
+ await this.transports.get(proxyId)?.transport.close();
3222
3222
  await this.transports.get(proxyId)?.stream.end();
3223
3223
  if (this.transports.get(proxyId)) {
3224
3224
  this.transports.get(proxyId).state = "CLOSED";
3225
3225
  }
3226
3226
  log12("Closed.", void 0, {
3227
3227
  F: __dxlog_file13,
3228
- L: 150,
3228
+ L: 153,
3229
3229
  S: this,
3230
3230
  C: (f, a) => f(...a)
3231
3231
  });
@@ -3248,8 +3248,8 @@ var RPC_TIMEOUT = 1e4;
3248
3248
  var RESP_MIN_THRESHOLD = 500;
3249
3249
  var TIMEOUT_THRESHOLD = 10;
3250
3250
  var SimplePeerTransportProxy = class {
3251
- constructor(_params) {
3252
- this._params = _params;
3251
+ constructor(_options) {
3252
+ this._options = _options;
3253
3253
  this._proxyId = PublicKey12.random();
3254
3254
  this._ctx = new Context6();
3255
3255
  this._timeoutCount = 0;
@@ -3257,9 +3257,14 @@ var SimplePeerTransportProxy = class {
3257
3257
  this.connected = new Event9();
3258
3258
  this.errors = new ErrorStream5();
3259
3259
  this._closed = false;
3260
- this._serviceStream = this._params.bridgeService.open({
3260
+ }
3261
+ get isOpen() {
3262
+ return !this._closed;
3263
+ }
3264
+ async open() {
3265
+ this._serviceStream = this._options.bridgeService.open({
3261
3266
  proxyId: this._proxyId,
3262
- initiator: this._params.initiator
3267
+ initiator: this._options.initiator
3263
3268
  }, {
3264
3269
  timeout: RPC_TIMEOUT
3265
3270
  });
@@ -3267,7 +3272,7 @@ var SimplePeerTransportProxy = class {
3267
3272
  this._serviceStream.subscribe(async (event) => {
3268
3273
  log13("SimplePeerTransportProxy: event", event, {
3269
3274
  F: __dxlog_file14,
3270
- L: 63,
3275
+ L: 66,
3271
3276
  S: this,
3272
3277
  C: (f, a) => f(...a)
3273
3278
  });
@@ -3282,7 +3287,7 @@ var SimplePeerTransportProxy = class {
3282
3287
  const proxyStream = new Writable({
3283
3288
  write: (chunk, _, callback) => {
3284
3289
  const then = performance.now();
3285
- this._params.bridgeService.sendData({
3290
+ this._options.bridgeService.sendData({
3286
3291
  proxyId: this._proxyId,
3287
3292
  payload: chunk
3288
3293
  }, {
@@ -3291,7 +3296,7 @@ var SimplePeerTransportProxy = class {
3291
3296
  if (performance.now() - then > RESP_MIN_THRESHOLD) {
3292
3297
  log13("slow response, delaying callback", void 0, {
3293
3298
  F: __dxlog_file14,
3294
- L: 87,
3299
+ L: 90,
3295
3300
  S: this,
3296
3301
  C: (f, a) => f(...a)
3297
3302
  });
@@ -3307,7 +3312,7 @@ var SimplePeerTransportProxy = class {
3307
3312
  } else {
3308
3313
  log13("timeout error, but still invoking callback", void 0, {
3309
3314
  F: __dxlog_file14,
3310
- L: 99,
3315
+ L: 102,
3311
3316
  S: this,
3312
3317
  C: (f, a) => f(...a)
3313
3318
  });
@@ -3316,7 +3321,7 @@ var SimplePeerTransportProxy = class {
3316
3321
  } else {
3317
3322
  log13.catch(err, void 0, {
3318
3323
  F: __dxlog_file14,
3319
- L: 103,
3324
+ L: 106,
3320
3325
  S: this,
3321
3326
  C: (f, a) => f(...a)
3322
3327
  });
@@ -3329,19 +3334,50 @@ var SimplePeerTransportProxy = class {
3329
3334
  err
3330
3335
  }, {
3331
3336
  F: __dxlog_file14,
3332
- L: 111,
3337
+ L: 114,
3333
3338
  S: this,
3334
3339
  C: (f, a) => f(...a)
3335
3340
  });
3336
3341
  });
3337
- this._params.stream.pipe(proxyStream);
3342
+ this._options.stream.pipe(proxyStream);
3338
3343
  }, (error) => log13.catch(error, void 0, {
3339
3344
  F: __dxlog_file14,
3340
- L: 116,
3345
+ L: 119,
3341
3346
  S: this,
3342
3347
  C: (f, a) => f(...a)
3343
3348
  }));
3344
3349
  }
3350
+ async close() {
3351
+ await this._ctx.dispose();
3352
+ if (this._closed) {
3353
+ return;
3354
+ }
3355
+ await this._serviceStream.close();
3356
+ try {
3357
+ await this._options.bridgeService.close({
3358
+ proxyId: this._proxyId
3359
+ }, {
3360
+ timeout: RPC_TIMEOUT
3361
+ });
3362
+ } catch (err) {
3363
+ log13.catch(err, void 0, {
3364
+ F: __dxlog_file14,
3365
+ L: 134,
3366
+ S: this,
3367
+ C: (f, a) => f(...a)
3368
+ });
3369
+ }
3370
+ this.closed.emit();
3371
+ this._closed = true;
3372
+ }
3373
+ async onSignal(signal) {
3374
+ this._options.bridgeService.sendSignal({
3375
+ proxyId: this._proxyId,
3376
+ signal
3377
+ }, {
3378
+ timeout: RPC_TIMEOUT
3379
+ }).catch((err) => this.errors.raise(decodeError(err)));
3380
+ }
3345
3381
  async _handleConnection(connectionEvent) {
3346
3382
  if (connectionEvent.error) {
3347
3383
  this.errors.raise(decodeError(connectionEvent.error));
@@ -3352,63 +3388,31 @@ var SimplePeerTransportProxy = class {
3352
3388
  break;
3353
3389
  }
3354
3390
  case ConnectionState4.CLOSED: {
3355
- await this.destroy();
3391
+ await this.close();
3356
3392
  break;
3357
3393
  }
3358
3394
  }
3359
3395
  }
3360
3396
  _handleData(dataEvent) {
3361
- this._params.stream.write(arrayToBuffer(dataEvent.payload));
3397
+ this._options.stream.write(arrayToBuffer(dataEvent.payload));
3362
3398
  }
3363
3399
  async _handleSignal(signalEvent) {
3364
- await this._params.sendSignal(signalEvent.payload);
3365
- }
3366
- signal(signal) {
3367
- this._params.bridgeService.sendSignal({
3368
- proxyId: this._proxyId,
3369
- signal
3370
- }, {
3371
- timeout: RPC_TIMEOUT
3372
- }).catch((err) => this.errors.raise(decodeError(err)));
3400
+ await this._options.sendSignal(signalEvent.payload);
3373
3401
  }
3374
3402
  async getDetails() {
3375
- return (await this._params.bridgeService.getDetails({
3403
+ return (await this._options.bridgeService.getDetails({
3376
3404
  proxyId: this._proxyId
3377
3405
  }, {
3378
3406
  timeout: RPC_TIMEOUT
3379
3407
  })).details;
3380
3408
  }
3381
3409
  async getStats() {
3382
- return (await this._params.bridgeService.getStats({
3410
+ return (await this._options.bridgeService.getStats({
3383
3411
  proxyId: this._proxyId
3384
3412
  }, {
3385
3413
  timeout: RPC_TIMEOUT
3386
3414
  })).stats;
3387
3415
  }
3388
- // TODO(burdon): Move open from constructor.
3389
- async destroy() {
3390
- await this._ctx.dispose();
3391
- if (this._closed) {
3392
- return;
3393
- }
3394
- await this._serviceStream.close();
3395
- try {
3396
- await this._params.bridgeService.close({
3397
- proxyId: this._proxyId
3398
- }, {
3399
- timeout: RPC_TIMEOUT
3400
- });
3401
- } catch (err) {
3402
- log13.catch(err, void 0, {
3403
- F: __dxlog_file14,
3404
- L: 179,
3405
- S: this,
3406
- C: (f, a) => f(...a)
3407
- });
3408
- }
3409
- this.closed.emit();
3410
- this._closed = true;
3411
- }
3412
3416
  /**
3413
3417
  * Called when underlying proxy service becomes unavailable.
3414
3418
  */
@@ -3437,7 +3441,7 @@ var SimplePeerTransportProxyFactory = class {
3437
3441
  createTransport(options) {
3438
3442
  invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3439
3443
  F: __dxlog_file14,
3440
- L: 216,
3444
+ L: 218,
3441
3445
  S: this,
3442
3446
  A: [
3443
3447
  "this._bridgeService",
@@ -3474,6 +3478,7 @@ var decodeError = (err) => {
3474
3478
  import { Duplex as Duplex2 } from "stream";
3475
3479
  import { Event as Event10, Trigger as Trigger2, synchronized as synchronized4 } from "@dxos/async";
3476
3480
  import { ErrorStream as ErrorStream6 } from "@dxos/debug";
3481
+ import { invariant as invariant14 } from "@dxos/invariant";
3477
3482
  import { log as log14 } from "@dxos/log";
3478
3483
  function _ts_decorate5(decorators, target, key, desc) {
3479
3484
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3489,163 +3494,203 @@ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-man
3489
3494
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
3490
3495
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3491
3496
  var MAX_MESSAGE_SIZE = 64 * 1024;
3497
+ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
3498
+ createTransport: (options) => new LibDataChannelTransport({
3499
+ ...options,
3500
+ webrtcConfig
3501
+ })
3502
+ });
3492
3503
  var LibDataChannelTransport = class _LibDataChannelTransport {
3493
3504
  static {
3494
3505
  this._instanceCount = 0;
3495
3506
  }
3496
- constructor(params) {
3497
- this.params = params;
3507
+ constructor(_options) {
3508
+ this._options = _options;
3498
3509
  this._closed = false;
3499
- this.closed = new Event10();
3500
3510
  this._connected = false;
3511
+ this._writeCallback = null;
3512
+ this._readyForCandidates = new Trigger2();
3513
+ this.closed = new Event10();
3501
3514
  this.connected = new Event10();
3502
3515
  this.errors = new ErrorStream6();
3503
- this._readyForCandidates = new Trigger2();
3504
- this._writeCallback = null;
3505
- this._peer = (async () => {
3506
- const { RTCPeerConnection } = (await importESM("node-datachannel/polyfill")).default;
3507
- if (this._closed) {
3508
- this.errors.raise(new Error("connection already closed"));
3509
- }
3510
- if (params.webrtcConfig) {
3511
- params.webrtcConfig.iceServers = params.webrtcConfig.iceServers ?? [];
3512
- } else {
3513
- params.webrtcConfig = {
3514
- iceServers: []
3515
- };
3516
+ }
3517
+ get isOpen() {
3518
+ return !!this._peer && !this._closed;
3519
+ }
3520
+ async open() {
3521
+ if (this._closed) {
3522
+ this.errors.raise(new Error("connection already closed"));
3523
+ }
3524
+ const { RTCPeerConnection } = (await importESM("node-datachannel/polyfill")).default;
3525
+ if (this._options.webrtcConfig) {
3526
+ this._options.webrtcConfig.iceServers = this._options.webrtcConfig.iceServers ?? [];
3527
+ } else {
3528
+ this._options.webrtcConfig = {
3529
+ iceServers: []
3530
+ };
3531
+ }
3532
+ this._peer = new RTCPeerConnection(this._options.webrtcConfig);
3533
+ this._peer.onicecandidateerror = (event) => {
3534
+ log14.error("peer.onicecandidateerror", {
3535
+ event
3536
+ }, {
3537
+ F: __dxlog_file15,
3538
+ L: 77,
3539
+ S: this,
3540
+ C: (f, a) => f(...a)
3541
+ });
3542
+ };
3543
+ this._peer.onconnectionstatechange = (event) => {
3544
+ log14.debug("peer.onconnectionstatechange", {
3545
+ event,
3546
+ peerConnectionState: this._peer?.connectionState,
3547
+ transportConnectionState: this._connected
3548
+ }, {
3549
+ F: __dxlog_file15,
3550
+ L: 81,
3551
+ S: this,
3552
+ C: (f, a) => f(...a)
3553
+ });
3554
+ };
3555
+ this._peer.onicecandidate = async (event) => {
3556
+ log14.debug("peer.onicecandidate", {
3557
+ event
3558
+ }, {
3559
+ F: __dxlog_file15,
3560
+ L: 91,
3561
+ S: this,
3562
+ C: (f, a) => f(...a)
3563
+ });
3564
+ if (event.candidate) {
3565
+ try {
3566
+ await this._options.sendSignal({
3567
+ payload: {
3568
+ data: {
3569
+ type: "candidate",
3570
+ candidate: {
3571
+ candidate: event.candidate.candidate,
3572
+ // These fields never seem to be not null, but connecting to Chrome doesn't work if they are.
3573
+ sdpMLineIndex: event.candidate.sdpMLineIndex ?? 0,
3574
+ sdpMid: event.candidate.sdpMid ?? 0
3575
+ }
3576
+ }
3577
+ }
3578
+ });
3579
+ } catch (err) {
3580
+ log14.info("signaling error", {
3581
+ err
3582
+ }, {
3583
+ F: __dxlog_file15,
3584
+ L: 108,
3585
+ S: this,
3586
+ C: (f, a) => f(...a)
3587
+ });
3588
+ }
3516
3589
  }
3517
- const peer = new RTCPeerConnection(params.webrtcConfig);
3518
- _LibDataChannelTransport._instanceCount++;
3519
- peer.onicecandidateerror = (event) => {
3520
- log14.error("peer.onicecandidateerror", {
3521
- event
3590
+ };
3591
+ if (this._options.initiator) {
3592
+ invariant14(this._peer, "not open", {
3593
+ F: __dxlog_file15,
3594
+ L: 114,
3595
+ S: this,
3596
+ A: [
3597
+ "this._peer",
3598
+ "'not open'"
3599
+ ]
3600
+ });
3601
+ this._peer.createOffer().then(async (offer) => {
3602
+ if (this._closed) {
3603
+ return;
3604
+ }
3605
+ if (this._peer?.connectionState !== "connecting") {
3606
+ log14.error("peer not connecting", {
3607
+ peer: this._peer
3608
+ }, {
3609
+ F: __dxlog_file15,
3610
+ L: 125,
3611
+ S: this,
3612
+ C: (f, a) => f(...a)
3613
+ });
3614
+ this.errors.raise(new Error("invalid state: peer is initiator, but other peer not in state connecting"));
3615
+ }
3616
+ log14.debug("creating offer", {
3617
+ peer: this._peer,
3618
+ offer
3522
3619
  }, {
3523
3620
  F: __dxlog_file15,
3524
- L: 63,
3621
+ L: 129,
3525
3622
  S: this,
3526
3623
  C: (f, a) => f(...a)
3527
3624
  });
3528
- };
3529
- peer.onconnectionstatechange = (event) => {
3530
- log14.debug("peer.onconnectionstatechange", {
3531
- event,
3532
- peerConnectionState: peer.connectionState,
3533
- transportConnectionState: this._connected
3534
- }, {
3535
- F: __dxlog_file15,
3536
- L: 67,
3537
- S: this,
3538
- C: (f, a) => f(...a)
3625
+ await this._peer.setLocalDescription(offer);
3626
+ await this._options.sendSignal({
3627
+ payload: {
3628
+ data: {
3629
+ type: offer.type,
3630
+ sdp: offer.sdp
3631
+ }
3632
+ }
3539
3633
  });
3634
+ }).catch((err) => {
3635
+ this.errors.raise(err);
3636
+ });
3637
+ this._handleChannel(this._peer.createDataChannel(DATACHANNEL_LABEL));
3638
+ log14.debug("created data channel", void 0, {
3639
+ F: __dxlog_file15,
3640
+ L: 139,
3641
+ S: this,
3642
+ C: (f, a) => f(...a)
3643
+ });
3644
+ this._peer.ondatachannel = () => {
3645
+ this.errors.raise(new Error("unexpected ondatachannel event for initiator"));
3540
3646
  };
3541
- peer.onicecandidate = async (event) => {
3542
- log14.debug("peer.onicecandidate", {
3647
+ } else {
3648
+ this._peer.ondatachannel = (event) => {
3649
+ log14.debug("peer.ondatachannel (non-initiator)", {
3543
3650
  event
3544
3651
  }, {
3545
3652
  F: __dxlog_file15,
3546
- L: 76,
3653
+ L: 145,
3547
3654
  S: this,
3548
3655
  C: (f, a) => f(...a)
3549
3656
  });
3550
- if (event.candidate) {
3551
- try {
3552
- await params.sendSignal({
3553
- payload: {
3554
- data: {
3555
- type: "candidate",
3556
- candidate: {
3557
- candidate: event.candidate.candidate,
3558
- // these fields never seem to be not null, but connecting to Chrome doesn't work if they are
3559
- sdpMLineIndex: event.candidate.sdpMLineIndex ?? 0,
3560
- sdpMid: event.candidate.sdpMid ?? 0
3561
- }
3562
- }
3563
- }
3564
- });
3565
- } catch (err) {
3566
- log14.info("signaling errror", {
3567
- err
3568
- }, {
3569
- F: __dxlog_file15,
3570
- L: 93,
3571
- S: this,
3572
- C: (f, a) => f(...a)
3573
- });
3574
- }
3657
+ if (event.channel.label !== DATACHANNEL_LABEL) {
3658
+ this.errors.raise(new Error(`unexpected channel label ${event.channel.label}`));
3575
3659
  }
3660
+ this._handleChannel(event.channel);
3576
3661
  };
3577
- if (params.initiator) {
3578
- peer.createOffer().then(async (offer) => {
3579
- if (this._closed) {
3580
- return;
3581
- }
3582
- if (peer.connectionState !== "connecting") {
3583
- log14.error("i am initiator but peer not in state connecting", {
3584
- peer
3585
- }, {
3586
- F: __dxlog_file15,
3587
- L: 106,
3588
- S: this,
3589
- C: (f, a) => f(...a)
3590
- });
3591
- this.errors.raise(new Error("invalid state: peer is initiator, but other peer not in state connecting"));
3592
- }
3593
- log14.debug(`im the initiator, creating offer, peer is in state ${peer.connectionState}`, {
3594
- offer
3595
- }, {
3596
- F: __dxlog_file15,
3597
- L: 109,
3598
- S: this,
3599
- C: (f, a) => f(...a)
3600
- });
3601
- await peer.setLocalDescription(offer);
3602
- await params.sendSignal({
3603
- payload: {
3604
- data: {
3605
- type: offer.type,
3606
- sdp: offer.sdp
3607
- }
3608
- }
3609
- });
3610
- return offer;
3611
- }).catch((err) => {
3612
- this.errors.raise(err);
3613
- });
3614
- this.handleChannel(peer.createDataChannel(DATACHANNEL_LABEL));
3615
- log14.debug("created data channel", void 0, {
3616
- F: __dxlog_file15,
3617
- L: 118,
3618
- S: this,
3619
- C: (f, a) => f(...a)
3620
- });
3621
- peer.ondatachannel = (event) => {
3622
- this.errors.raise(new Error("got ondatachannel when i am the initiator?"));
3623
- };
3624
- } else {
3625
- peer.ondatachannel = (event) => {
3626
- log14.debug("peer.ondatachannel (non-initiator)", {
3627
- event
3628
- }, {
3629
- F: __dxlog_file15,
3630
- L: 124,
3631
- S: this,
3632
- C: (f, a) => f(...a)
3633
- });
3634
- if (event.channel.label !== DATACHANNEL_LABEL) {
3635
- this.errors.raise(new Error(`unexpected channel label ${event.channel.label}`));
3636
- }
3637
- this.handleChannel(event.channel);
3638
- };
3639
- }
3640
- return peer;
3641
- })();
3662
+ }
3663
+ _LibDataChannelTransport._instanceCount++;
3664
+ }
3665
+ async close() {
3666
+ await this._close();
3667
+ if (--_LibDataChannelTransport._instanceCount === 0) {
3668
+ (await importESM("node-datachannel")).cleanup();
3669
+ }
3642
3670
  }
3643
- handleChannel(dataChannel) {
3671
+ async _close() {
3672
+ if (this._closed) {
3673
+ return;
3674
+ }
3675
+ await this._disconnectStreams();
3676
+ try {
3677
+ this._peer?.close();
3678
+ } catch (err) {
3679
+ this.errors.raise(err);
3680
+ }
3681
+ this._peer = void 0;
3682
+ this._closed = true;
3683
+ this.closed.emit();
3684
+ }
3685
+ /**
3686
+ * Handle data channel events.
3687
+ */
3688
+ _handleChannel(dataChannel) {
3644
3689
  this._channel = dataChannel;
3645
3690
  this._channel.onopen = () => {
3646
- log14.debug("dataChannel.onopen", void 0, {
3691
+ log14.debug("channel.onopen", void 0, {
3647
3692
  F: __dxlog_file15,
3648
- L: 140,
3693
+ L: 190,
3649
3694
  S: this,
3650
3695
  C: (f, a) => f(...a)
3651
3696
  });
@@ -3664,9 +3709,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3664
3709
  }
3665
3710
  if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3666
3711
  if (this._writeCallback !== null) {
3667
- log14.error("consumer trying to write before we're ready for more data", void 0, {
3712
+ log14.error("consumer trying to write before we are ready for more data", void 0, {
3668
3713
  F: __dxlog_file15,
3669
- L: 157,
3714
+ L: 207,
3670
3715
  S: this,
3671
3716
  C: (f, a) => f(...a)
3672
3717
  });
@@ -3677,26 +3722,31 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3677
3722
  }
3678
3723
  }
3679
3724
  });
3680
- duplex.pipe(this.params.stream).pipe(duplex);
3725
+ duplex.pipe(this._options.stream).pipe(duplex);
3681
3726
  this._stream = duplex;
3682
3727
  this._connected = true;
3683
3728
  this.connected.emit();
3684
3729
  };
3685
- this._channel.onerror = async (err) => {
3686
- this.errors.raise(new Error("channel error: " + err.toString()));
3687
- await this._close();
3688
- };
3689
3730
  this._channel.onclose = async (err) => {
3690
- log14.info("channel onclose", {
3731
+ log14.info("channel.onclose", {
3691
3732
  err
3692
3733
  }, {
3693
3734
  F: __dxlog_file15,
3694
- L: 177,
3735
+ L: 223,
3695
3736
  S: this,
3696
3737
  C: (f, a) => f(...a)
3697
3738
  });
3698
3739
  await this._close();
3699
3740
  };
3741
+ this._channel.onerror = async (err) => {
3742
+ this.errors.raise(new Error("channel error: " + err.toString()));
3743
+ await this._close();
3744
+ };
3745
+ this._channel.onbufferedamountlow = () => {
3746
+ const cb = this._writeCallback;
3747
+ this._writeCallback = null;
3748
+ cb?.();
3749
+ };
3700
3750
  this._channel.onmessage = (event) => {
3701
3751
  let data = event.data;
3702
3752
  if (data instanceof ArrayBuffer) {
@@ -3704,37 +3754,27 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3704
3754
  }
3705
3755
  this._stream.push(data);
3706
3756
  };
3707
- this._channel.onbufferedamountlow = () => {
3708
- const cb = this._writeCallback;
3709
- this._writeCallback = null;
3710
- cb?.();
3711
- };
3712
3757
  }
3713
- async _close() {
3714
- if (this._closed) {
3715
- return;
3716
- }
3717
- await this._disconnectStreams();
3718
- const peer = await this._peer;
3758
+ async onSignal(signal) {
3759
+ invariant14(this._peer, "not open", {
3760
+ F: __dxlog_file15,
3761
+ L: 249,
3762
+ S: this,
3763
+ A: [
3764
+ "this._peer",
3765
+ "'not open'"
3766
+ ]
3767
+ });
3719
3768
  try {
3720
- peer.close();
3721
- } catch (err) {
3722
- this.errors.raise(err);
3723
- }
3724
- this._closed = true;
3725
- this.closed.emit();
3726
- }
3727
- signal(signal) {
3728
- this._peer.then(async (peer) => {
3729
3769
  const data = signal.payload.data;
3730
3770
  switch (data.type) {
3731
3771
  case "offer": {
3732
- if ((await this._peer).connectionState !== "new") {
3772
+ if (this._peer.connectionState !== "new") {
3733
3773
  log14.error("received offer but peer not in state new", {
3734
- peer
3774
+ peer: this._peer
3735
3775
  }, {
3736
3776
  F: __dxlog_file15,
3737
- L: 218,
3777
+ L: 256,
3738
3778
  S: this,
3739
3779
  C: (f, a) => f(...a)
3740
3780
  });
@@ -3742,13 +3782,13 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3742
3782
  break;
3743
3783
  }
3744
3784
  try {
3745
- await peer.setRemoteDescription({
3785
+ await this._peer.setRemoteDescription({
3746
3786
  type: data.type,
3747
3787
  sdp: data.sdp
3748
3788
  });
3749
- const answer = await peer.createAnswer();
3750
- await peer.setLocalDescription(answer);
3751
- await this.params.sendSignal({
3789
+ const answer = await this._peer.createAnswer();
3790
+ await this._peer.setLocalDescription(answer);
3791
+ await this._options.sendSignal({
3752
3792
  payload: {
3753
3793
  data: {
3754
3794
  type: answer.type,
@@ -3758,11 +3798,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3758
3798
  });
3759
3799
  this._readyForCandidates.wake();
3760
3800
  } catch (err) {
3761
- log14.error("can't handle offer from signalling server", {
3801
+ log14.error("cannot handle offer from signalling server", {
3762
3802
  err
3763
3803
  }, {
3764
3804
  F: __dxlog_file15,
3765
- L: 229,
3805
+ L: 268,
3766
3806
  S: this,
3767
3807
  C: (f, a) => f(...a)
3768
3808
  });
@@ -3772,17 +3812,17 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3772
3812
  }
3773
3813
  case "answer":
3774
3814
  try {
3775
- await peer.setRemoteDescription({
3815
+ await this._peer.setRemoteDescription({
3776
3816
  type: data.type,
3777
3817
  sdp: data.sdp
3778
3818
  });
3779
3819
  this._readyForCandidates.wake();
3780
3820
  } catch (err) {
3781
- log14.error("can't handle answer from signalling server", {
3821
+ log14.error("cannot handle answer from signalling server", {
3782
3822
  err
3783
3823
  }, {
3784
3824
  F: __dxlog_file15,
3785
- L: 240,
3825
+ L: 279,
3786
3826
  S: this,
3787
3827
  C: (f, a) => f(...a)
3788
3828
  });
@@ -3791,7 +3831,7 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3791
3831
  break;
3792
3832
  case "candidate":
3793
3833
  await this._readyForCandidates.wait();
3794
- await peer.addIceCandidate({
3834
+ await this._peer.addIceCandidate({
3795
3835
  candidate: data.candidate.candidate
3796
3836
  });
3797
3837
  break;
@@ -3801,20 +3841,20 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3801
3841
  signal
3802
3842
  }, {
3803
3843
  F: __dxlog_file15,
3804
- L: 251,
3844
+ L: 290,
3805
3845
  S: this,
3806
3846
  C: (f, a) => f(...a)
3807
3847
  });
3808
3848
  this.errors.raise(new Error(`unhandled signal type ${data.type}`));
3809
3849
  }
3810
- }).catch((err) => {
3850
+ } catch (err) {
3811
3851
  log14.catch(err, void 0, {
3812
3852
  F: __dxlog_file15,
3813
- L: 256,
3853
+ L: 294,
3814
3854
  S: this,
3815
3855
  C: (f, a) => f(...a)
3816
3856
  });
3817
- });
3857
+ }
3818
3858
  }
3819
3859
  async getDetails() {
3820
3860
  const stats = await this._getStats();
@@ -3827,26 +3867,6 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3827
3867
  }
3828
3868
  return `${rc.ip}:${rc.port} ${rc.candidateType}`;
3829
3869
  }
3830
- async _getStats() {
3831
- return this._peer.then(async (peer) => {
3832
- const stats = await peer.getStats();
3833
- const statsEntries = Array.from(stats.entries());
3834
- const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
3835
- const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
3836
- let selectedCandidatePair;
3837
- let remoteCandidate;
3838
- if (candidatePair.length > 0) {
3839
- selectedCandidatePair = candidatePair[0][1];
3840
- remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
3841
- }
3842
- return {
3843
- transport,
3844
- selectedCandidatePair,
3845
- remoteCandidate,
3846
- raw: Object.fromEntries(stats)
3847
- };
3848
- });
3849
- }
3850
3870
  async getStats() {
3851
3871
  const stats = await this._getStats();
3852
3872
  if (!stats) {
@@ -3866,25 +3886,40 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3866
3886
  rawStats: stats.raw
3867
3887
  };
3868
3888
  }
3869
- async destroy() {
3870
- await this._close();
3871
- if (--_LibDataChannelTransport._instanceCount === 0) {
3872
- (await importESM("node-datachannel")).cleanup();
3889
+ async _getStats() {
3890
+ invariant14(this._peer, "not open", {
3891
+ F: __dxlog_file15,
3892
+ L: 334,
3893
+ S: this,
3894
+ A: [
3895
+ "this._peer",
3896
+ "'not open'"
3897
+ ]
3898
+ });
3899
+ const stats = await this._peer.getStats();
3900
+ const statsEntries = Array.from(stats.entries());
3901
+ const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
3902
+ const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
3903
+ let selectedCandidatePair;
3904
+ let remoteCandidate;
3905
+ if (candidatePair.length > 0) {
3906
+ selectedCandidatePair = candidatePair[0][1];
3907
+ remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
3873
3908
  }
3909
+ return {
3910
+ transport,
3911
+ selectedCandidatePair,
3912
+ remoteCandidate,
3913
+ raw: Object.fromEntries(stats)
3914
+ };
3874
3915
  }
3875
3916
  async _disconnectStreams() {
3876
- this.params.stream.unpipe?.(this._stream)?.unpipe?.(this.params.stream);
3917
+ this._options.stream.unpipe?.(this._stream)?.unpipe?.(this._options.stream);
3877
3918
  }
3878
3919
  };
3879
3920
  _ts_decorate5([
3880
3921
  synchronized4
3881
3922
  ], LibDataChannelTransport.prototype, "_close", null);
3882
- var createLibDataChannelTransportFactory = (webrtcConfig) => ({
3883
- createTransport: (params) => new LibDataChannelTransport({
3884
- ...params,
3885
- webrtcConfig
3886
- })
3887
- });
3888
3923
  var importESM = Function("path", "return import(path)");
3889
3924
 
3890
3925
  // packages/core/mesh/network-manager/src/transport/tcp-transport.browser.ts
@@ -3899,10 +3934,14 @@ var TcpTransport = class {
3899
3934
  this.connected = new Event11();
3900
3935
  this.errors = new ErrorStream7();
3901
3936
  }
3902
- async destroy() {
3903
- throw new Error("Method not implemented.");
3937
+ get isOpen() {
3938
+ return true;
3939
+ }
3940
+ async open() {
3904
3941
  }
3905
- signal() {
3942
+ async close() {
3943
+ }
3944
+ async onSignal() {
3906
3945
  throw new Error("Method not implemented.");
3907
3946
  }
3908
3947
  async getStats() {
@@ -3952,15 +3991,15 @@ export {
3952
3991
  MemoryTransportFactory,
3953
3992
  MemoryTransport,
3954
3993
  TransportKind,
3955
- SimplePeerTransport,
3956
3994
  createSimplePeerTransportFactory,
3995
+ SimplePeerTransport,
3957
3996
  SimplePeerTransportService,
3958
3997
  SimplePeerTransportProxy,
3959
3998
  SimplePeerTransportProxyFactory,
3960
- LibDataChannelTransport,
3961
3999
  createLibDataChannelTransportFactory,
4000
+ LibDataChannelTransport,
3962
4001
  TcpTransportFactory,
3963
4002
  TcpTransport,
3964
4003
  createTeleportProtocolFactory
3965
4004
  };
3966
- //# sourceMappingURL=chunk-OIR45T43.mjs.map
4005
+ //# sourceMappingURL=chunk-SOVZDG44.mjs.map