@dxos/network-manager 0.6.14-staging.e15392e → 0.7.0

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-RUNQZNCV.mjs → chunk-MAR4A5JK.mjs} +144 -85
  2. package/dist/lib/browser/chunk-MAR4A5JK.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 +15 -9
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-D6P7ACEM.cjs → chunk-J5PWZKEH.cjs} +147 -88
  8. package/dist/lib/node/chunk-J5PWZKEH.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +23 -23
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/testing/index.cjs +28 -22
  13. package/dist/lib/node/testing/index.cjs.map +3 -3
  14. package/dist/lib/node-esm/{chunk-22DA2US6.mjs → chunk-XHE7MQ7U.mjs} +144 -85
  15. package/dist/lib/node-esm/chunk-XHE7MQ7U.mjs.map +7 -0
  16. package/dist/lib/node-esm/index.mjs +1 -1
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +15 -9
  19. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  20. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  21. package/dist/types/src/swarm/swarm.d.ts +1 -0
  22. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  23. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  24. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
  25. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +4 -0
  26. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
  27. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
  28. package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
  29. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
  30. package/package.json +18 -18
  31. package/src/swarm/connection.ts +2 -2
  32. package/src/swarm/peer.ts +4 -1
  33. package/src/swarm/swarm.ts +15 -2
  34. package/src/testing/test-builder.ts +1 -0
  35. package/src/testing/test-wire-protocol.ts +6 -4
  36. package/src/tests/basic-test-suite.ts +13 -13
  37. package/src/tests/webrtc-transport.test.ts +1 -1
  38. package/src/transport/webrtc/rtc-peer-connection.ts +21 -7
  39. package/src/transport/webrtc/rtc-transport-channel.ts +7 -1
  40. package/src/transport/webrtc/rtc-transport-factory.ts +1 -0
  41. package/src/transport/webrtc/rtc-transport-service.ts +4 -2
  42. package/src/transport/webrtc/rtc-transport.test.ts +18 -6
  43. package/dist/lib/browser/chunk-RUNQZNCV.mjs.map +0 -7
  44. package/dist/lib/node/chunk-D6P7ACEM.cjs.map +0 -7
  45. package/dist/lib/node-esm/chunk-22DA2US6.mjs.map +0 -7
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_D6P7ACEM_exports = {};
30
- __export(chunk_D6P7ACEM_exports, {
29
+ var chunk_J5PWZKEH_exports = {};
30
+ __export(chunk_J5PWZKEH_exports, {
31
31
  Connection: () => Connection,
32
32
  ConnectionLimiter: () => ConnectionLimiter,
33
33
  ConnectionLog: () => ConnectionLog,
@@ -51,7 +51,7 @@ __export(chunk_D6P7ACEM_exports, {
51
51
  createRtcTransportFactory: () => createRtcTransportFactory,
52
52
  createTeleportProtocolFactory: () => createTeleportProtocolFactory
53
53
  });
54
- module.exports = __toCommonJS(chunk_D6P7ACEM_exports);
54
+ module.exports = __toCommonJS(chunk_J5PWZKEH_exports);
55
55
  var import_async = require("@dxos/async");
56
56
  var import_context = require("@dxos/context");
57
57
  var import_debug = require("@dxos/debug");
@@ -340,7 +340,7 @@ var Connection = class {
340
340
  S: this,
341
341
  C: (f, a) => f(...a)
342
342
  });
343
- this.abort().catch((err2) => this.errors.raise(err2));
343
+ this.abort(err).catch((err2) => this.errors.raise(err2));
344
344
  } else if (err instanceof import_protocols.ConnectivityError) {
345
345
  import_log.log.info("aborting due to transport ConnectivityError", void 0, {
346
346
  F: __dxlog_file,
@@ -348,7 +348,7 @@ var Connection = class {
348
348
  S: this,
349
349
  C: (f, a) => f(...a)
350
350
  });
351
- this.abort().catch((err2) => this.errors.raise(err2));
351
+ this.abort(err).catch((err2) => this.errors.raise(err2));
352
352
  }
353
353
  if (this._state !== "CLOSED" && this._state !== "CLOSING") {
354
354
  await this.connectedTimeoutContext.dispose();
@@ -1293,21 +1293,22 @@ var Peer = class {
1293
1293
  });
1294
1294
  },
1295
1295
  onClosed: (err) => {
1296
- (0, import_log5.log)("connection closed", {
1296
+ const logMeta = {
1297
1297
  topic: this.topic,
1298
1298
  peerId: this.localInfo,
1299
1299
  remoteId: this.remoteInfo,
1300
1300
  initiator
1301
- }, {
1301
+ };
1302
+ (0, import_log5.log)("connection closed", logMeta, {
1302
1303
  F: __dxlog_file4,
1303
- L: 288,
1304
+ L: 289,
1304
1305
  S: this,
1305
1306
  C: (f, a) => f(...a)
1306
1307
  });
1307
1308
  this._connectionLimiter.doneConnecting(sessionId);
1308
1309
  (0, import_invariant4.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1309
1310
  F: __dxlog_file4,
1310
- L: 293,
1311
+ L: 294,
1311
1312
  S: this,
1312
1313
  A: [
1313
1314
  "this.connection === connection",
@@ -1322,7 +1323,7 @@ var Peer = class {
1322
1323
  initiator
1323
1324
  }, {
1324
1325
  F: __dxlog_file4,
1325
- L: 295,
1326
+ L: 296,
1326
1327
  S: this,
1327
1328
  C: (f, a) => f(...a)
1328
1329
  });
@@ -1337,6 +1338,12 @@ var Peer = class {
1337
1338
  }
1338
1339
  this._callbacks.onDisconnected();
1339
1340
  (0, import_async4.scheduleTask)(this._connectionCtx, () => {
1341
+ (0, import_log5.log)("peer became available", logMeta, {
1342
+ F: __dxlog_file4,
1343
+ L: 320,
1344
+ S: this,
1345
+ C: (f, a) => f(...a)
1346
+ });
1340
1347
  this.availableToConnect = true;
1341
1348
  this._callbacks.onPeerAvailable();
1342
1349
  }, this._availableAfter);
@@ -1357,7 +1364,7 @@ var Peer = class {
1357
1364
  err
1358
1365
  }, {
1359
1366
  F: __dxlog_file4,
1360
- L: 335,
1367
+ L: 338,
1361
1368
  S: this,
1362
1369
  C: (f, a) => f(...a)
1363
1370
  });
@@ -1370,7 +1377,7 @@ var Peer = class {
1370
1377
  err
1371
1378
  }, {
1372
1379
  F: __dxlog_file4,
1373
- L: 342,
1380
+ L: 345,
1374
1381
  S: this,
1375
1382
  C: (f, a) => f(...a)
1376
1383
  });
@@ -1389,7 +1396,7 @@ var Peer = class {
1389
1396
  sessionId: connection.sessionId
1390
1397
  }, {
1391
1398
  F: __dxlog_file4,
1392
- L: 367,
1399
+ L: 370,
1393
1400
  S: this,
1394
1401
  C: (f, a) => f(...a)
1395
1402
  });
@@ -1399,7 +1406,7 @@ var Peer = class {
1399
1406
  sessionId: connection.sessionId
1400
1407
  }, {
1401
1408
  F: __dxlog_file4,
1402
- L: 373,
1409
+ L: 376,
1403
1410
  S: this,
1404
1411
  C: (f, a) => f(...a)
1405
1412
  });
@@ -1410,7 +1417,7 @@ var Peer = class {
1410
1417
  message
1411
1418
  }, {
1412
1419
  F: __dxlog_file4,
1413
- L: 378,
1420
+ L: 381,
1414
1421
  S: this,
1415
1422
  C: (f, a) => f(...a)
1416
1423
  });
@@ -1425,7 +1432,7 @@ var Peer = class {
1425
1432
  topic: this.topic
1426
1433
  }, {
1427
1434
  F: __dxlog_file4,
1428
- L: 388,
1435
+ L: 391,
1429
1436
  S: this,
1430
1437
  C: (f, a) => f(...a)
1431
1438
  });
