@dxos/network-manager 0.8.4-main.c1de068 → 0.8.4-main.f5c0578

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 (66) hide show
  1. package/dist/lib/browser/{chunk-2XXESTV3.mjs → chunk-JUVDHWW4.mjs} +308 -164
  2. package/dist/lib/browser/chunk-JUVDHWW4.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 +32 -5
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/browser/transport/tcp/index.mjs +3 -5
  8. package/dist/lib/browser/transport/tcp/index.mjs.map +1 -1
  9. package/dist/lib/node-esm/{chunk-RPB6YS7U.mjs → chunk-HUSU3OKQ.mjs} +308 -164
  10. package/dist/lib/node-esm/chunk-HUSU3OKQ.mjs.map +7 -0
  11. package/dist/lib/node-esm/index.mjs +1 -1
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +32 -5
  14. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  15. package/dist/lib/node-esm/transport/tcp/index.mjs +8 -0
  16. package/dist/lib/node-esm/transport/tcp/index.mjs.map +3 -3
  17. package/dist/types/src/connection-log.d.ts.map +1 -1
  18. package/dist/types/src/network-manager.d.ts.map +1 -1
  19. package/dist/types/src/signal/swarm-messenger.d.ts +1 -1
  20. package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
  21. package/dist/types/src/swarm/peer.d.ts +2 -2
  22. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  23. package/dist/types/src/swarm/swarm.d.ts +3 -3
  24. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  25. package/dist/types/src/testing/test-builder.d.ts +1 -1
  26. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  27. package/dist/types/src/testing/test-wire-protocol.d.ts +1 -1
  28. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
  29. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  30. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +2 -2
  31. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
  32. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts +1 -1
  33. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
  34. package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
  35. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts +1 -1
  36. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
  37. package/dist/types/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +22 -18
  39. package/src/connection-log.ts +1 -1
  40. package/src/network-manager.ts +1 -1
  41. package/src/signal/ice.test.ts +1 -1
  42. package/src/signal/integration.node.test.ts +2 -2
  43. package/src/signal/swarm-messenger.node.test.ts +1 -1
  44. package/src/signal/swarm-messenger.ts +1 -1
  45. package/src/swarm/connection.test.ts +2 -1
  46. package/src/swarm/connection.ts +3 -3
  47. package/src/swarm/peer.ts +3 -2
  48. package/src/swarm/swarm-mapper.ts +1 -1
  49. package/src/swarm/swarm.test.ts +5 -4
  50. package/src/swarm/swarm.ts +5 -4
  51. package/src/testing/test-builder.ts +11 -4
  52. package/src/testing/test-wire-protocol.ts +2 -2
  53. package/src/tests/basic-test-suite.ts +3 -2
  54. package/src/tests/memory-transport.test.ts +4 -2
  55. package/src/tests/tcp-transport.node.test.ts +4 -2
  56. package/src/tests/webrtc-transport.test.ts +2 -1
  57. package/src/transport/tcp/tcp-transport.ts +1 -1
  58. package/src/transport/webrtc/rtc-peer-connection.ts +4 -3
  59. package/src/transport/webrtc/rtc-transport-channel.test.ts +3 -1
  60. package/src/transport/webrtc/rtc-transport-channel.ts +2 -1
  61. package/src/transport/webrtc/rtc-transport-factory.ts +3 -2
  62. package/src/transport/webrtc/rtc-transport-proxy.test.ts +5 -3
  63. package/src/transport/webrtc/rtc-transport-service.ts +6 -5
  64. package/src/transport/webrtc/rtc-transport.test.ts +4 -3
  65. package/dist/lib/browser/chunk-2XXESTV3.mjs.map +0 -7
  66. package/dist/lib/node-esm/chunk-RPB6YS7U.mjs.map +0 -7
@@ -1,13 +1,13 @@
1
1
  import "@dxos/node-std/globals";
2
2
 
3
3
  // src/swarm/connection.ts
4
- import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized, Trigger } from "@dxos/async";
5
- import { Context, cancelWithContext, ContextDisposedError } from "@dxos/context";
4
+ import { DeferredTask, Event, Trigger, scheduleTask, scheduleTaskInterval, sleep, synchronized } from "@dxos/async";
5
+ import { Context, ContextDisposedError, cancelWithContext } from "@dxos/context";
6
6
  import { ErrorStream } from "@dxos/debug";
7
7
  import { invariant } from "@dxos/invariant";
8
8
  import { PublicKey } from "@dxos/keys";
9
9
  import { log, logInfo } from "@dxos/log";
10
- import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, TimeoutError, trace } from "@dxos/protocols";
10
+ import { CancelledError, ConnectionResetError, ConnectivityError, ProtocolError, TimeoutError, trace } from "@dxos/protocols";
11
11
  function _ts_decorate(decorators, target, key, desc) {
12
12
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13
13
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -31,6 +31,30 @@ var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
31
31
  return ConnectionState5;
32
32
  }({});
