@dxos/network-manager 0.1.53-main.3ecc504 → 0.1.53-main.55faa2f
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.
- package/dist/lib/browser/{chunk-U73XV3EJ.mjs → chunk-SA5ALANV.mjs} +76 -70
- package/dist/lib/browser/chunk-SA5ALANV.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/node/index.cjs +74 -68
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +71 -63
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/connection-log.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
- package/package.json +18 -17
- package/src/connection-log.ts +6 -0
- package/src/network-manager.ts +5 -5
- package/src/signal/swarm-messenger.ts +7 -7
- package/src/swarm/connection.ts +9 -9
- package/src/swarm/peer.ts +6 -6
- package/src/swarm/swarm.ts +8 -8
- package/src/topology/fully-connected-topology.ts +3 -3
- package/src/topology/mmst-topology.ts +5 -5
- package/src/topology/star-topology.ts +4 -4
- package/src/transport/memory-transport.ts +3 -6
- package/src/transport/webrtc-transport-proxy.ts +4 -3
- package/src/transport/webrtc-transport-service.ts +3 -3
- package/src/transport/webrtc-transport.ts +2 -2
- package/dist/lib/browser/chunk-U73XV3EJ.mjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -59,7 +59,7 @@ var import_keys6 = require("@dxos/keys");
|
|
|
59
59
|
var import_util4 = require("@dxos/util");
|
|
60
60
|
|
|
61
61
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
62
|
-
var
|
|
62
|
+
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
63
63
|
var import_async = require("@dxos/async");
|
|
64
64
|
var import_context = require("@dxos/context");
|
|
65
65
|
var import_debug = require("@dxos/debug");
|
|
@@ -149,7 +149,7 @@ var Connection = class {
|
|
|
149
149
|
*/
|
|
150
150
|
// TODO(burdon): Make async?
|
|
151
151
|
openConnection() {
|
|
152
|
-
(0,
|
|
152
|
+
(0, import_tiny_invariant.default)(this._state === ConnectionState.INITIAL, "Invalid state.");
|
|
153
153
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
|
|
154
154
|
id: this._instanceId
|
|
155
155
|
}), {
|
|
@@ -171,7 +171,7 @@ var Connection = class {
|
|
|
171
171
|
});
|
|
172
172
|
this.close().catch((err) => this.errors.raise(err));
|
|
173
173
|
});
|
|
174
|
-
(0,
|
|
174
|
+
(0, import_tiny_invariant.default)(!this._transport);
|
|
175
175
|
this._transport = this._transportFactory.createTransport({
|
|
176
176
|
initiator: this.initiator,
|
|
177
177
|
stream: this._protocol.stream,
|
|
@@ -293,7 +293,7 @@ var Connection = class {
|
|
|
293
293
|
*/
|
|
294
294
|
async signal(msg) {
|
|
295
295
|
var _a, _b, _c;
|
|
296
|
-
(0,
|
|
296
|
+
(0, import_tiny_invariant.default)(msg.sessionId);
|
|
297
297
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
298
298
|
(0, import_log.log)("dropping signal for incorrect session id", {}, {
|
|
299
299
|
file: "connection.ts",
|
|
@@ -303,9 +303,9 @@ var Connection = class {
|
|
|
303
303
|
});
|
|
304
304
|
return;
|
|
305
305
|
}
|
|
306
|
-
(0,
|
|
307
|
-
(0,
|
|
308
|
-
(0,
|
|
306
|
+
(0, import_tiny_invariant.default)(msg.data.signal || msg.data.signalBatch);
|
|
307
|
+
(0, import_tiny_invariant.default)((_a = msg.author) == null ? void 0 : _a.equals(this.remoteId));
|
|
308
|
+
(0, import_tiny_invariant.default)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId));
|
|
309
309
|
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
310
310
|
msg.data.signal
|
|
311
311
|
];
|
|
@@ -326,7 +326,7 @@ var Connection = class {
|
|
|
326
326
|
});
|
|
327
327
|
this._incomingSignalBuffer.push(signal);
|
|
328
328
|
} else {
|
|
329
|
-
(0,
|
|
329
|
+
(0, import_tiny_invariant.default)(this._transport, "Connection not ready to accept signals.");
|
|
330
330
|
(0, import_log.log)("received signal", {
|
|
331
331
|
peerId: this.ownId,
|
|
332
332
|
remoteId: this.remoteId,
|
|
@@ -352,7 +352,7 @@ var Connection = class {
|
|
|
352
352
|
scope: this,
|
|
353
353
|
callSite: (f, a) => f(...a)
|
|
354
354
|
});
|
|
355
|
-
(0,
|
|
355
|
+
(0, import_tiny_invariant.default)(state !== this._state, "Already in this state.");
|
|
356
356
|
this._state = state;
|
|
357
357
|
this.stateChanged.emit(state);
|
|
358
358
|
}
|
|
@@ -362,7 +362,7 @@ __decorate([
|
|
|
362
362
|
], Connection.prototype, "close", null);
|
|
363
363
|
|
|
364
364
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
365
|
-
var
|
|
365
|
+
var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
|
|
366
366
|
var import_async3 = require("@dxos/async");
|
|
367
367
|
var import_context4 = require("@dxos/context");
|
|
368
368
|
var import_debug2 = require("@dxos/debug");
|
|
@@ -372,7 +372,7 @@ var import_protocols3 = require("@dxos/protocols");
|
|
|
372
372
|
var import_util2 = require("@dxos/util");
|
|
373
373
|
|
|
374
374
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
375
|
-
var
|
|
375
|
+
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
376
376
|
var import_context2 = require("@dxos/context");
|
|
377
377
|
var import_keys2 = require("@dxos/keys");
|
|
378
378
|
var import_log2 = require("@dxos/log");
|
|
@@ -439,7 +439,7 @@ var SwarmMessenger = class {
|
|
|
439
439
|
}
|
|
440
440
|
async signal(message) {
|
|
441
441
|
var _a, _b;
|
|
442
|
-
(0,
|
|
442
|
+
(0, import_tiny_invariant2.default)(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message");
|
|
443
443
|
await this._sendReliableMessage({
|
|
444
444
|
author: message.author,
|
|
445
445
|
recipient: message.recipient,
|
|
@@ -490,11 +490,11 @@ var SwarmMessenger = class {
|
|
|
490
490
|
}
|
|
491
491
|
async _resolveAnswers(message) {
|
|
492
492
|
var _a, _b, _c;
|
|
493
|
-
(0,
|
|
493
|
+
(0, import_tiny_invariant2.default)((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId");
|
|
494
494
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
495
495
|
if (offerRecord) {
|
|
496
496
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
497
|
-
(0,
|
|
497
|
+
(0, import_tiny_invariant2.default)((_c = message.data) == null ? void 0 : _c.answer, "No answer");
|
|
498
498
|
(0, import_log2.log)("resolving", {
|
|
499
499
|
answer: message.data.answer
|
|
500
500
|
}, {
|
|
@@ -507,7 +507,7 @@ var SwarmMessenger = class {
|
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
509
|
async _handleOffer({ author, recipient, message }) {
|
|
510
|
-
(0,
|
|
510
|
+
(0, import_tiny_invariant2.default)(message.data.offer, "No offer");
|
|
511
511
|
const offerMessage = {
|
|
512
512
|
author,
|
|
513
513
|
recipient,
|
|
@@ -542,8 +542,8 @@ var SwarmMessenger = class {
|
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
544
|
async _handleSignal({ author, recipient, message }) {
|
|
545
|
-
(0,
|
|
546
|
-
(0,
|
|
545
|
+
(0, import_tiny_invariant2.default)(message.messageId);
|
|
546
|
+
(0, import_tiny_invariant2.default)(message.data.signal || message.data.signalBatch, "Invalid message");
|
|
547
547
|
const signalMessage = {
|
|
548
548
|
author,
|
|
549
549
|
recipient,
|
|
@@ -558,7 +558,7 @@ var SwarmMessenger = class {
|
|
|
558
558
|
};
|
|
559
559
|
|
|
560
560
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
561
|
-
var
|
|
561
|
+
var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
|
|
562
562
|
var import_async2 = require("@dxos/async");
|
|
563
563
|
var import_context3 = require("@dxos/context");
|
|
564
564
|
var import_keys3 = require("@dxos/keys");
|
|
@@ -617,7 +617,7 @@ var Peer = class {
|
|
|
617
617
|
}
|
|
618
618
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
619
619
|
if (!this.connection) {
|
|
620
|
-
(0,
|
|
620
|
+
(0, import_tiny_invariant3.default)(message.sessionId);
|
|
621
621
|
const connection = this._createConnection(false, message.sessionId);
|
|
622
622
|
try {
|
|
623
623
|
connection.openConnection();
|
|
@@ -648,8 +648,8 @@ var Peer = class {
|
|
|
648
648
|
* Initiate a connection to the remote peer.
|
|
649
649
|
*/
|
|
650
650
|
async initiateConnection() {
|
|
651
|
-
(0,
|
|
652
|
-
(0,
|
|
651
|
+
(0, import_tiny_invariant3.default)(!this.initiating, "Initiation in progress.");
|
|
652
|
+
(0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
|
|
653
653
|
const sessionId = import_keys3.PublicKey.random();
|
|
654
654
|
(0, import_log3.log)("initiating...", {
|
|
655
655
|
id: this.id,
|
|
@@ -736,7 +736,7 @@ var Peer = class {
|
|
|
736
736
|
scope: this,
|
|
737
737
|
callSite: (f, a) => f(...a)
|
|
738
738
|
});
|
|
739
|
-
(0,
|
|
739
|
+
(0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
|
|
740
740
|
const connection = new Connection(
|
|
741
741
|
this.topic,
|
|
742
742
|
this.localPeerId,
|
|
@@ -776,7 +776,7 @@ var Peer = class {
|
|
|
776
776
|
scope: this,
|
|
777
777
|
callSite: (f, a) => f(...a)
|
|
778
778
|
});
|
|
779
|
-
(0,
|
|
779
|
+
(0, import_tiny_invariant3.default)(this.connection === connection, "Connection mismatch (race condition).");
|
|
780
780
|
if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
|
|
781
781
|
this._availableAfter = 0;
|
|
782
782
|
} else {
|
|
@@ -965,7 +965,7 @@ var Swarm = class {
|
|
|
965
965
|
return this._topic;
|
|
966
966
|
}
|
|
967
967
|
async open() {
|
|
968
|
-
(0,
|
|
968
|
+
(0, import_tiny_invariant4.default)(!this._listeningHandle);
|
|
969
969
|
this._listeningHandle = await this._messenger.listen({
|
|
970
970
|
peerId: this._ownPeerId,
|
|
971
971
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
@@ -1002,7 +1002,7 @@ var Swarm = class {
|
|
|
1002
1002
|
});
|
|
1003
1003
|
}
|
|
1004
1004
|
async setTopology(topology) {
|
|
1005
|
-
(0,
|
|
1005
|
+
(0, import_tiny_invariant4.default)(!this._ctx.disposed, "Swarm is offline");
|
|
1006
1006
|
if (topology === this._topology) {
|
|
1007
1007
|
return;
|
|
1008
1008
|
}
|
|
@@ -1090,7 +1090,7 @@ var Swarm = class {
|
|
|
1090
1090
|
accept: false
|
|
1091
1091
|
};
|
|
1092
1092
|
}
|
|
1093
|
-
(0,
|
|
1093
|
+
(0, import_tiny_invariant4.default)(message.author);
|
|
1094
1094
|
if (!((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId))) {
|
|
1095
1095
|
(0, import_log4.log)("rejecting offer with incorrect peerId", {
|
|
1096
1096
|
message
|
|
@@ -1141,9 +1141,9 @@ var Swarm = class {
|
|
|
1141
1141
|
});
|
|
1142
1142
|
return;
|
|
1143
1143
|
}
|
|
1144
|
-
(0,
|
|
1145
|
-
(0,
|
|
1146
|
-
(0,
|
|
1144
|
+
(0, import_tiny_invariant4.default)((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`);
|
|
1145
|
+
(0, import_tiny_invariant4.default)((_b = message.topic) == null ? void 0 : _b.equals(this._topic));
|
|
1146
|
+
(0, import_tiny_invariant4.default)(message.author);
|
|
1147
1147
|
const peer = this._getOrCreatePeer(message.author);
|
|
1148
1148
|
await peer.onSignal(message);
|
|
1149
1149
|
}
|
|
@@ -1195,7 +1195,7 @@ var Swarm = class {
|
|
|
1195
1195
|
return peer;
|
|
1196
1196
|
}
|
|
1197
1197
|
async _destroyPeer(peerId) {
|
|
1198
|
-
(0,
|
|
1198
|
+
(0, import_tiny_invariant4.default)(this._peers.has(peerId));
|
|
1199
1199
|
await this._peers.get(peerId).destroy();
|
|
1200
1200
|
this._peers.delete(peerId);
|
|
1201
1201
|
}
|
|
@@ -1414,6 +1414,7 @@ var ConnectionLog = class {
|
|
|
1414
1414
|
this._swarms.set(import_keys6.PublicKey.from(swarm._instanceId), info);
|
|
1415
1415
|
this.update.emit();
|
|
1416
1416
|
swarm.connectionAdded.on((connection) => {
|
|
1417
|
+
var _a, _b;
|
|
1417
1418
|
const connectionInfo = {
|
|
1418
1419
|
state: ConnectionState.INITIAL,
|
|
1419
1420
|
remotePeerId: connection.remoteId,
|
|
@@ -1432,6 +1433,10 @@ var ConnectionLog = class {
|
|
|
1432
1433
|
});
|
|
1433
1434
|
this.update.emit();
|
|
1434
1435
|
});
|
|
1436
|
+
(_b = (_a = connection.protocol) == null ? void 0 : _a.stats) == null ? void 0 : _b.on((stats) => {
|
|
1437
|
+
connectionInfo.streams = stats;
|
|
1438
|
+
this.update.emit();
|
|
1439
|
+
});
|
|
1435
1440
|
});
|
|
1436
1441
|
}
|
|
1437
1442
|
leftSwarm(swarm) {
|
|
@@ -1441,7 +1446,7 @@ var ConnectionLog = class {
|
|
|
1441
1446
|
};
|
|
1442
1447
|
|
|
1443
1448
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1444
|
-
var
|
|
1449
|
+
var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
|
|
1445
1450
|
var import_async6 = require("@dxos/async");
|
|
1446
1451
|
var import_keys7 = require("@dxos/keys");
|
|
1447
1452
|
var import_log6 = require("@dxos/log");
|
|
@@ -1530,10 +1535,10 @@ var NetworkManager = class {
|
|
|
1530
1535
|
*/
|
|
1531
1536
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1532
1537
|
var _a;
|
|
1533
|
-
(0,
|
|
1534
|
-
(0,
|
|
1535
|
-
(0,
|
|
1536
|
-
(0,
|
|
1538
|
+
(0, import_tiny_invariant5.default)(import_keys7.PublicKey.isPublicKey(topic));
|
|
1539
|
+
(0, import_tiny_invariant5.default)(import_keys7.PublicKey.isPublicKey(peerId));
|
|
1540
|
+
(0, import_tiny_invariant5.default)(topology);
|
|
1541
|
+
(0, import_tiny_invariant5.default)(typeof protocol === "function");
|
|
1537
1542
|
if (this._swarms.has(topic)) {
|
|
1538
1543
|
throw new Error(`Already connected to swarm: ${import_keys7.PublicKey.from(topic)}`);
|
|
1539
1544
|
}
|
|
@@ -1652,17 +1657,17 @@ var NetworkManager = class {
|
|
|
1652
1657
|
};
|
|
1653
1658
|
|
|
1654
1659
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1655
|
-
var
|
|
1660
|
+
var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
|
|
1656
1661
|
var FullyConnectedTopology = class {
|
|
1657
1662
|
toString() {
|
|
1658
1663
|
return "FullyConnectedTopology";
|
|
1659
1664
|
}
|
|
1660
1665
|
init(controller) {
|
|
1661
|
-
(0,
|
|
1666
|
+
(0, import_tiny_invariant6.default)(!this._controller, "Already initialized");
|
|
1662
1667
|
this._controller = controller;
|
|
1663
1668
|
}
|
|
1664
1669
|
update() {
|
|
1665
|
-
(0,
|
|
1670
|
+
(0, import_tiny_invariant6.default)(this._controller, "Not initialized");
|
|
1666
1671
|
const { candidates: discovered } = this._controller.getState();
|
|
1667
1672
|
for (const peer of discovered) {
|
|
1668
1673
|
this._controller.connect(peer);
|
|
@@ -1676,7 +1681,7 @@ var FullyConnectedTopology = class {
|
|
|
1676
1681
|
};
|
|
1677
1682
|
|
|
1678
1683
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1679
|
-
var
|
|
1684
|
+
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1680
1685
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
1681
1686
|
var import_log7 = require("@dxos/log");
|
|
1682
1687
|
var MMSTTopology = class {
|
|
@@ -1687,11 +1692,11 @@ var MMSTTopology = class {
|
|
|
1687
1692
|
this._sampleSize = sampleSize;
|
|
1688
1693
|
}
|
|
1689
1694
|
init(controller) {
|
|
1690
|
-
(0,
|
|
1695
|
+
(0, import_tiny_invariant7.default)(!this._controller, "Already initialized");
|
|
1691
1696
|
this._controller = controller;
|
|
1692
1697
|
}
|
|
1693
1698
|
update() {
|
|
1694
|
-
(0,
|
|
1699
|
+
(0, import_tiny_invariant7.default)(this._controller, "Not initialized");
|
|
1695
1700
|
const { connected, candidates } = this._controller.getState();
|
|
1696
1701
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
1697
1702
|
(0, import_log7.log)("Running the algorithm.", {}, {
|
|
@@ -1705,7 +1710,7 @@ var MMSTTopology = class {
|
|
|
1705
1710
|
}
|
|
1706
1711
|
}
|
|
1707
1712
|
async onOffer(peer) {
|
|
1708
|
-
(0,
|
|
1713
|
+
(0, import_tiny_invariant7.default)(this._controller, "Not initialized");
|
|
1709
1714
|
const { connected } = this._controller.getState();
|
|
1710
1715
|
const accept = connected.length < this._maxPeers;
|
|
1711
1716
|
(0, import_log7.log)(`Offer ${peer} accept=${accept}`, {}, {
|
|
@@ -1719,7 +1724,7 @@ var MMSTTopology = class {
|
|
|
1719
1724
|
async destroy() {
|
|
1720
1725
|
}
|
|
1721
1726
|
_runAlgorithm() {
|
|
1722
|
-
(0,
|
|
1727
|
+
(0, import_tiny_invariant7.default)(this._controller, "Not initialized");
|
|
1723
1728
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
1724
1729
|
if (connected.length > this._maxPeers) {
|
|
1725
1730
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
@@ -1753,7 +1758,7 @@ var MMSTTopology = class {
|
|
|
1753
1758
|
var sortByXorDistance = (keys, reference) => keys.sort((a, b) => import_xor_distance.default.gt((0, import_xor_distance.default)(a.asBuffer(), reference.asBuffer()), (0, import_xor_distance.default)(b.asBuffer(), reference.asBuffer())));
|
|
1754
1759
|
|
|
1755
1760
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1756
|
-
var
|
|
1761
|
+
var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
|
|
1757
1762
|
var import_log8 = require("@dxos/log");
|
|
1758
1763
|
var StarTopology = class {
|
|
1759
1764
|
// prettier-ignore
|
|
@@ -1764,11 +1769,11 @@ var StarTopology = class {
|
|
|
1764
1769
|
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
1765
1770
|
}
|
|
1766
1771
|
init(controller) {
|
|
1767
|
-
(0,
|
|
1772
|
+
(0, import_tiny_invariant8.default)(!this._controller, "Already initialized.");
|
|
1768
1773
|
this._controller = controller;
|
|
1769
1774
|
}
|
|
1770
1775
|
update() {
|
|
1771
|
-
(0,
|
|
1776
|
+
(0, import_tiny_invariant8.default)(this._controller, "Not initialized.");
|
|
1772
1777
|
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
1773
1778
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
1774
1779
|
(0, import_log8.log)("leaf peer dropping all connections apart from central peer.", {}, {
|
|
@@ -1806,7 +1811,7 @@ var StarTopology = class {
|
|
|
1806
1811
|
}
|
|
1807
1812
|
}
|
|
1808
1813
|
async onOffer(peer) {
|
|
1809
|
-
(0,
|
|
1814
|
+
(0, import_tiny_invariant8.default)(this._controller, "Not initialized.");
|
|
1810
1815
|
const { ownPeerId } = this._controller.getState();
|
|
1811
1816
|
(0, import_log8.log)("offer", {
|
|
1812
1817
|
peer,
|
|
@@ -1825,8 +1830,8 @@ var StarTopology = class {
|
|
|
1825
1830
|
};
|
|
1826
1831
|
|
|
1827
1832
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1828
|
-
var import_node_assert9 = __toESM(require("node:assert"));
|
|
1829
1833
|
var import_node_stream = require("node:stream");
|
|
1834
|
+
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
1830
1835
|
var import_async7 = require("@dxos/async");
|
|
1831
1836
|
var import_debug4 = require("@dxos/debug");
|
|
1832
1837
|
var import_keys8 = require("@dxos/keys");
|
|
@@ -1872,7 +1877,7 @@ var _MemoryTransport = class {
|
|
|
1872
1877
|
scope: this,
|
|
1873
1878
|
callSite: (f, a) => f(...a)
|
|
1874
1879
|
});
|
|
1875
|
-
(0,
|
|
1880
|
+
(0, import_tiny_invariant9.default)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
|
|
1876
1881
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1877
1882
|
if (this.options.initiator) {
|
|
1878
1883
|
setTimeout(async () => {
|
|
@@ -1906,12 +1911,12 @@ var _MemoryTransport = class {
|
|
|
1906
1911
|
this.closed.emit();
|
|
1907
1912
|
return;
|
|
1908
1913
|
}
|
|
1909
|
-
(0,
|
|
1914
|
+
(0, import_tiny_invariant9.default)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`);
|
|
1910
1915
|
this._remoteConnection._remoteConnection = this;
|
|
1911
1916
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1912
1917
|
(0, import_log9.log)("connected", {}, {
|
|
1913
1918
|
file: "memory-transport.ts",
|
|
1914
|
-
line:
|
|
1919
|
+
line: 103,
|
|
1915
1920
|
scope: this,
|
|
1916
1921
|
callSite: (f, a) => f(...a)
|
|
1917
1922
|
});
|
|
@@ -1929,7 +1934,7 @@ var _MemoryTransport = class {
|
|
|
1929
1934
|
async destroy() {
|
|
1930
1935
|
(0, import_log9.log)("closing", {}, {
|
|
1931
1936
|
file: "memory-transport.ts",
|
|
1932
|
-
line:
|
|
1937
|
+
line: 124,
|
|
1933
1938
|
scope: this,
|
|
1934
1939
|
callSite: (f, a) => f(...a)
|
|
1935
1940
|
});
|
|
@@ -1938,7 +1943,7 @@ var _MemoryTransport = class {
|
|
|
1938
1943
|
if (this._remoteConnection) {
|
|
1939
1944
|
(0, import_log9.log)("closing", {}, {
|
|
1940
1945
|
file: "memory-transport.ts",
|
|
1941
|
-
line:
|
|
1946
|
+
line: 129,
|
|
1942
1947
|
scope: this,
|
|
1943
1948
|
callSite: (f, a) => f(...a)
|
|
1944
1949
|
});
|
|
@@ -1951,7 +1956,7 @@ var _MemoryTransport = class {
|
|
|
1951
1956
|
this._remoteConnection = void 0;
|
|
1952
1957
|
(0, import_log9.log)("closed", {}, {
|
|
1953
1958
|
file: "memory-transport.ts",
|
|
1954
|
-
line:
|
|
1959
|
+
line: 147,
|
|
1955
1960
|
scope: this,
|
|
1956
1961
|
callSite: (f, a) => f(...a)
|
|
1957
1962
|
});
|
|
@@ -1959,7 +1964,7 @@ var _MemoryTransport = class {
|
|
|
1959
1964
|
this.closed.emit();
|
|
1960
1965
|
(0, import_log9.log)("closed", {}, {
|
|
1961
1966
|
file: "memory-transport.ts",
|
|
1962
|
-
line:
|
|
1967
|
+
line: 151,
|
|
1963
1968
|
scope: this,
|
|
1964
1969
|
callSite: (f, a) => f(...a)
|
|
1965
1970
|
});
|
|
@@ -1969,7 +1974,7 @@ var _MemoryTransport = class {
|
|
|
1969
1974
|
payload
|
|
1970
1975
|
}, {
|
|
1971
1976
|
file: "memory-transport.ts",
|
|
1972
|
-
line:
|
|
1977
|
+
line: 155,
|
|
1973
1978
|
scope: this,
|
|
1974
1979
|
callSite: (f, a) => f(...a)
|
|
1975
1980
|
});
|
|
@@ -1994,8 +1999,8 @@ __decorate4([
|
|
|
1994
1999
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
1995
2000
|
|
|
1996
2001
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1997
|
-
var import_node_assert10 = __toESM(require("node:assert"));
|
|
1998
2002
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
2003
|
+
var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
|
|
1999
2004
|
var import_async8 = require("@dxos/async");
|
|
2000
2005
|
var import_debug5 = require("@dxos/debug");
|
|
2001
2006
|
var import_keys9 = require("@dxos/keys");
|
|
@@ -2123,7 +2128,7 @@ var WebRTCTransport = class {
|
|
|
2123
2128
|
if (this._closed) {
|
|
2124
2129
|
return;
|
|
2125
2130
|
}
|
|
2126
|
-
(0,
|
|
2131
|
+
(0, import_tiny_invariant10.default)(signal.payload.data, "Signal message must contain signal data.");
|
|
2127
2132
|
this._peer.signal(signal.payload.data);
|
|
2128
2133
|
}
|
|
2129
2134
|
async _disconnectStreams() {
|
|
@@ -2139,8 +2144,8 @@ var createWebRTCTransportFactory = (webrtcConfig) => ({
|
|
|
2139
2144
|
});
|
|
2140
2145
|
|
|
2141
2146
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
2142
|
-
var import_node_assert11 = __toESM(require("node:assert"));
|
|
2143
2147
|
var import_node_stream2 = require("node:stream");
|
|
2148
|
+
var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
|
|
2144
2149
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
2145
2150
|
var import_keys10 = require("@dxos/keys");
|
|
2146
2151
|
var import_log11 = require("@dxos/log");
|
|
@@ -2216,11 +2221,11 @@ var WebRTCTransportService = class {
|
|
|
2216
2221
|
return rpcStream;
|
|
2217
2222
|
}
|
|
2218
2223
|
async sendSignal({ proxyId, signal }) {
|
|
2219
|
-
(0,
|
|
2224
|
+
(0, import_tiny_invariant11.default)(this.transports.has(proxyId));
|
|
2220
2225
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2221
2226
|
}
|
|
2222
2227
|
async sendData({ proxyId, payload }) {
|
|
2223
|
-
(0,
|
|
2228
|
+
(0, import_tiny_invariant11.default)(this.transports.has(proxyId));
|
|
2224
2229
|
await this.transports.get(proxyId).stream.push(payload);
|
|
2225
2230
|
}
|
|
2226
2231
|
async close({ proxyId }) {
|
|
@@ -2238,13 +2243,14 @@ var WebRTCTransportService = class {
|
|
|
2238
2243
|
};
|
|
2239
2244
|
|
|
2240
2245
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2241
|
-
var
|
|
2246
|
+
var import_tiny_invariant12 = __toESM(require("tiny-invariant"));
|
|
2242
2247
|
var import_async9 = require("@dxos/async");
|
|
2243
2248
|
var import_context5 = require("@dxos/context");
|
|
2244
2249
|
var import_debug6 = require("@dxos/debug");
|
|
2245
2250
|
var import_keys11 = require("@dxos/keys");
|
|
2246
2251
|
var import_log12 = require("@dxos/log");
|
|
2247
2252
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2253
|
+
var import_util8 = require("@dxos/util");
|
|
2248
2254
|
var WebRTCTransportProxy = class {
|
|
2249
2255
|
// prettier-ignore
|
|
2250
2256
|
constructor(_params) {
|
|
@@ -2263,7 +2269,7 @@ var WebRTCTransportProxy = class {
|
|
|
2263
2269
|
this._serviceStream.subscribe(async (event) => {
|
|
2264
2270
|
(0, import_log12.log)("WebRTCTransportProxy: event", event, {
|
|
2265
2271
|
file: "webrtc-transport-proxy.ts",
|
|
2266
|
-
line:
|
|
2272
|
+
line: 50,
|
|
2267
2273
|
scope: this,
|
|
2268
2274
|
callSite: (f, a) => f(...a)
|
|
2269
2275
|
});
|
|
@@ -2284,7 +2290,7 @@ var WebRTCTransportProxy = class {
|
|
|
2284
2290
|
} catch (err) {
|
|
2285
2291
|
import_log12.log.catch(err, {}, {
|
|
2286
2292
|
file: "webrtc-transport-proxy.ts",
|
|
2287
|
-
line:
|
|
2293
|
+
line: 67,
|
|
2288
2294
|
scope: this,
|
|
2289
2295
|
callSite: (f, a) => f(...a)
|
|
2290
2296
|
});
|
|
@@ -2296,7 +2302,7 @@ var WebRTCTransportProxy = class {
|
|
|
2296
2302
|
});
|
|
2297
2303
|
}, (error) => import_log12.log.catch(error, {}, {
|
|
2298
2304
|
file: "webrtc-transport-proxy.ts",
|
|
2299
|
-
line:
|
|
2305
|
+
line: 73,
|
|
2300
2306
|
scope: this,
|
|
2301
2307
|
callSite: (f, a) => f(...a)
|
|
2302
2308
|
}));
|
|
@@ -2317,7 +2323,7 @@ var WebRTCTransportProxy = class {
|
|
|
2317
2323
|
}
|
|
2318
2324
|
}
|
|
2319
2325
|
_handleData(dataEvent) {
|
|
2320
|
-
this._params.stream.write(
|
|
2326
|
+
this._params.stream.write((0, import_util8.arrayToBuffer)(dataEvent.payload));
|
|
2321
2327
|
}
|
|
2322
2328
|
async _handleSignal(signalEvent) {
|
|
2323
2329
|
await this._params.sendSignal(signalEvent.payload);
|
|
@@ -2342,7 +2348,7 @@ var WebRTCTransportProxy = class {
|
|
|
2342
2348
|
} catch (err) {
|
|
2343
2349
|
import_log12.log.catch(err, {}, {
|
|
2344
2350
|
file: "webrtc-transport-proxy.ts",
|
|
2345
|
-
line:
|
|
2351
|
+
line: 124,
|
|
2346
2352
|
scope: this,
|
|
2347
2353
|
callSite: (f, a) => f(...a)
|
|
2348
2354
|
});
|
|
@@ -2376,7 +2382,7 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2376
2382
|
return this;
|
|
2377
2383
|
}
|
|
2378
2384
|
createTransport(options) {
|
|
2379
|
-
(0,
|
|
2385
|
+
(0, import_tiny_invariant12.default)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections");
|
|
2380
2386
|
const transport = new WebRTCTransportProxy({
|
|
2381
2387
|
...options,
|
|
2382
2388
|
bridgeService: this._bridgeService
|