@@ -1641,10 +1648,16 @@ var Swarm = class {
1641
1648
  const peer = this._peers.get(swarmEvent.peerLeft.peer);
1642
1649
  if (peer) {
1643
1650
  peer.advertizing = false;
1644
- if (peer.connection?.state !== ConnectionState.CONNECTED) {
1651
+ if (this._isConnectionEstablishmentInProgress(peer)) {
1652
+ (0, import_log4.log)(`destroying peer, state: ${peer.connection?.state}`, void 0, {
1653
+ F: __dxlog_file5,
1654
+ L: 195,
1655
+ S: this,
1656
+ C: (f, a) => f(...a)
1657
+ });
1645
1658
  void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => import_log4.log.catch(err, void 0, {
1646
1659
  F: __dxlog_file5,
1647
- L: 194,
1660
+ L: 196,
1648
1661
  S: this,
1649
1662
  C: (f, a) => f(...a)
1650
1663
  }));
@@ -1654,7 +1667,7 @@ var Swarm = class {
1654
1667
  peer: swarmEvent.peerLeft.peer.peerKey
1655
1668
  }, {
1656
1669
  F: __dxlog_file5,
1657
- L: 197,
1670
+ L: 199,
1658
1671
  S: this,
1659
1672
  C: (f, a) => f(...a)
1660
1673
  });
@@ -1667,14 +1680,14 @@ var Swarm = class {
1667
1680
  message
1668
1681
  }, {
1669
1682
  F: __dxlog_file5,
1670
- L: 206,
1683
+ L: 208,
1671
1684
  S: this,
1672
1685
  C: (f, a) => f(...a)
1673
1686
  });
1674
1687
  if (this._ctx.disposed) {
1675
1688
  (0, import_log4.log)("ignored for disposed swarm", void 0, {
1676
1689
  F: __dxlog_file5,
1677
- L: 208,
1690
+ L: 210,
1678
1691
  S: this,
1679
1692
  C: (f, a) => f(...a)
1680
1693
  });
@@ -1684,7 +1697,7 @@ var Swarm = class {
1684
1697
  }
1685
1698
  (0, import_invariant3.invariant)(message.author, void 0, {
1686
1699
  F: __dxlog_file5,
1687
- L: 213,
1700
+ L: 215,
1688
1701
  S: this,
1689
1702
  A: [
1690
1703
  "message.author",
@@ -1696,7 +1709,7 @@ var Swarm = class {
1696
1709
  message
1697
1710
  }, {
1698
1711
  F: __dxlog_file5,
1699
- L: 215,
1712
+ L: 217,
1700
1713
  S: this,
1701
1714
  C: (f, a) => f(...a)
1702
1715
  });
@@ -1709,7 +1722,7 @@ var Swarm = class {
1709
1722
  message
1710
1723
  }, {
1711
1724
  F: __dxlog_file5,
1712
- L: 219,
1725
+ L: 221,
1713
1726
  S: this,
1714
1727
  C: (f, a) => f(...a)
1715
1728
  });
@@ -1727,14 +1740,14 @@ var Swarm = class {
1727
1740
  message
1728
1741
  }, {
1729
1742
  F: __dxlog_file5,
1730
- L: 230,
1743
+ L: 232,
1731
1744
  S: this,
1732
1745
  C: (f, a) => f(...a)
1733
1746
  });
1734
1747
  if (this._ctx.disposed) {
1735
1748
  import_log4.log.info("ignored for offline swarm", void 0, {
1736
1749
  F: __dxlog_file5,
1737
- L: 232,
1750
+ L: 234,
1738
1751
  S: this,
1739
1752
  C: (f, a) => f(...a)
1740
1753
  });
@@ -1742,7 +1755,7 @@ var Swarm = class {
1742
1755
  }
1743
1756
  (0, import_invariant3.invariant)(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1744
1757
  F: __dxlog_file5,
1745
- L: 235,
1758
+ L: 237,
1746
1759
  S: this,
1747
1760
  A: [
1748
1761
  "message.recipient.peerKey === this._ownPeer.peerKey",
@@ -1751,7 +1764,7 @@ var Swarm = class {
1751
1764
  });
1752
1765
  (0, import_invariant3.invariant)(message.topic?.equals(this._topic), void 0, {
1753
1766
  F: __dxlog_file5,
1754
- L: 239,
1767
+ L: 241,
1755
1768
  S: this,
1756
1769
  A: [
1757
1770
  "message.topic?.equals(this._topic)",
@@ -1760,7 +1773,7 @@ var Swarm = class {
1760
1773
  });
1761
1774
  (0, import_invariant3.invariant)(message.author, void 0, {
1762
1775
  F: __dxlog_file5,
1763
- L: 240,
1776
+ L: 242,
1764
1777
  S: this,
1765
1778
  A: [
1766
1779
  "message.author",
@@ -1781,13 +1794,13 @@ var Swarm = class {
1781
1794
  async goOnline() {
1782
1795
  this._ctx = new import_context3.Context(void 0, {
1783
1796
  F: __dxlog_file5,
1784
- L: 256
1797
+ L: 258
1785
1798
  });
1786
1799
  }
1787
1800
  _getOrCreatePeer(peerInfo) {
1788
1801
  (0, import_invariant3.invariant)(peerInfo.peerKey, "PeerInfo.peerKey is required", {
1789
1802
  F: __dxlog_file5,
1790
- L: 260,
1803
+ L: 262,
1791
1804
  S: this,
1792
1805
  A: [
1793
1806
  "peerInfo.peerKey",
@@ -1805,6 +1818,12 @@ var Swarm = class {
1805
1818
  },
1806
1819
  onDisconnected: async () => {
1807
1820
  if (this._isUnregistered(peer)) {
1821
+ import_log4.log.verbose("ignored onDisconnected for unregistered peer", void 0, {
1822
+ F: __dxlog_file5,
1823
+ L: 282,
1824
+ S: this,
1825
+ C: (f, a) => f(...a)
1826
+ });
1808
1827
  return;
1809
1828
  }
1810
1829
  if (!peer.advertizing) {
@@ -1819,7 +1838,7 @@ var Swarm = class {
1819
1838
  peerInfo
1820
1839
  }, {
1821
1840
  F: __dxlog_file5,
1822
- L: 293,
1841
+ L: 296,
1823
1842
  S: this,
1824
1843
  C: (f, a) => f(...a)
1825
1844
  });
@@ -1841,10 +1860,19 @@ var Swarm = class {
1841
1860
  return peer;
1842
1861
  }
1843
1862
  async _destroyPeer(peerInfo, reason) {
1863
+ (0, import_log4.log)("destroy peer", {
1864
+ peerKey: peerInfo.peerKey,
1865
+ reason
1866
+ }, {
1867
+ F: __dxlog_file5,
1868
+ L: 318,
1869
+ S: this,
1870
+ C: (f, a) => f(...a)
1871
+ });
1844
1872
  const peer = this._peers.get(peerInfo);
1845
1873
  (0, import_invariant3.invariant)(peer, void 0, {
1846
1874
  F: __dxlog_file5,
1847
- L: 316,
1875
+ L: 320,
1848
1876
  S: this,
1849
1877
  A: [
1850
1878
  "peer",
@@ -1874,7 +1902,7 @@ var Swarm = class {
1874
1902
  } catch (err) {
1875
1903
  (0, import_log4.log)("initiation error", err, {
1876
1904
  F: __dxlog_file5,
1877
- L: 343,
1905
+ L: 347,
1878
1906
  S: this,
1879
1907
  C: (f, a) => f(...a)
1880
1908
  });
@@ -1905,7 +1933,7 @@ var Swarm = class {
1905
1933
  remotePeer
1906
1934
  }, {
1907
1935
  F: __dxlog_file5,
1908
- L: 371,
1936
+ L: 375,
1909
1937
  S: this,
1910
1938
  C: (f, a) => f(...a)
1911
1939
  });
@@ -1924,7 +1952,7 @@ var Swarm = class {
1924
1952
  remotePeer
1925
1953
  }, {
1926
1954
  F: __dxlog_file5,
1927
- L: 387,
1955
+ L: 391,
1928
1956
  S: this,
1929
1957
  C: (f, a) => f(...a)
1930
1958
  });
@@ -1934,7 +1962,7 @@ var Swarm = class {
1934
1962
  remotePeer
1935
1963
  }, {
1936
1964
  F: __dxlog_file5,
1937
- L: 390,
1965
+ L: 394,
1938
1966
  S: this,
1939
1967
  C: (f, a) => f(...a)
1940
1968
  });
@@ -1946,6 +1974,16 @@ var Swarm = class {
1946
1974
  }
1947
1975
  await peer.closeConnection();
1948
1976
  }
1977
+ _isConnectionEstablishmentInProgress(peer) {
1978
+ if (!peer.connection) {
1979
+ return true;
1980
+ }
1981
+ return [
1982
+ ConnectionState.INITIAL,
1983
+ ConnectionState.CREATED,
1984
+ ConnectionState.CONNECTING
1985
+ ].includes(peer.connection.state);
1986
+ }
1949
1987
  _isUnregistered(peer) {
1950
1988
  return !peer || this._peers.get(peer.remoteInfo) !== peer;
1951
1989
  }
@@ -3091,7 +3129,17 @@ var RtcTransportChannel = class extends import_context6.Resource {
3091
3129
  }
3092
3130
  }).catch((err) => {
3093
3131
  if (this.isOpen) {
3094
- this.errors.raise(new import_protocols8.ConnectivityError(`Failed to create a channel: ${err?.message ?? "unknown reason."}`));
3132
+ const error = err instanceof Error ? err : new import_protocols8.ConnectivityError(`Failed to create a channel: ${JSON.stringify(err?.message)}`);
3133
+ this.errors.raise(error);
3134
+ } else {
3135
+ import_log13.log.verbose("connection establishment failed after transport was closed", {
3136
+ err
3137
+ }, {
3138
+ F: __dxlog_file13,
3139
+ L: 76,
3140
+ S: this,
3141
+ C: (f, a) => f(...a)
3142
+ });
3095
3143
  }
3096
3144
  }).finally(() => {
3097
3145
  this._isChannelCreationInProgress = false;
@@ -3106,7 +3154,7 @@ var RtcTransportChannel = class extends import_context6.Resource {
3106
3154
  this.closed.emit();
3107
3155
  (0, import_log13.log)("closed", void 0, {
3108
3156
  F: __dxlog_file13,
3109
- L: 86,
3157
+ L: 92,
3110
3158
  S: this,
3111
3159
  C: (f, a) => f(...a)
3112
3160
  });
@@ -3119,7 +3167,7 @@ var RtcTransportChannel = class extends import_context6.Resource {
3119
3167
  topic: this._options.topic
3120
3168
  }, {
3121
3169
  F: __dxlog_file13,
3122
- L: 93,
3170
+ L: 99,
3123
3171
  S: this,
3124
3172
  C: (f, a) => f(...a)
3125
3173
  });
@@ -3128,7 +3176,7 @@ var RtcTransportChannel = class extends import_context6.Resource {
3128
3176
  }
3129
3177
  (0, import_log13.log)("onopen", void 0, {
3130
3178
  F: __dxlog_file13,
3131
- L: 98,
3179
+ L: 104,
3132
3180
  S: this,
3133
3181
  C: (f, a) => f(...a)
3134
3182
  });
@@ -3146,7 +3194,7 @@ var RtcTransportChannel = class extends import_context6.Resource {
3146
3194
  onclose: async () => {
3147
3195
  (0, import_log13.log)("onclose", void 0, {
3148
3196
  F: __dxlog_file13,
3149
- L: 111,
3197
+ L: 117,
3150
3198
  S: this,
3151
3199
  C: (f, a) => f(...a)
3152
3200
  });
@@ -3156,7 +3204,7 @@ var RtcTransportChannel = class extends import_context6.Resource {
3156
3204
  if (!this._stream) {
3157
3205
  import_log13.log.warn("ignoring message on a closed channel", void 0, {
3158
3206
  F: __dxlog_file13,
3159
- L: 117,
3207
+ L: 123,
3160
3208
  S: this,
3161
3209
  C: (f, a) => f(...a)
3162
3210
  });
@@ -3185,7 +3233,7 @@ var RtcTransportChannel = class extends import_context6.Resource {
3185
3233
  if (!this._channel) {
3186
3234
  import_log13.log.warn("writing to a channel after a connection was closed", void 0, {
3187
3235
  F: __dxlog_file13,
3188
- L: 145,
3236
+ L: 151,
3189
3237
  S: this,
3190
3238
  C: (f, a) => f(...a)
3191
3239
  });
@@ -3208,7 +3256,7 @@ var RtcTransportChannel = class extends import_context6.Resource {
3208
3256
  if (this._streamDataFlushedCallback !== null) {
3209
3257
  import_log13.log.error("consumer trying to write before we are ready for more data", void 0, {
3210
3258
  F: __dxlog_file13,
3211
- L: 166,
3259
+ L: 172,
3212
3260
  S: this,
3213
3261
  C: (f, a) => f(...a)
3214
3262
  });
@@ -3224,7 +3272,7 @@ var RtcTransportChannel = class extends import_context6.Resource {
3224
3272
  } catch (error) {
3225
3273
  import_log13.log.catch(error, void 0, {
3226
3274
  F: __dxlog_file13,
3227
- L: 178,
3275
+ L: 184,
3228
3276
  S: this,
3229
3277
  C: (f, a) => f(...a)
3230
3278
  });
@@ -3271,6 +3319,7 @@ function _ts_decorate6(decorators, target, key, desc) {
3271
3319
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3272
3320
  }
3273
3321
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
3322
+ var isLegacyInteropEnabled = () => Boolean(globalThis?.DEVICE_INVITE_INTEROP);
3274
3323
  var RtcPeerConnection = class {
3275
3324
  constructor(_factory, _options) {
3276
3325
  this._factory = _factory;
@@ -3280,7 +3329,7 @@ var RtcPeerConnection = class {
3280
3329
  this._dataChannels = /* @__PURE__ */ new Map();
3281
3330
  this._readyForCandidates = new import_async11.Trigger();
3282
3331
  this._offerProcessingMutex = new import_async11.Mutex();
3283
- this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
3332
+ this._initiator = isLegacyInteropEnabled() ? Boolean(this._options.legacyInitiator) : chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
3284
3333
  }
3285
3334
  get transportChannelCount() {
3286
3335
  return this._transportChannels.size;
@@ -3289,30 +3338,31 @@ var RtcPeerConnection = class {
3289
3338
  return this._connection;
3290
3339
  }
3291
3340
  async createDataChannel(topic) {
3341
+ const channelKey = isLegacyInteropEnabled() ? "dxos.mesh.transport" : topic;
3292
3342
  const connection = await this._openConnection();
3293
- if (!this._transportChannels.has(topic)) {
3343
+ if (isLegacyInteropEnabled() ? this._transportChannels.size === 0 : !this._transportChannels.has(channelKey)) {
3294
3344
  if (!this._transportChannels.size) {
3295
3345
  this._lockAndCloseConnection();
3296
3346
  }
3297
3347
  throw new Error("Transport closed while connection was being open");
3298
3348
  }
3299
3349
  if (this._initiator) {
3300
- const channel = connection.createDataChannel(topic);
3301
- this._dataChannels.set(topic, channel);
3350
+ const channel = connection.createDataChannel(channelKey);
3351
+ this._dataChannels.set(channelKey, channel);
3302
3352
  return channel;
3303
3353
  } else {
3304
- const existingChannel = this._dataChannels.get(topic);
3354
+ const existingChannel = this._dataChannels.get(channelKey);
3305
3355
  if (existingChannel) {
3306
3356
  return existingChannel;
3307
3357
  }
3308
3358
  (0, import_log12.log)("waiting for initiator-peer to open a data channel", void 0, {
3309
3359
  F: __dxlog_file14,
3310
- L: 90,
3360
+ L: 104,
3311
3361
  S: this,
3312
3362
  C: (f, a) => f(...a)
3313
3363
  });
3314
3364
  return new Promise((resolve, reject) => {
3315
- this._channelCreatedCallbacks.set(topic, {
3365
+ this._channelCreatedCallbacks.set(channelKey, {
3316
3366
  resolve,
3317
3367
  reject
3318
3368
  });
@@ -3338,7 +3388,7 @@ var RtcPeerConnection = class {
3338
3388
  remotePeer: this._options.remotePeerKey
3339
3389
  }), {
3340
3390
  F: __dxlog_file14,
3341
- L: 115,
3391
+ L: 129,
3342
3392
  S: this,
3343
3393
  C: (f, a) => f(...a)
3344
3394
  });
@@ -3349,7 +3399,7 @@ var RtcPeerConnection = class {
3349
3399
  onnegotiationneeded: async () => {
3350
3400
  (0, import_invariant11.invariant)(this._initiator, void 0, {
3351
3401
  F: __dxlog_file14,
3352
- L: 130,
3402
+ L: 144,
3353
3403
  S: this,
3354
3404
  A: [
3355
3405
  "this._initiator",
@@ -3362,7 +3412,7 @@ var RtcPeerConnection = class {
3362
3412
  }
3363
3413
  (0, import_log12.log)("onnegotiationneeded", void 0, {
3364
3414
  F: __dxlog_file14,
3365
- L: 137,
3415
+ L: 151,
3366
3416
  S: this,
3367
3417
  C: (f, a) => f(...a)
3368
3418
  });
@@ -3386,7 +3436,7 @@ var RtcPeerConnection = class {
3386
3436
  candidate: event.candidate.candidate
3387
3437
  }, {
3388
3438
  F: __dxlog_file14,
3389
- L: 156,
3439
+ L: 170,
3390
3440
  S: this,
3391
3441
  C: (f, a) => f(...a)
3392
3442
  });
@@ -3394,7 +3444,7 @@ var RtcPeerConnection = class {
3394
3444
  } else {
3395
3445
  (0, import_log12.log)("onicecandidate gathering complete", void 0, {
3396
3446
  F: __dxlog_file14,
3397
- L: 159,
3447
+ L: 173,
3398
3448
  S: this,
3399
3449
  C: (f, a) => f(...a)
3400
3450
  });
@@ -3422,7 +3472,7 @@ var RtcPeerConnection = class {
3422
3472
  state: connection.iceConnectionState
3423
3473
  }, {
3424
3474
  F: __dxlog_file14,
3425
- L: 179,
3475
+ L: 193,
3426
3476
  S: this,
3427
3477
  C: (f, a) => f(...a)
3428
3478
  });
@@ -3444,7 +3494,7 @@ var RtcPeerConnection = class {
3444
3494
  state: connection.connectionState
3445
3495
  }, {
3446
3496
  F: __dxlog_file14,
3447
- L: 196,
3497
+ L: 210,
3448
3498
  S: this,
3449
3499
  C: (f, a) => f(...a)
3450
3500
  });
@@ -3457,7 +3507,7 @@ var RtcPeerConnection = class {
3457
3507
  state: connection.signalingState
3458
3508
  }, {
3459
3509
  F: __dxlog_file14,
3460
- L: 203,
3510
+ L: 217,
3461
3511
  S: this,
3462
3512
  C: (f, a) => f(...a)
3463
3513
  });
@@ -3467,7 +3517,7 @@ var RtcPeerConnection = class {
3467
3517
  ondatachannel: (event) => {
3468
3518
  (0, import_invariant11.invariant)(!this._initiator, "Initiator is expected to create data channels.", {
3469
3519
  F: __dxlog_file14,
3470
- L: 209,
3520
+ L: 223,
3471
3521
  S: this,
3472
3522
  A: [
3473
3523
  "!this._initiator",
@@ -3482,7 +3532,7 @@ var RtcPeerConnection = class {
3482
3532
  label: event.channel.label
3483
3533
  }, {
3484
3534
  F: __dxlog_file14,
3485
- L: 216,
3535
+ L: 230,
3486
3536
  S: this,
3487
3537
  C: (f, a) => f(...a)
3488
3538
  });
@@ -3510,7 +3560,7 @@ var RtcPeerConnection = class {
3510
3560
  error
3511
3561
  }, {
3512
3562
  F: __dxlog_file14,
3513
- L: 241,
3563
+ L: 255,
3514
3564
  S: this,
3515
3565
  C: (f, a) => f(...a)
3516
3566
  });
@@ -3531,7 +3581,7 @@ var RtcPeerConnection = class {
3531
3581
  reason: error.message
3532
3582
  }, {
3533
3583
  F: __dxlog_file14,
3534
- L: 255,
3584
+ L: 269,
3535
3585
  S: this,
3536
3586
  C: (f, a) => f(...a)
3537
3587
  });
@@ -3539,7 +3589,7 @@ var RtcPeerConnection = class {
3539
3589
  _lockAndCloseConnection() {
3540
3590
  (0, import_invariant11.invariant)(this._transportChannels.size === 0, void 0, {
3541
3591
  F: __dxlog_file14,
3542
- L: 260,
3592
+ L: 274,
3543
3593
  S: this,
3544
3594
  A: [
3545
3595
  "this._transportChannels.size === 0",
@@ -3550,7 +3600,7 @@ var RtcPeerConnection = class {
3550
3600
  this._safeCloseConnection();
3551
3601
  (0, import_log12.log)("connection closed", void 0, {
3552
3602
  F: __dxlog_file14,
3553
- L: 263,
3603
+ L: 277,
3554
3604
  S: this,
3555
3605
  C: (f, a) => f(...a)
3556
3606
  });
@@ -3563,7 +3613,7 @@ var RtcPeerConnection = class {
3563
3613
  type: signal.payload.data.type
3564
3614
  }, {
3565
3615
  F: __dxlog_file14,
3566
- L: 271,
3616
+ L: 285,
3567
3617
  S: this,
3568
3618
  C: (f, a) => f(...a)
3569
3619
  });
@@ -3626,9 +3676,11 @@ var RtcPeerConnection = class {
3626
3676
  this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
3627
3677
  break;
3628
3678
  }
3629
- (0, import_log12.log)("signal processed", void 0, {
3679
+ (0, import_log12.log)("signal processed", {
3680
+ type: data.type
3681
+ }, {
3630
3682
  F: __dxlog_file14,
3631
- L: 330,
3683
+ L: 344,
3632
3684
  S: this,
3633
3685
  C: (f, a) => f(...a)
3634
3686
  });
@@ -3641,7 +3693,7 @@ var RtcPeerConnection = class {
3641
3693
  candidate
3642
3694
  }, {
3643
3695
  F: __dxlog_file14,
3644
- L: 338,
3696
+ L: 352,
3645
3697
  S: this,
3646
3698
  C: (f, a) => f(...a)
3647
3699
  });
@@ -3650,7 +3702,7 @@ var RtcPeerConnection = class {
3650
3702
  } catch (err) {
3651
3703
  import_log12.log.catch(err, void 0, {
3652
3704
  F: __dxlog_file14,
3653
- L: 342,
3705
+ L: 356,
3654
3706
  S: this,
3655
3707
  C: (f, a) => f(...a)
3656
3708
  });
@@ -3660,7 +3712,7 @@ var RtcPeerConnection = class {
3660
3712
  if (connection === this._connection) {
3661
3713
  (0, import_log12.log)("ready to process ice candidates", void 0, {
3662
3714
  F: __dxlog_file14,
3663
- L: 348,
3715
+ L: 362,
3664
3716
  S: this,
3665
3717
  C: (f, a) => f(...a)
3666
3718
  });
@@ -3668,7 +3720,7 @@ var RtcPeerConnection = class {
3668
3720
  } else {
3669
3721
  import_log12.log.warn("session was negotiated after connection became inactive", void 0, {
3670
3722
  F: __dxlog_file14,
3671
- L: 351,
3723
+ L: 365,
3672
3724
  S: this,
3673
3725
  C: (f, a) => f(...a)
3674
3726
  });
@@ -3680,7 +3732,7 @@ var RtcPeerConnection = class {
3680
3732
  state: connection.connectionState
3681
3733
  }, {
3682
3734
  F: __dxlog_file14,
3683
- L: 356,
3735
+ L: 370,
3684
3736
  S: this,
3685
3737
  C: (f, a) => f(...a)
3686
3738
  });
@@ -3693,7 +3745,7 @@ var RtcPeerConnection = class {
3693
3745
  } catch (err) {
3694
3746
  import_log12.log.catch(err, void 0, {
3695
3747
  F: __dxlog_file14,
3696
- L: 368,
3748
+ L: 382,
3697
3749
  S: this,
3698
3750
  C: (f, a) => f(...a)
3699
3751
  });
@@ -3704,7 +3756,7 @@ var RtcPeerConnection = class {
3704
3756
  this._readyForCandidates.wake();
3705
3757
  void this._factory.onConnectionDestroyed().catch((err) => import_log12.log.catch(err, void 0, {
3706
3758
  F: __dxlog_file14,
3707
- L: 374,
3759
+ L: 388,
3708
3760
  S: this,
3709
3761
  C: (f, a) => f(...a)
3710
3762
  }));
@@ -3729,7 +3781,7 @@ var RtcPeerConnection = class {
3729
3781
  } catch (error) {
3730
3782
  import_log12.log.catch(error, void 0, {
3731
3783
  F: __dxlog_file14,
3732
- L: 390,
3784
+ L: 404,
3733
3785
  S: this,
3734
3786
  C: (f, a) => f(...a)
3735
3787
  });
@@ -3756,7 +3808,7 @@ var RtcPeerConnection = class {
3756
3808
  err
3757
3809
  }, {
3758
3810
  F: __dxlog_file14,
3759
- L: 411,
3811
+ L: 425,
3760
3812
  S: this,
3761
3813
  C: (f, a) => f(...a)
3762
3814
  });
@@ -3844,6 +3896,7 @@ var createRtcTransportFactory = (webrtcConfig, iceProvider) => {
3844
3896
  ownPeerKey: options.ownPeerKey,
3845
3897
  remotePeerKey: options.remotePeerKey,
3846
3898
  sendSignal: options.sendSignal,
3899
+ legacyInitiator: options.initiator,
3847
3900
  webrtcConfig,
3848
3901
  iceProvider
3849
3902
  });
@@ -4176,7 +4229,6 @@ var RtcTransportService = class {
4176
4229
  connectorStream: transportStream,
4177
4230
  writeProcessedCallbacks: []
4178
4231
  };
4179
- pushNewState(import_bridge2.ConnectionState.CONNECTING);
4180
4232
  transport.connected.on(() => pushNewState(import_bridge2.ConnectionState.CONNECTED));
4181
4233
  transport.errors.handle(async (err) => {
4182
4234
  pushNewState(import_bridge2.ConnectionState.CLOSED, err);
@@ -4195,13 +4247,20 @@ var RtcTransportService = class {
4195
4247
  close(err);
4196
4248
  });
4197
4249
  ready();
4250
+ (0, import_log15.log)("stream ready", void 0, {
4251
+ F: __dxlog_file16,
4252
+ L: 115,
4253
+ S: this,
4254
+ C: (f, a) => f(...a)
4255
+ });
4256
+ pushNewState(import_bridge2.ConnectionState.CONNECTING);
4198
4257
  });
4199
4258
  }
4200
4259
  async sendSignal({ proxyId, signal }) {
4201
4260
  const transport = this._openTransports.get(proxyId);
4202
4261
  (0, import_invariant14.invariant)(transport, void 0, {
4203
4262
  F: __dxlog_file16,
4204
- L: 121,
4263
+ L: 123,
4205
4264
  S: this,
4206
4265
  A: [
4207
4266
  "transport",
@@ -4214,7 +4273,7 @@ var RtcTransportService = class {
4214
4273
  const transport = this._openTransports.get(proxyId);
4215
4274
  (0, import_invariant14.invariant)(transport, void 0, {
4216
4275
  F: __dxlog_file16,
4217
- L: 128,
4276
+ L: 130,
4218
4277
  S: this,
4219
4278
  A: [
4220
4279
  "transport",
@@ -4229,7 +4288,7 @@ var RtcTransportService = class {
4229
4288
  const transport = this._openTransports.get(proxyId);
4230
4289
  (0, import_invariant14.invariant)(transport, void 0, {
4231
4290
  F: __dxlog_file16,
4232
- L: 135,
4291
+ L: 137,
4233
4292
  S: this,
4234
4293
  A: [
4235
4294
  "transport",
@@ -4244,7 +4303,7 @@ var RtcTransportService = class {
4244
4303
  const transport = this._openTransports.get(proxyId);
4245
4304
  (0, import_invariant14.invariant)(transport, void 0, {
4246
4305
  F: __dxlog_file16,
4247
- L: 142,
4306
+ L: 144,
4248
4307
  S: this,
4249
4308
  A: [
4250
4309
  "transport",
@@ -4278,7 +4337,7 @@ var RtcTransportService = class {
4278
4337
  message: error?.message
4279
4338
  }, {
4280
4339
  F: __dxlog_file16,
4281
- L: 172,
4340
+ L: 174,
4282
4341
  S: this,
4283
4342
  C: (f, a) => f(...a)
4284
4343
  });
@@ -4290,14 +4349,14 @@ var RtcTransportService = class {
4290
4349
  message: error?.message
4291
4350
  }, {
4292
4351
  F: __dxlog_file16,
4293
- L: 177,
4352
+ L: 179,
4294
4353
  S: this,
4295
4354
  C: (f, a) => f(...a)
4296
4355
  });
4297
4356
  }
4298
4357
  (0, import_log15.log)("closed", void 0, {
4299
4358
  F: __dxlog_file16,
4300
- L: 179,
4359
+ L: 181,
4301
4360
  S: this,
4302
4361
  C: (f, a) => f(...a)
4303
4362
  });
@@ -4361,4 +4420,4 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
4361
4420
  createRtcTransportFactory,
4362
4421
  createTeleportProtocolFactory
4363
4422
  });
4364
- //# sourceMappingURL=chunk-D6P7ACEM.cjs.map
4423
+ //# sourceMappingURL=chunk-J5PWZKEH.cjs.map