33
33
  var Connection = class {
34
+ topic;
35
+ localInfo;
36
+ remoteInfo;
37
+ sessionId;
38
+ initiator;
39
+ _signalMessaging;
40
+ _protocol;
41
+ _transportFactory;
42
+ _callbacks;
43
+ _ctx;
44
+ connectedTimeoutContext;
45
+ _protocolClosed;
46
+ _transportClosed;
47
+ _state;
48
+ _transport;
49
+ closeReason;
50
+ _incomingSignalBuffer;
51
+ _outgoingSignalBuffer;
52
+ stateChanged;
53
+ errors;
54
+ _instanceId;
55
+ transportStats;
56
+ _signalSendTask;
57
+ _signallingDelay;
34
58
  constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
35
59
  this.topic = topic;
36
60
  this.localInfo = localInfo;
@@ -641,12 +665,16 @@ import { ComplexMap } from "@dxos/util";
641
665
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
642
666
  var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
643
667
  var SwarmMessenger = class {
668
+ _ctx = new Context2(void 0, {
669
+ F: __dxlog_file3,
670
+ L: 35
671
+ });
672
+ _sendMessage;
673
+ _onSignal;
674
+ _onOffer;
675
+ _topic;
676
+ _offerRecords = new ComplexMap((key) => key.toHex());
644
677
  constructor({ sendMessage, onSignal, onOffer, topic }) {
645
- this._ctx = new Context2(void 0, {
646
- F: __dxlog_file3,
647
- L: 35
648
- });
649
- this._offerRecords = new ComplexMap((key) => key.toHex());
650
678
  this._sendMessage = sendMessage;
651
679
  this._onSignal = onSignal;
652
680
  this._onOffer = onOffer;
@@ -909,6 +937,29 @@ var ConnectionDisplacedError = class extends SystemError {
909
937
  };
910
938
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
911
939
  var Peer = class {
940
+ remoteInfo;
941
+ topic;
942
+ localInfo;
943
+ _signalMessaging;
944
+ _protocolProvider;
945
+ _transportFactory;
946
+ _connectionLimiter;
947
+ _callbacks;
948
+ /**
949
+ * Will be available to connect after this time.
950
+ */
951
+ _availableAfter;
952
+ availableToConnect;
953
+ _lastConnectionTime;
954
+ _ctx;
955
+ _connectionCtx;
956
+ connection;
957
+ /**
958
+ * Whether the peer is currently advertizing itself on the signal-network.
959
+ */
960
+ advertizing;
961
+ initiating;
962
+ connectionDisplaced;
912
963
  constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
913
964
  this.remoteInfo = remoteInfo;
914
965
  this.topic = topic;
@@ -922,7 +973,7 @@ var Peer = class {
922
973
  this.availableToConnect = true;
923
974
  this._ctx = new Context3(void 0, {
924
975
  F: __dxlog_file4,
925
- L: 80
976
+ L: 81
926
977
  });
927
978
  this.advertizing = false;
928
979
  this.initiating = false;
@@ -940,7 +991,7 @@ var Peer = class {
940
991
  ].includes(this.connection.state)) {
941
992
  log4.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
942
993
  F: __dxlog_file4,
943
- L: 115,
994
+ L: 116,
944
995
  S: this,
945
996
  C: (f, a) => f(...a)
946
997
  });
@@ -957,7 +1008,7 @@ var Peer = class {
957
1008
  sessionId: this.connection?.sessionId
958
1009
  }, {
959
1010
  F: __dxlog_file4,
960
- L: 124,
1011
+ L: 125,
961
1012
  S: this,
962
1013
  C: (f, a) => f(...a)
963
1014
  });
@@ -974,7 +1025,7 @@ var Peer = class {
974
1025
  if (!this.connection) {
975
1026
  invariant3(message.sessionId, void 0, {
976
1027
  F: __dxlog_file4,
977
- L: 144,
1028
+ L: 145,
978
1029
  S: this,
979
1030
  A: [
980
1031
  "message.sessionId",
@@ -995,7 +1046,7 @@ var Peer = class {
995
1046
  err
996
1047
  }, {
997
1048
  F: __dxlog_file4,
998
- L: 154,
1049
+ L: 155,
999
1050
  S: this,
1000
1051
  C: (f, a) => f(...a)
1001
1052
  });
@@ -1017,7 +1068,7 @@ var Peer = class {
1017
1068
  async initiateConnection() {
1018
1069
  invariant3(!this.initiating, "Initiation in progress.", {
1019
1070
  F: __dxlog_file4,
1020
- L: 171,
1071
+ L: 172,
1021
1072
  S: this,
1022
1073
  A: [
1023
1074
  "!this.initiating",
@@ -1026,7 +1077,7 @@ var Peer = class {
1026
1077
  });
1027
1078
  invariant3(!this.connection, "Already connected.", {
1028
1079
  F: __dxlog_file4,
1029
- L: 172,
1080
+ L: 173,
1030
1081
  S: this,
1031
1082
  A: [
1032
1083
  "!this.connection",
@@ -1041,7 +1092,7 @@ var Peer = class {
1041
1092
  sessionId
1042
1093
  }, {
1043
1094
  F: __dxlog_file4,
1044
- L: 174,
1095
+ L: 175,
1045
1096
  S: this,
1046
1097
  C: (f, a) => f(...a)
1047
1098
  });
@@ -1067,14 +1118,14 @@ var Peer = class {
1067
1118
  remote: this.remoteInfo
1068
1119
  }, {
1069
1120
  F: __dxlog_file4,
1070
- L: 191,
1121
+ L: 192,
1071
1122
  S: this,
1072
1123
  C: (f, a) => f(...a)
1073
1124
  });
1074
1125
  if (connection.state !== ConnectionState.INITIAL) {
1075
1126
  log4("ignoring response", void 0, {
1076
1127
  F: __dxlog_file4,
1077
- L: 193,
1128
+ L: 194,
1078
1129
  S: this,
1079
1130
  C: (f, a) => f(...a)
1080
1131
  });
@@ -1088,7 +1139,7 @@ var Peer = class {
1088
1139
  remote: this.remoteInfo
1089
1140
  }, {
1090
1141
  F: __dxlog_file4,
1091
- L: 197,
1142
+ L: 198,
1092
1143
  S: this,
1093
1144
  C: (f, a) => f(...a)
1094
1145
  });
@@ -1110,7 +1161,7 @@ var Peer = class {
1110
1161
  remote: this.remoteInfo
1111
1162
  }, {
1112
1163
  F: __dxlog_file4,
1113
- L: 210,
1164
+ L: 211,
1114
1165
  S: this,
1115
1166
  C: (f, a) => f(...a)
1116
1167
  });
@@ -1122,7 +1173,7 @@ var Peer = class {
1122
1173
  try {
1123
1174
  log4("opening connection as initiator", void 0, {
1124
1175
  F: __dxlog_file4,
1125
- L: 223,
1176
+ L: 224,
1126
1177
  S: this,
1127
1178
  C: (f, a) => f(...a)
1128
1179
  });
@@ -1136,7 +1187,7 @@ var Peer = class {
1136
1187
  remote: this.remoteInfo
1137
1188
  }, {
1138
1189
  F: __dxlog_file4,
1139
- L: 227,
1190
+ L: 228,
1140
1191
  S: this,
1141
1192
  C: (f, a) => f(...a)
1142
1193
  });
@@ -1144,7 +1195,7 @@ var Peer = class {
1144
1195
  err
1145
1196
  }, {
1146
1197
  F: __dxlog_file4,
1147
- L: 234,
1198
+ L: 235,
1148
1199
  S: this,
1149
1200
  C: (f, a) => f(...a)
1150
1201
  });
@@ -1167,13 +1218,13 @@ var Peer = class {
1167
1218
  sessionId
1168
1219
  }, {
1169
1220
  F: __dxlog_file4,
1170
- L: 248,
1221
+ L: 249,
1171
1222
  S: this,
1172
1223
  C: (f, a) => f(...a)
1173
1224
  });
1174
1225
  invariant3(!this.connection, "Already connected.", {
1175
1226
  F: __dxlog_file4,
1176
- L: 255,
1227
+ L: 256,
1177
1228
  S: this,
1178
1229
  A: [
1179
1230
  "!this.connection",
@@ -1209,7 +1260,7 @@ var Peer = class {
1209
1260
  initiator
1210
1261
  }, {
1211
1262
  F: __dxlog_file4,
1212
- L: 279,
1263
+ L: 280,
1213
1264
  S: this,
1214
1265
  C: (f, a) => f(...a)
1215
1266
  });
@@ -1223,14 +1274,14 @@ var Peer = class {
1223
1274
  };
1224
1275
  log4("connection closed", logMeta, {
1225
1276
  F: __dxlog_file4,
1226
- L: 289,
1277
+ L: 290,
1227
1278
  S: this,
1228
1279
  C: (f, a) => f(...a)
1229
1280
  });
1230
1281
  this._connectionLimiter.doneConnecting(sessionId);
1231
1282
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1232
1283
  F: __dxlog_file4,
1233
- L: 294,
1284
+ L: 295,
1234
1285
  S: this,
1235
1286
  A: [
1236
1287
  "this.connection === connection",
@@ -1245,7 +1296,7 @@ var Peer = class {
1245
1296
  initiator
1246
1297
  }, {
1247
1298
  F: __dxlog_file4,
1248
- L: 296,
1299
+ L: 297,
1249
1300
  S: this,
1250
1301
  C: (f, a) => f(...a)
1251
1302
  });
@@ -1262,7 +1313,7 @@ var Peer = class {
1262
1313
  scheduleTask2(this._connectionCtx, () => {
1263
1314
  log4("peer became available", logMeta, {
1264
1315
  F: __dxlog_file4,
1265
- L: 320,
1316
+ L: 321,
1266
1317
  S: this,
1267
1318
  C: (f, a) => f(...a)
1268
1319
  });
@@ -1286,7 +1337,7 @@ var Peer = class {
1286
1337
  err
1287
1338
  }, {
1288
1339
  F: __dxlog_file4,
1289
- L: 338,
1340
+ L: 339,
1290
1341
  S: this,
1291
1342
  C: (f, a) => f(...a)
1292
1343
  });
@@ -1299,7 +1350,7 @@ var Peer = class {
1299
1350
  err
1300
1351
  }, {
1301
1352
  F: __dxlog_file4,
1302
- L: 345,
1353
+ L: 346,
1303
1354
  S: this,
1304
1355
  C: (f, a) => f(...a)
1305
1356
  });
@@ -1318,7 +1369,7 @@ var Peer = class {
1318
1369
  sessionId: connection.sessionId
1319
1370
  }, {
1320
1371
  F: __dxlog_file4,
1321
- L: 370,
1372
+ L: 371,
1322
1373
  S: this,
1323
1374
  C: (f, a) => f(...a)
1324
1375
  });
@@ -1330,7 +1381,7 @@ var Peer = class {
1330
1381
  sessionId: connection.sessionId
1331
1382
  }, {
1332
1383
  F: __dxlog_file4,
1333
- L: 376,
1384
+ L: 377,
1334
1385
  S: this,
1335
1386
  C: (f, a) => f(...a)
1336
1387
  });
@@ -1341,7 +1392,7 @@ var Peer = class {
1341
1392
  message
1342
1393
  }, {
1343
1394
  F: __dxlog_file4,
1344
- L: 381,
1395
+ L: 382,
1345
1396
  S: this,
1346
1397
  C: (f, a) => f(...a)
1347
1398
  });
@@ -1356,7 +1407,7 @@ var Peer = class {
1356
1407
  topic: this.topic
1357
1408
  }, {
1358
1409
  F: __dxlog_file4,
1359
- L: 391,
1410
+ L: 392,
1360
1411
  S: this,
1361
1412
  C: (f, a) => f(...a)
1362
1413
  });
@@ -1392,6 +1443,43 @@ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm
1392
1443
  var INITIATION_DELAY = 100;
1393
1444
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1394
1445
  var Swarm = class {
1446
+ _topic;
1447
+ _ownPeer;
1448
+ _topology;
1449
+ _protocolProvider;
1450
+ _messenger;
1451
+ _transportFactory;
1452
+ _label;
1453
+ _connectionLimiter;
1454
+ _initiationDelay;
1455
+ _swarmMessenger;
1456
+ _ctx;
1457
+ _listeningHandle;
1458
+ /**
1459
+ * PeerInfo -> Peer.
1460
+ * @internal
1461
+ */
1462
+ _peers;
1463
+ /**
1464
+ * Unique id of the swarm, local to the current peer, generated when swarm is joined.
1465
+ */
1466
+ _instanceId;
1467
+ /**
1468
+ * New connection to a peer is started.
1469
+ * @internal
1470
+ */
1471
+ connectionAdded;
1472
+ /**
1473
+ * Connection to a peer is dropped.
1474
+ * @internal
1475
+ */
1476
+ disconnected;
1477
+ /**
1478
+ * Connection is established to a new peer.
1479
+ * @internal
1480
+ */
1481
+ connected;
1482
+ errors;
1395
1483
  // TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
1396
1484
  // TODO(burdon): Pass in object.
1397
1485
  constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
@@ -1406,7 +1494,7 @@ var Swarm = class {
1406
1494
  this._initiationDelay = _initiationDelay;
1407
1495
  this._ctx = new Context4(void 0, {
1408
1496
  F: __dxlog_file5,
1409
- L: 38
1497
+ L: 39
1410
1498
  });
1411
1499
  this._listeningHandle = void 0;
1412
1500
  this._peers = new ComplexMap2(PeerInfoHash);
@@ -1423,7 +1511,7 @@ var Swarm = class {
1423
1511
  }
1424
1512
  }), {
1425
1513
  F: __dxlog_file5,
1426
- L: 88,
1514
+ L: 89,
1427
1515
  S: this,
1428
1516
  C: (f, a) => f(...a)
1429
1517
  });
@@ -1431,7 +1519,7 @@ var Swarm = class {
1431
1519
  peerId: _ownPeer
1432
1520
  }, {
1433
1521
  F: __dxlog_file5,
1434
- L: 92,
1522
+ L: 93,
1435
1523
  S: this,
1436
1524
  C: (f, a) => f(...a)
1437
1525
  });
@@ -1446,7 +1534,7 @@ var Swarm = class {
1446
1534
  id: this._instanceId
1447
1535
  }), {
1448
1536
  F: __dxlog_file5,
1449
- L: 101,
1537
+ L: 102,
1450
1538
  S: this,
1451
1539
  C: (f, a) => f(...a)
1452
1540
  });
@@ -1472,7 +1560,7 @@ var Swarm = class {
1472
1560
  async open() {
1473
1561
  invariant4(!this._listeningHandle, void 0, {
1474
1562
  F: __dxlog_file5,
1475
- L: 132,
1563
+ L: 133,
1476
1564
  S: this,
1477
1565
  A: [
1478
1566
  "!this._listeningHandle",
@@ -1487,7 +1575,7 @@ var Swarm = class {
1487
1575
  err
1488
1576
  }, {
1489
1577
  F: __dxlog_file5,
1490
- L: 140,
1578
+ L: 141,
1491
1579
  S: this,
1492
1580
  C: (f, a) => f(...a)
1493
1581
  }));
@@ -1497,7 +1585,7 @@ var Swarm = class {
1497
1585
  async destroy() {
1498
1586
  log5("destroying...", void 0, {
1499
1587
  F: __dxlog_file5,
1500
- L: 146,
1588
+ L: 147,
1501
1589
  S: this,
1502
1590
  C: (f, a) => f(...a)
1503
1591
  });
@@ -1508,7 +1596,7 @@ var Swarm = class {
1508
1596
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
1509
1597
  log5("destroyed", void 0, {
1510
1598
  F: __dxlog_file5,
1511
- L: 153,
1599
+ L: 154,
1512
1600
  S: this,
1513
1601
  C: (f, a) => f(...a)
1514
1602
  });
@@ -1516,7 +1604,7 @@ var Swarm = class {
1516
1604
  async setTopology(topology) {
1517
1605
  invariant4(!this._ctx.disposed, "Swarm is offline", {
1518
1606
  F: __dxlog_file5,
1519
- L: 157,
1607
+ L: 158,
1520
1608
  S: this,
1521
1609
  A: [
1522
1610
  "!this._ctx.disposed",
@@ -1531,7 +1619,7 @@ var Swarm = class {
1531
1619
  topology: getClassName(topology)
1532
1620
  }, {
1533
1621
  F: __dxlog_file5,
1534
- L: 161,
1622
+ L: 162,
1535
1623
  S: this,
1536
1624
  C: (f, a) => f(...a)
1537
1625
  });
@@ -1545,14 +1633,14 @@ var Swarm = class {
1545
1633
  swarmEvent
1546
1634
  }, {
1547
1635
  F: __dxlog_file5,
1548
- L: 174,
1636
+ L: 175,
1549
1637
  S: this,
1550
1638
  C: (f, a) => f(...a)
1551
1639
  });
1552
1640
  if (this._ctx.disposed) {
1553
1641
  log5("swarm event ignored for disposed swarm", void 0, {
1554
1642
  F: __dxlog_file5,
1555
- L: 177,
1643
+ L: 178,
1556
1644
  S: this,
1557
1645
  C: (f, a) => f(...a)
1558
1646
  });
@@ -1565,7 +1653,7 @@ var Swarm = class {
1565
1653
  peerId
1566
1654
  }, {
1567
1655
  F: __dxlog_file5,
1568
- L: 184,
1656
+ L: 185,
1569
1657
  S: this,
1570
1658
  C: (f, a) => f(...a)
1571
1659
  });
@@ -1579,13 +1667,13 @@ var Swarm = class {
1579
1667
  if (this._isConnectionEstablishmentInProgress(peer)) {
1580
1668
  log5(`destroying peer, state: ${peer.connection?.state}`, void 0, {
1581
1669
  F: __dxlog_file5,
1582
- L: 195,
1670
+ L: 196,
1583
1671
  S: this,
1584
1672
  C: (f, a) => f(...a)
1585
1673
  });
1586
1674
  void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log5.catch(err, void 0, {
1587
1675
  F: __dxlog_file5,
1588
- L: 196,
1676
+ L: 197,
1589
1677
  S: this,
1590
1678
  C: (f, a) => f(...a)
1591
1679
  }));
@@ -1595,7 +1683,7 @@ var Swarm = class {
1595
1683
  peer: swarmEvent.peerLeft.peer.peerKey
1596
1684
  }, {
1597
1685
  F: __dxlog_file5,
1598
- L: 199,
1686
+ L: 200,
1599
1687
  S: this,
1600
1688
  C: (f, a) => f(...a)
1601
1689
  });
@@ -1608,14 +1696,14 @@ var Swarm = class {
1608
1696
  message
1609
1697
  }, {
1610
1698
  F: __dxlog_file5,
1611
- L: 208,
1699
+ L: 209,
1612
1700
  S: this,
1613
1701
  C: (f, a) => f(...a)
1614
1702
  });
1615
1703
  if (this._ctx.disposed) {
1616
1704
  log5("ignored for disposed swarm", void 0, {
1617
1705
  F: __dxlog_file5,
1618
- L: 210,
1706
+ L: 211,
1619
1707
  S: this,
1620
1708
  C: (f, a) => f(...a)
1621
1709
  });
@@ -1625,7 +1713,7 @@ var Swarm = class {
1625
1713
  }
1626
1714
  invariant4(message.author, void 0, {
1627
1715
  F: __dxlog_file5,
1628
- L: 215,
1716
+ L: 216,
1629
1717
  S: this,
1630
1718
  A: [
1631
1719
  "message.author",
@@ -1637,7 +1725,7 @@ var Swarm = class {
1637
1725
  message
1638
1726
  }, {
1639
1727
  F: __dxlog_file5,
1640
- L: 217,
1728
+ L: 218,
1641
1729
  S: this,
1642
1730
  C: (f, a) => f(...a)
1643
1731
  });
@@ -1650,7 +1738,7 @@ var Swarm = class {
1650
1738
  message
1651
1739
  }, {
1652
1740
  F: __dxlog_file5,
1653
- L: 221,
1741
+ L: 222,
1654
1742
  S: this,
1655
1743
  C: (f, a) => f(...a)
1656
1744
  });
@@ -1678,14 +1766,14 @@ var Swarm = class {
1678
1766
  message
1679
1767
  }, {
1680
1768
  F: __dxlog_file5,
1681
- L: 246,
1769
+ L: 247,
1682
1770
  S: this,
1683
1771
  C: (f, a) => f(...a)
1684
1772
  });
1685
1773
  if (this._ctx.disposed) {
1686
1774
  log5.info("ignored for offline swarm", void 0, {
1687
1775
  F: __dxlog_file5,
1688
- L: 248,
1776
+ L: 249,
1689
1777
  S: this,
1690
1778
  C: (f, a) => f(...a)
1691
1779
  });
@@ -1693,7 +1781,7 @@ var Swarm = class {
1693
1781
  }
1694
1782
  invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1695
1783
  F: __dxlog_file5,
1696
- L: 251,
1784
+ L: 252,
1697
1785
  S: this,
1698
1786
  A: [
1699
1787
  "message.recipient.peerKey === this._ownPeer.peerKey",
@@ -1702,7 +1790,7 @@ var Swarm = class {
1702
1790
  });
1703
1791
  invariant4(message.topic?.equals(this._topic), void 0, {
1704
1792
  F: __dxlog_file5,
1705
- L: 255,
1793
+ L: 256,
1706
1794
  S: this,
1707
1795
  A: [
1708
1796
  "message.topic?.equals(this._topic)",
@@ -1711,7 +1799,7 @@ var Swarm = class {
1711
1799
  });
1712
1800
  invariant4(message.author, void 0, {
1713
1801
  F: __dxlog_file5,
1714
- L: 256,
1802
+ L: 257,
1715
1803
  S: this,
1716
1804
  A: [
1717
1805
  "message.author",
@@ -1732,13 +1820,13 @@ var Swarm = class {
1732
1820
  async goOnline() {
1733
1821
  this._ctx = new Context4(void 0, {
1734
1822
  F: __dxlog_file5,
1735
- L: 272
1823
+ L: 273
1736
1824
  });
1737
1825
  }
1738
1826
  _getOrCreatePeer(peerInfo) {
1739
1827
  invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
1740
1828
  F: __dxlog_file5,
1741
- L: 276,
1829
+ L: 277,
1742
1830
  S: this,
1743
1831
  A: [
1744
1832
  "peerInfo.peerKey",
@@ -1758,7 +1846,7 @@ var Swarm = class {
1758
1846
  if (this._isUnregistered(peer)) {
1759
1847
  log5.verbose("ignored onDisconnected for unregistered peer", void 0, {
1760
1848
  F: __dxlog_file5,
1761
- L: 296,
1849
+ L: 297,
1762
1850
  S: this,
1763
1851
  C: (f, a) => f(...a)
1764
1852
  });
@@ -1776,7 +1864,7 @@ var Swarm = class {
1776
1864
  peerInfo
1777
1865
  }, {
1778
1866
  F: __dxlog_file5,
1779
- L: 310,
1867
+ L: 311,
1780
1868
  S: this,
1781
1869
  C: (f, a) => f(...a)
1782
1870
  });
@@ -1803,14 +1891,14 @@ var Swarm = class {
1803
1891
  reason
1804
1892
  }, {
1805
1893
  F: __dxlog_file5,
1806
- L: 332,
1894
+ L: 333,
1807
1895
  S: this,
1808
1896
  C: (f, a) => f(...a)
1809
1897
  });
1810
1898
  const peer = this._peers.get(peerInfo);
1811
1899
  invariant4(peer, void 0, {
1812
1900
  F: __dxlog_file5,
1813
- L: 334,
1901
+ L: 335,
1814
1902
  S: this,
1815
1903
  A: [
1816
1904
  "peer",
@@ -1840,7 +1928,7 @@ var Swarm = class {
1840
1928
  } catch (err) {
1841
1929
  log5("initiation error", err, {
1842
1930
  F: __dxlog_file5,
1843
- L: 361,
1931
+ L: 362,
1844
1932
  S: this,
1845
1933
  C: (f, a) => f(...a)
1846
1934
  });
@@ -1871,7 +1959,7 @@ var Swarm = class {
1871
1959
  remotePeer
1872
1960
  }, {
1873
1961
  F: __dxlog_file5,
1874
- L: 389,
1962
+ L: 390,
1875
1963
  S: this,
1876
1964
  C: (f, a) => f(...a)
1877
1965
  });
@@ -1890,7 +1978,7 @@ var Swarm = class {
1890
1978
  remotePeer
1891
1979
  }, {
1892
1980
  F: __dxlog_file5,
1893
- L: 405,
1981
+ L: 406,
1894
1982
  S: this,
1895
1983
  C: (f, a) => f(...a)
1896
1984
  });
@@ -1900,7 +1988,7 @@ var Swarm = class {
1900
1988
  remotePeer
1901
1989
  }, {
1902
1990
  F: __dxlog_file5,
1903
- L: 408,
1991
+ L: 409,
1904
1992
  S: this,
1905
1993
  C: (f, a) => f(...a)
1906
1994
  });
@@ -1956,6 +2044,11 @@ import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
1956
2044
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
1957
2045
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1958
2046
  var SwarmMapper = class {
2047
+ _swarm;
2048
+ _subscriptions;
2049
+ _connectionSubscriptions;
2050
+ _peers;
2051
+ mapUpdated;
1959
2052
  get peers() {
1960
2053
  return Array.from(this._peers.values());
1961
2054
  }
@@ -2030,20 +2123,21 @@ import { ComplexMap as ComplexMap4 } from "@dxos/util";
2030
2123
  var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2031
2124
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2032
2125
  var ConnectionLimiter = class {
2033
- constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2034
- this._ctx = new Context5(void 0, {
2035
- F: __dxlog_file7,
2036
- L: 23
2037
- });
2038
- /**
2039
- * Queue of promises to resolve when initiating connections amount is below the limit.
2040
- */
2041
- this._waitingPromises = new ComplexMap4(PublicKey6.hash);
2042
- this.resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
2043
- Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
2044
- resolve();
2045
- });
2126
+ _ctx = new Context5(void 0, {
2127
+ F: __dxlog_file7,
2128
+ L: 23
2129
+ });
2130
+ _maxConcurrentInitConnections;
2131
+ /**
2132
+ * Queue of promises to resolve when initiating connections amount is below the limit.
2133
+ */
2134
+ _waitingPromises = new ComplexMap4(PublicKey6.hash);
2135
+ resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
2136
+ Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
2137
+ resolve();
2046
2138
  });
2139
+ });
2140
+ constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2047
2141
  this._maxConcurrentInitConnections = maxConcurrentInitConnections;
2048
2142
  }
2049
2143
  /**
@@ -2119,13 +2213,11 @@ var EventType = /* @__PURE__ */ function(EventType2) {
2119
2213
  return EventType2;
2120
2214
  }({});
2121
2215
  var ConnectionLog = class {
2122
- constructor() {
2123
- /**
2124
- * SwarmId => info
2125
- */
2126
- this._swarms = new ComplexMap5(PublicKey7.hash);
2127
- this.update = new Event5();
2128
- }
2216
+ /**
2217
+ * SwarmId => info
2218
+ */
2219
+ _swarms = new ComplexMap5(PublicKey7.hash);
2220
+ update = new Event5();
2129
2221
  getSwarmInfo(swarmId) {
2130
2222
  return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
2131
2223
  }
@@ -2213,17 +2305,23 @@ function _ts_decorate4(decorators, target, key, desc) {
2213
2305
  }
2214
2306
  var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2215
2307
  var SwarmNetworkManager = class {
2308
+ /**
2309
+ * @internal
2310
+ */
2311
+ _swarms = new ComplexMap6(PublicKey8.hash);
2312
+ _mappers = new ComplexMap6(PublicKey8.hash);
2313
+ _transportFactory;
2314
+ _signalManager;
2315
+ _messenger;
2316
+ _signalConnection;
2317
+ _connectionLimiter;
2318
+ _connectionLog;
2319
+ _instanceId = PublicKey8.random().toHex();
2320
+ _peerInfo = void 0;
2321
+ _connectionState = ConnectionState2.ONLINE;
2322
+ connectionStateChanged = new Event6();
2323
+ topicsUpdated = new Event6();
2216
2324
  constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }) {
2217
- /**
2218
- * @internal
2219
- */
2220
- this._swarms = new ComplexMap6(PublicKey8.hash);
2221
- this._mappers = new ComplexMap6(PublicKey8.hash);
2222
- this._instanceId = PublicKey8.random().toHex();
2223
- this._peerInfo = void 0;
2224
- this._connectionState = ConnectionState2.ONLINE;
2225
- this.connectionStateChanged = new Event6();
2226
- this.topicsUpdated = new Event6();
2227
2325
  this._transportFactory = transportFactory;
2228
2326
  this._signalManager = signalManager;
2229
2327
  this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
@@ -2460,6 +2558,7 @@ _ts_decorate4([
2460
2558
  import { invariant as invariant7 } from "@dxos/invariant";
2461
2559
  var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2462
2560
  var FullyConnectedTopology = class {
2561
+ _controller;
2463
2562
  toString() {
2464
2563
  return "FullyConnectedTopology";
2465
2564
  }
@@ -2504,9 +2603,13 @@ var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topo
2504
2603
  var MIN_UPDATE_INTERVAL = 1e3 * 10;
2505
2604
  var MAX_CHANGES_PER_UPDATE = 1;
2506
2605
  var MMSTTopology = class {
2606
+ _originateConnections;
2607
+ _maxPeers;
2608
+ _sampleSize;
2609
+ _controller;
2610
+ _sampleCollected = false;
2611
+ _lastAction = /* @__PURE__ */ new Date(0);
2507
2612
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2508
- this._sampleCollected = false;
2509
- this._lastAction = /* @__PURE__ */ new Date(0);
2510
2613
  this._originateConnections = originateConnections;
2511
2614
  this._maxPeers = maxPeers;
2512
2615
  this._sampleSize = sampleSize;
@@ -2708,6 +2811,8 @@ import { invariant as invariant9 } from "@dxos/invariant";
2708
2811
  import { log as log10 } from "@dxos/log";
2709
2812
  var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2710
2813
  var StarTopology = class {
2814
+ _centralPeer;
2815
+ _controller;
2711
2816
  constructor(_centralPeer) {
2712
2817
  this._centralPeer = _centralPeer;
2713
2818
  }
@@ -2827,10 +2932,19 @@ var MemoryTransportFactory = {
2827
2932
  createTransport: (options) => new MemoryTransport(options)
2828
2933
  };
2829
2934
  var MemoryTransport = class _MemoryTransport {
2830
- static {
2831
- // TODO(burdon): Remove static properties (inject context into constructor).
2832
- this._connections = new ComplexMap7(PublicKey9.hash);
2833
- }
2935
+ _options;
2936
+ // TODO(burdon): Remove static properties (inject context into constructor).
2937
+ static _connections = new ComplexMap7(PublicKey9.hash);
2938
+ _instanceId;
2939
+ _remote;
2940
+ _outgoingDelay;
2941
+ _incomingDelay;
2942
+ _closed;
2943
+ _remoteInstanceId;
2944
+ _remoteConnection;
2945
+ closed;
2946
+ connected;
2947
+ errors;
2834
2948
  constructor(_options) {
2835
2949
  this._options = _options;
2836
2950
  this._instanceId = PublicKey9.random();
@@ -3014,12 +3128,8 @@ var BrowserRtcConnectionFactory = class {
3014
3128
  }
3015
3129
  };
3016
3130
  var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
3017
- static {
3018
- this._createdConnections = 0;
3019
- }
3020
- static {
3021
- this._cleanupMutex = new Mutex();
3022
- }
3131
+ static _createdConnections = 0;
3132
+ static _cleanupMutex = new Mutex();
3023
3133
  // This should be inside the function to avoid triggering `eval` in the global scope.
3024
3134
  // eslint-disable-next-line @typescript-eslint/no-implied-eval
3025
3135
  // TODO(burdon): Do imports here?
@@ -3050,7 +3160,7 @@ var getRtcConnectionFactory = () => {
3050
3160
  };
3051
3161
 
3052
3162
  // src/transport/webrtc/rtc-peer-connection.ts
3053
- import { synchronized as synchronized5, Trigger as Trigger3, Mutex as Mutex2 } from "@dxos/async";
3163
+ import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
3054
3164
  import { invariant as invariant12 } from "@dxos/invariant";
3055
3165
  import { log as log13, logInfo as logInfo4 } from "@dxos/log";
3056
3166
  import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
@@ -3117,6 +3227,15 @@ var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/tran
3117
3227
  var MAX_MESSAGE_SIZE = 64 * 1024;
3118
3228
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3119
3229
  var RtcTransportChannel = class extends Resource {
3230
+ _connection;
3231
+ _options;
3232
+ closed;
3233
+ connected;
3234
+ errors;
3235
+ _channel;
3236
+ _stream;
3237
+ _streamDataFlushedCallback;
3238
+ _isChannelCreationInProgress;
3120
3239
  constructor(_connection, _options) {
3121
3240
  super(), this._connection = _connection, this._options = _options, this.closed = new AsyncEvent(), this.connected = new AsyncEvent(), this.errors = new ErrorStream4(), this._streamDataFlushedCallback = null, this._isChannelCreationInProgress = false;
3122
3241
  }
@@ -3131,7 +3250,7 @@ var RtcTransportChannel = class extends Resource {
3131
3250
  async _open() {
3132
3251
  invariant11(!this._isChannelCreationInProgress, void 0, {
3133
3252
  F: __dxlog_file13,
3134
- L: 56,
3253
+ L: 57,
3135
3254
  S: this,
3136
3255
  A: [
3137
3256
  "!this._isChannelCreationInProgress",
@@ -3155,7 +3274,7 @@ var RtcTransportChannel = class extends Resource {
3155
3274
  err
3156
3275
  }, {
3157
3276
  F: __dxlog_file13,
3158
- L: 76,
3277
+ L: 77,
3159
3278
  S: this,
3160
3279
  C: (f, a) => f(...a)
3161
3280
  });
@@ -3173,7 +3292,7 @@ var RtcTransportChannel = class extends Resource {
3173
3292
  this.closed.emit();
3174
3293
  log12("closed", void 0, {
3175
3294
  F: __dxlog_file13,
3176
- L: 92,
3295
+ L: 93,
3177
3296
  S: this,
3178
3297
  C: (f, a) => f(...a)
3179
3298
  });
@@ -3186,7 +3305,7 @@ var RtcTransportChannel = class extends Resource {
3186
3305
  topic: this._options.topic
3187
3306
  }, {
3188
3307
  F: __dxlog_file13,
3189
- L: 99,
3308
+ L: 100,
3190
3309
  S: this,
3191
3310
  C: (f, a) => f(...a)
3192
3311
  });
@@ -3195,7 +3314,7 @@ var RtcTransportChannel = class extends Resource {
3195
3314
  }
3196
3315
  log12("onopen", void 0, {
3197
3316
  F: __dxlog_file13,
3198
- L: 104,
3317
+ L: 105,
3199
3318
  S: this,
3200
3319
  C: (f, a) => f(...a)
3201
3320
  });
@@ -3213,7 +3332,7 @@ var RtcTransportChannel = class extends Resource {
3213
3332
  onclose: async () => {
3214
3333
  log12("onclose", void 0, {
3215
3334
  F: __dxlog_file13,
3216
- L: 117,
3335
+ L: 118,
3217
3336
  S: this,
3218
3337
  C: (f, a) => f(...a)
3219
3338
  });
@@ -3223,7 +3342,7 @@ var RtcTransportChannel = class extends Resource {
3223
3342
  if (!this._stream) {
3224
3343
  log12.warn("ignoring message on a closed channel", void 0, {
3225
3344
  F: __dxlog_file13,
3226
- L: 123,
3345
+ L: 124,
3227
3346
  S: this,
3228
3347
  C: (f, a) => f(...a)
3229
3348
  });
@@ -3254,7 +3373,7 @@ var RtcTransportChannel = class extends Resource {
3254
3373
  if (!this._channel) {
3255
3374
  log12.warn("writing to a channel after a connection was closed", void 0, {
3256
3375
  F: __dxlog_file13,
3257
- L: 153,
3376
+ L: 154,
3258
3377
  S: this,
3259
3378
  C: (f, a) => f(...a)
3260
3379
  });
@@ -3277,7 +3396,7 @@ var RtcTransportChannel = class extends Resource {
3277
3396
  if (this._streamDataFlushedCallback !== null) {
3278
3397
  log12.error("consumer trying to write before we are ready for more data", void 0, {
3279
3398
  F: __dxlog_file13,
3280
- L: 174,
3399
+ L: 175,
3281
3400
  S: this,
3282
3401
  C: (f, a) => f(...a)
3283
3402
  });
@@ -3293,7 +3412,7 @@ var RtcTransportChannel = class extends Resource {
3293
3412
  } catch (error) {
3294
3413
  log12.catch(error, void 0, {
3295
3414
  F: __dxlog_file13,
3296
- L: 186,
3415
+ L: 187,
3297
3416
  S: this,
3298
3417
  C: (f, a) => f(...a)
3299
3418
  });
@@ -3345,6 +3464,24 @@ function _ts_decorate6(decorators, target, key, desc) {
3345
3464
  }
3346
3465
  var __dxlog_file14 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
3347
3466
  var RtcPeerConnection = class {
3467
+ _factory;
3468
+ _options;
3469
+ // A peer who is not the initiator waits for another party to open a channel.
3470
+ _channelCreatedCallbacks;
3471
+ // Channels indexed by topic.
3472
+ _transportChannels;
3473
+ _dataChannels;
3474
+ // A peer is ready to receive ICE candidates when local and remote description were set.
3475
+ _readyForCandidates;
3476
+ _offerProcessingMutex;
3477
+ /**
3478
+ * Can't use peer.connection.initiator, because if two connections to the same peer are created in
3479
+ * different swarms, we might be the initiator of the first one, but not of the other one.
3480
+ * Use a stable peer keypair property (key ordering) to decide who's acting as the initiator of
3481
+ * transport connection establishment and data channel creation.
3482
+ */
3483
+ _initiator;
3484
+ _connection;
3348
3485
  constructor(_factory, _options) {
3349
3486
  this._factory = _factory;
3350
3487
  this._options = _options;
@@ -3380,7 +3517,7 @@ var RtcPeerConnection = class {
3380
3517
  }
3381
3518
  log13("waiting for initiator-peer to open a data channel", void 0, {
3382
3519
  F: __dxlog_file14,
3383
- L: 95,
3520
+ L: 96,
3384
3521
  S: this,
3385
3522
  C: (f, a) => f(...a)
3386
3523
  });
@@ -3411,7 +3548,7 @@ var RtcPeerConnection = class {
3411
3548
  remotePeer: this._options.remotePeerKey
3412
3549
  }), {
3413
3550
  F: __dxlog_file14,
3414
- L: 120,
3551
+ L: 121,
3415
3552
  S: this,
3416
3553
  C: (f, a) => f(...a)
3417
3554
  });
@@ -3422,7 +3559,7 @@ var RtcPeerConnection = class {
3422
3559
  onnegotiationneeded: async () => {
3423
3560
  invariant12(this._initiator, void 0, {
3424
3561
  F: __dxlog_file14,
3425
- L: 135,
3562
+ L: 136,
3426
3563
  S: this,
3427
3564
  A: [
3428
3565
  "this._initiator",
@@ -3435,7 +3572,7 @@ var RtcPeerConnection = class {
3435
3572
  }
3436
3573
  log13("onnegotiationneeded", void 0, {
3437
3574
  F: __dxlog_file14,
3438
- L: 142,
3575
+ L: 143,
3439
3576
  S: this,
3440
3577
  C: (f, a) => f(...a)
3441
3578
  });
@@ -3459,7 +3596,7 @@ var RtcPeerConnection = class {
3459
3596
  candidate: event.candidate.candidate
3460
3597
  }, {
3461
3598
  F: __dxlog_file14,
3462
- L: 161,
3599
+ L: 162,
3463
3600
  S: this,
3464
3601
  C: (f, a) => f(...a)
3465
3602
  });
@@ -3467,7 +3604,7 @@ var RtcPeerConnection = class {
3467
3604
  } else {
3468
3605
  log13("onicecandidate gathering complete", void 0, {
3469
3606
  F: __dxlog_file14,
3470
- L: 164,
3607
+ L: 165,
3471
3608
  S: this,
3472
3609
  C: (f, a) => f(...a)
3473
3610
  });
@@ -3495,7 +3632,7 @@ var RtcPeerConnection = class {
3495
3632
  state: connection.iceConnectionState
3496
3633
  }, {
3497
3634
  F: __dxlog_file14,
3498
- L: 184,
3635
+ L: 185,
3499
3636
  S: this,
3500
3637
  C: (f, a) => f(...a)
3501
3638
  });
@@ -3517,7 +3654,7 @@ var RtcPeerConnection = class {
3517
3654
  state: connection.connectionState
3518
3655
  }, {
3519
3656
  F: __dxlog_file14,
3520
- L: 201,
3657
+ L: 202,
3521
3658
  S: this,
3522
3659
  C: (f, a) => f(...a)
3523
3660
  });
@@ -3530,7 +3667,7 @@ var RtcPeerConnection = class {
3530
3667
  state: connection.signalingState
3531
3668
  }, {
3532
3669
  F: __dxlog_file14,
3533
- L: 208,
3670
+ L: 209,
3534
3671
  S: this,
3535
3672
  C: (f, a) => f(...a)
3536
3673
  });
@@ -3540,7 +3677,7 @@ var RtcPeerConnection = class {
3540
3677
  ondatachannel: (event) => {
3541
3678
  invariant12(!this._initiator, "Initiator is expected to create data channels.", {
3542
3679
  F: __dxlog_file14,
3543
- L: 214,
3680
+ L: 215,
3544
3681
  S: this,
3545
3682
  A: [
3546
3683
  "!this._initiator",
@@ -3555,7 +3692,7 @@ var RtcPeerConnection = class {
3555
3692
  label: event.channel.label
3556
3693
  }, {
3557
3694
  F: __dxlog_file14,
3558
- L: 221,
3695
+ L: 222,
3559
3696
  S: this,
3560
3697
  C: (f, a) => f(...a)
3561
3698
  });
@@ -3583,7 +3720,7 @@ var RtcPeerConnection = class {
3583
3720
  error
3584
3721
  }, {
3585
3722
  F: __dxlog_file14,
3586
- L: 246,
3723
+ L: 247,
3587
3724
  S: this,
3588
3725
  C: (f, a) => f(...a)
3589
3726
  });
@@ -3604,7 +3741,7 @@ var RtcPeerConnection = class {
3604
3741
  reason: error.message
3605
3742
  }, {
3606
3743
  F: __dxlog_file14,
3607
- L: 260,
3744
+ L: 261,
3608
3745
  S: this,
3609
3746
  C: (f, a) => f(...a)
3610
3747
  });
@@ -3612,7 +3749,7 @@ var RtcPeerConnection = class {
3612
3749
  async _lockAndCloseConnection() {
3613
3750
  invariant12(this._transportChannels.size === 0, void 0, {
3614
3751
  F: __dxlog_file14,
3615
- L: 265,
3752
+ L: 266,
3616
3753
  S: this,
3617
3754
  A: [
3618
3755
  "this._transportChannels.size === 0",
@@ -3623,7 +3760,7 @@ var RtcPeerConnection = class {
3623
3760
  this._safeCloseConnection();
3624
3761
  log13("connection closed", void 0, {
3625
3762
  F: __dxlog_file14,
3626
- L: 268,
3763
+ L: 269,
3627
3764
  S: this,
3628
3765
  C: (f, a) => f(...a)
3629
3766
  });
@@ -3636,7 +3773,7 @@ var RtcPeerConnection = class {
3636
3773
  type: signal.payload.data.type
3637
3774
  }, {
3638
3775
  F: __dxlog_file14,
3639
- L: 276,
3776
+ L: 277,
3640
3777
  S: this,
3641
3778
  C: (f, a) => f(...a)
3642
3779
  });
@@ -3703,7 +3840,7 @@ var RtcPeerConnection = class {
3703
3840
  type: data.type
3704
3841
  }, {
3705
3842
  F: __dxlog_file14,
3706
- L: 335,
3843
+ L: 336,
3707
3844
  S: this,
3708
3845
  C: (f, a) => f(...a)
3709
3846
  });
@@ -3716,7 +3853,7 @@ var RtcPeerConnection = class {
3716
3853
  candidate
3717
3854
  }, {
3718
3855
  F: __dxlog_file14,
3719
- L: 343,
3856
+ L: 344,
3720
3857
  S: this,
3721
3858
  C: (f, a) => f(...a)
3722
3859
  });
@@ -3725,7 +3862,7 @@ var RtcPeerConnection = class {
3725
3862
  } catch (err) {
3726
3863
  log13.catch(err, void 0, {
3727
3864
  F: __dxlog_file14,
3728
- L: 347,
3865
+ L: 348,
3729
3866
  S: this,
3730
3867
  C: (f, a) => f(...a)
3731
3868
  });
@@ -3735,7 +3872,7 @@ var RtcPeerConnection = class {
3735
3872
  if (connection === this._connection) {
3736
3873
  log13("ready to process ice candidates", void 0, {
3737
3874
  F: __dxlog_file14,
3738
- L: 353,
3875
+ L: 354,
3739
3876
  S: this,
3740
3877
  C: (f, a) => f(...a)
3741
3878
  });
@@ -3743,7 +3880,7 @@ var RtcPeerConnection = class {
3743
3880
  } else {
3744
3881
  log13.warn("session was negotiated after connection became inactive", void 0, {
3745
3882
  F: __dxlog_file14,
3746
- L: 356,
3883
+ L: 357,
3747
3884
  S: this,
3748
3885
  C: (f, a) => f(...a)
3749
3886
  });
@@ -3755,7 +3892,7 @@ var RtcPeerConnection = class {
3755
3892
  state: connection.connectionState
3756
3893
  }, {
3757
3894
  F: __dxlog_file14,
3758
- L: 361,
3895
+ L: 362,
3759
3896
  S: this,
3760
3897
  C: (f, a) => f(...a)
3761
3898
  });
@@ -3768,7 +3905,7 @@ var RtcPeerConnection = class {
3768
3905
  } catch (err) {
3769
3906
  log13.catch(err, void 0, {
3770
3907
  F: __dxlog_file14,
3771
- L: 373,
3908
+ L: 374,
3772
3909
  S: this,
3773
3910
  C: (f, a) => f(...a)
3774
3911
  });
@@ -3779,7 +3916,7 @@ var RtcPeerConnection = class {
3779
3916
  this._readyForCandidates.wake();
3780
3917
  void this._factory.onConnectionDestroyed().catch((err) => log13.catch(err, void 0, {
3781
3918
  F: __dxlog_file14,
3782
- L: 379,
3919
+ L: 380,
3783
3920
  S: this,
3784
3921
  C: (f, a) => f(...a)
3785
3922
  }));
@@ -3804,7 +3941,7 @@ var RtcPeerConnection = class {
3804
3941
  } catch (error) {
3805
3942
  log13.catch(error, void 0, {
3806
3943
  F: __dxlog_file14,
3807
- L: 395,
3944
+ L: 396,
3808
3945
  S: this,
3809
3946
  C: (f, a) => f(...a)
3810
3947
  });
@@ -3831,7 +3968,7 @@ var RtcPeerConnection = class {
3831
3968
  err
3832
3969
  }, {
3833
3970
  F: __dxlog_file14,
3834
- L: 416,
3971
+ L: 417,
3835
3972
  S: this,
3836
3973
  C: (f, a) => f(...a)
3837
3974
  });
@@ -3946,6 +4083,12 @@ var RPC_TIMEOUT = 1e4;
3946
4083
  var CLOSE_RPC_TIMEOUT = 3e3;
3947
4084
  var RESP_MIN_THRESHOLD = 500;
3948
4085
  var RtcTransportProxy = class extends Resource2 {
4086
+ _options;
4087
+ _proxyId;
4088
+ closed;
4089
+ connected;
4090
+ errors;
4091
+ _serviceStream;
3949
4092
  constructor(_options) {
3950
4093
  super(), this._options = _options, this._proxyId = PublicKey10.random(), this.closed = new Event8(), this.connected = new Event8(), this.errors = new ErrorStream5();
3951
4094
  }
@@ -4156,9 +4299,8 @@ var RtcTransportProxy = class extends Resource2 {
4156
4299
  }
4157
4300
  };
4158
4301
  var RtcTransportProxyFactory = class {
4159
- constructor() {
4160
- this._connections = /* @__PURE__ */ new Set();
4161
- }
4302
+ _bridgeService;
4303
+ _connections = /* @__PURE__ */ new Set();
4162
4304
  /**
4163
4305
  * Sets the current BridgeService to be used to open connections.
4164
4306
  * Calling this method will close any existing connections.
@@ -4214,6 +4356,8 @@ import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/
4214
4356
  import { ComplexMap as ComplexMap8 } from "@dxos/util";
4215
4357
  var __dxlog_file16 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
4216
4358
  var RtcTransportService = class {
4359
+ _transportFactory;
4360
+ _openTransports;
4217
4361
  constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
4218
4362
  this._transportFactory = _transportFactory;
4219
4363
  this._openTransports = new ComplexMap8(PublicKey11.hash);
@@ -4226,7 +4370,7 @@ var RtcTransportService = class {
4226
4370
  if (existingTransport) {
4227
4371
  log15.error("requesting a new transport bridge for an existing proxy", void 0, {
4228
4372
  F: __dxlog_file16,
4229
- L: 53,
4373
+ L: 54,
4230
4374
  S: this,
4231
4375
  C: (f, a) => f(...a)
4232
4376
  });
@@ -4292,7 +4436,7 @@ var RtcTransportService = class {
4292
4436
  ready();
4293
4437
  log15("stream ready", void 0, {
4294
4438
  F: __dxlog_file16,
4295
- L: 115,
4439
+ L: 116,
4296
4440
  S: this,
4297
4441
  C: (f, a) => f(...a)
4298
4442
  });
@@ -4303,7 +4447,7 @@ var RtcTransportService = class {
4303
4447
  const transport = this._openTransports.get(proxyId);
4304
4448
  invariant14(transport, void 0, {
4305
4449
  F: __dxlog_file16,
4306
- L: 123,
4450
+ L: 124,
4307
4451
  S: this,
4308
4452
  A: [
4309
4453
  "transport",
@@ -4316,7 +4460,7 @@ var RtcTransportService = class {
4316
4460
  const transport = this._openTransports.get(proxyId);
4317
4461
  invariant14(transport, void 0, {
4318
4462
  F: __dxlog_file16,
4319
- L: 130,
4463
+ L: 131,
4320
4464
  S: this,
4321
4465
  A: [
4322
4466
  "transport",
@@ -4331,7 +4475,7 @@ var RtcTransportService = class {
4331
4475
  const transport = this._openTransports.get(proxyId);
4332
4476
  invariant14(transport, void 0, {
4333
4477
  F: __dxlog_file16,
4334
- L: 137,
4478
+ L: 138,
4335
4479
  S: this,
4336
4480
  A: [
4337
4481
  "transport",
@@ -4346,7 +4490,7 @@ var RtcTransportService = class {
4346
4490
  const transport = this._openTransports.get(proxyId);
4347
4491
  invariant14(transport, void 0, {
4348
4492
  F: __dxlog_file16,
4349
- L: 144,
4493
+ L: 145,
4350
4494
  S: this,
4351
4495
  A: [
4352
4496
  "transport",
@@ -4380,7 +4524,7 @@ var RtcTransportService = class {
4380
4524
  message: error?.message
4381
4525
  }, {
4382
4526
  F: __dxlog_file16,
4383
- L: 174,
4527
+ L: 175,
4384
4528
  S: this,
4385
4529
  C: (f, a) => f(...a)
4386
4530
  });
@@ -4392,14 +4536,14 @@ var RtcTransportService = class {
4392
4536
  message: error?.message
4393
4537
  }, {
4394
4538
  F: __dxlog_file16,
4395
- L: 179,
4539
+ L: 180,
4396
4540
  S: this,
4397
4541
  C: (f, a) => f(...a)
4398
4542
  });
4399
4543
  }
4400
4544
  log15("closed", void 0, {
4401
4545
  F: __dxlog_file16,
4402
- L: 181,
4546
+ L: 182,
4403
4547
  S: this,
4404
4548
  C: (f, a) => f(...a)
4405
4549
  });
@@ -4466,4 +4610,4 @@ export {
4466
4610
  RtcTransportService,
4467
4611
  createTeleportProtocolFactory
4468
4612
  };
4469
- //# sourceMappingURL=chunk-2XXESTV3.mjs.map
4613
+ //# sourceMappingURL=chunk-JUVDHWW4.mjs.map