@dxos/network-manager 0.1.45 → 0.1.46-next.c3cc04c
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/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +7 -5
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +49 -47
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/testing/test-builder.ts +4 -1
- package/src/tests/basic-test-suite.ts +6 -7
- package/src/tests/webrtc-transport.test.ts +1 -1
- package/src/transport/webrtc-transport-proxy.test.ts +3 -9
|
@@ -204,7 +204,7 @@ var Connection = class {
|
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
async close() {
|
|
207
|
-
var
|
|
207
|
+
var _a2;
|
|
208
208
|
if (this._state === ConnectionState.CLOSED) {
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
@@ -228,7 +228,7 @@ var Connection = class {
|
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
230
|
try {
|
|
231
|
-
await ((
|
|
231
|
+
await ((_a2 = this._transport) == null ? void 0 : _a2.destroy());
|
|
232
232
|
} catch (err1) {
|
|
233
233
|
import_log.log.catch(err1, {}, {
|
|
234
234
|
file: "connection.ts",
|
|
@@ -248,7 +248,7 @@ var Connection = class {
|
|
|
248
248
|
this._changeState(ConnectionState.CLOSED);
|
|
249
249
|
}
|
|
250
250
|
async signal(msg) {
|
|
251
|
-
var
|
|
251
|
+
var _a2, _b;
|
|
252
252
|
(0, import_node_assert.default)(msg.sessionId);
|
|
253
253
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
254
254
|
(0, import_log.log)("dropping signal for incorrect session id", {}, {
|
|
@@ -260,7 +260,7 @@ var Connection = class {
|
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
262
262
|
(0, import_node_assert.default)(msg.data.signal);
|
|
263
|
-
(0, import_node_assert.default)((
|
|
263
|
+
(0, import_node_assert.default)((_a2 = msg.author) == null ? void 0 : _a2.equals(this.remoteId));
|
|
264
264
|
(0, import_node_assert.default)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId));
|
|
265
265
|
if (this._state === ConnectionState.INITIAL) {
|
|
266
266
|
(0, import_log.log)("buffered signal", {
|
|
@@ -334,7 +334,7 @@ var MessageRouter = class {
|
|
|
334
334
|
this._topic = topic;
|
|
335
335
|
}
|
|
336
336
|
async receiveMessage({ author, recipient, payload }) {
|
|
337
|
-
var
|
|
337
|
+
var _a2, _b, _c;
|
|
338
338
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
339
339
|
return;
|
|
340
340
|
}
|
|
@@ -352,7 +352,7 @@ var MessageRouter = class {
|
|
|
352
352
|
scope: this,
|
|
353
353
|
callSite: (f, a) => f(...a)
|
|
354
354
|
});
|
|
355
|
-
if ((
|
|
355
|
+
if ((_a2 = message.data) == null ? void 0 : _a2.offer) {
|
|
356
356
|
await this._handleOffer({
|
|
357
357
|
author,
|
|
358
358
|
recipient,
|
|
@@ -369,8 +369,8 @@ var MessageRouter = class {
|
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
async signal(message) {
|
|
372
|
-
var
|
|
373
|
-
(0, import_node_assert2.default)((
|
|
372
|
+
var _a2;
|
|
373
|
+
(0, import_node_assert2.default)((_a2 = message.data) == null ? void 0 : _a2.signal);
|
|
374
374
|
await this._sendReliableMessage({
|
|
375
375
|
author: message.author,
|
|
376
376
|
recipient: message.recipient,
|
|
@@ -395,11 +395,11 @@ var MessageRouter = class {
|
|
|
395
395
|
});
|
|
396
396
|
}
|
|
397
397
|
async _sendReliableMessage({ author, recipient, message }) {
|
|
398
|
-
var
|
|
398
|
+
var _a2;
|
|
399
399
|
const networkMessage = {
|
|
400
400
|
...message,
|
|
401
401
|
// Setting unique message_id if it not specified yet.
|
|
402
|
-
messageId: (
|
|
402
|
+
messageId: (_a2 = message.messageId) != null ? _a2 : import_keys2.PublicKey.random()
|
|
403
403
|
};
|
|
404
404
|
(0, import_log2.log)("sending", {
|
|
405
405
|
from: author,
|
|
@@ -428,8 +428,8 @@ var MessageRouter = class {
|
|
|
428
428
|
});
|
|
429
429
|
}
|
|
430
430
|
async _resolveAnswers(message) {
|
|
431
|
-
var
|
|
432
|
-
(0, import_node_assert2.default)((_b = (
|
|
431
|
+
var _a2, _b, _c;
|
|
432
|
+
(0, import_node_assert2.default)((_b = (_a2 = message.data) == null ? void 0 : _a2.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId");
|
|
433
433
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
434
434
|
if (offerRecord) {
|
|
435
435
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
@@ -650,7 +650,7 @@ var Peer = class {
|
|
|
650
650
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
651
651
|
*/
|
|
652
652
|
_createConnection(initiator, sessionId) {
|
|
653
|
-
var
|
|
653
|
+
var _a2;
|
|
654
654
|
(0, import_log3.log)("creating connection", {
|
|
655
655
|
topic: this.topic,
|
|
656
656
|
peerId: this.localPeerId,
|
|
@@ -681,7 +681,7 @@ var Peer = class {
|
|
|
681
681
|
this._transportFactory
|
|
682
682
|
);
|
|
683
683
|
this._callbacks.onInitiated(connection);
|
|
684
|
-
void ((
|
|
684
|
+
void ((_a2 = this._connectionCtx) == null ? void 0 : _a2.dispose());
|
|
685
685
|
this._connectionCtx = this._ctx.derive();
|
|
686
686
|
connection.stateChanged.on((state) => {
|
|
687
687
|
switch (state) {
|
|
@@ -778,7 +778,7 @@ var Peer = class {
|
|
|
778
778
|
await this.connection.signal(message);
|
|
779
779
|
}
|
|
780
780
|
async destroy() {
|
|
781
|
-
var
|
|
781
|
+
var _a2;
|
|
782
782
|
await this._ctx.dispose();
|
|
783
783
|
(0, import_log3.log)("Destroying peer", {
|
|
784
784
|
peerId: this.id,
|
|
@@ -789,7 +789,7 @@ var Peer = class {
|
|
|
789
789
|
scope: this,
|
|
790
790
|
callSite: (f, a) => f(...a)
|
|
791
791
|
});
|
|
792
|
-
await ((
|
|
792
|
+
await ((_a2 = this == null ? void 0 : this.connection) == null ? void 0 : _a2.close());
|
|
793
793
|
}
|
|
794
794
|
};
|
|
795
795
|
__decorate2([
|
|
@@ -938,7 +938,7 @@ var Swarm = class {
|
|
|
938
938
|
this._topology.update();
|
|
939
939
|
}
|
|
940
940
|
onSwarmEvent(swarmEvent) {
|
|
941
|
-
var
|
|
941
|
+
var _a2;
|
|
942
942
|
(0, import_log4.log)("swarm event", {
|
|
943
943
|
swarmEvent
|
|
944
944
|
}, {
|
|
@@ -974,7 +974,7 @@ var Swarm = class {
|
|
|
974
974
|
const peer1 = this._peers.get(import_keys4.PublicKey.from(swarmEvent.peerLeft.peer));
|
|
975
975
|
if (peer1) {
|
|
976
976
|
peer1.advertizing = false;
|
|
977
|
-
if (((
|
|
977
|
+
if (((_a2 = peer1.connection) == null ? void 0 : _a2.state) !== ConnectionState.CONNECTED) {
|
|
978
978
|
void this._destroyPeer(peer1.id).catch((err) => import_log4.log.catch(err, {}, {
|
|
979
979
|
file: "swarm.ts",
|
|
980
980
|
line: 179,
|
|
@@ -987,7 +987,7 @@ var Swarm = class {
|
|
|
987
987
|
this._topology.update();
|
|
988
988
|
}
|
|
989
989
|
async onOffer(message) {
|
|
990
|
-
var
|
|
990
|
+
var _a2, _b;
|
|
991
991
|
(0, import_log4.log)("offer", {
|
|
992
992
|
message
|
|
993
993
|
}, {
|
|
@@ -1008,7 +1008,7 @@ var Swarm = class {
|
|
|
1008
1008
|
};
|
|
1009
1009
|
}
|
|
1010
1010
|
(0, import_node_assert4.default)(message.author);
|
|
1011
|
-
if (!((
|
|
1011
|
+
if (!((_a2 = message.recipient) == null ? void 0 : _a2.equals(this._ownPeerId))) {
|
|
1012
1012
|
(0, import_log4.log)("rejecting offer with incorrect peerId", {
|
|
1013
1013
|
message
|
|
1014
1014
|
}, {
|
|
@@ -1040,7 +1040,7 @@ var Swarm = class {
|
|
|
1040
1040
|
return answer;
|
|
1041
1041
|
}
|
|
1042
1042
|
async onSignal(message) {
|
|
1043
|
-
var
|
|
1043
|
+
var _a2, _b;
|
|
1044
1044
|
(0, import_log4.log)("signal", {
|
|
1045
1045
|
message
|
|
1046
1046
|
}, {
|
|
@@ -1058,7 +1058,7 @@ var Swarm = class {
|
|
|
1058
1058
|
});
|
|
1059
1059
|
return;
|
|
1060
1060
|
}
|
|
1061
|
-
(0, import_node_assert4.default)((
|
|
1061
|
+
(0, import_node_assert4.default)((_a2 = message.recipient) == null ? void 0 : _a2.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`);
|
|
1062
1062
|
(0, import_node_assert4.default)((_b = message.topic) == null ? void 0 : _b.equals(this._topic));
|
|
1063
1063
|
(0, import_node_assert4.default)(message.author);
|
|
1064
1064
|
const peer = this._getOrCreatePeer(message.author);
|
|
@@ -1249,8 +1249,8 @@ var SwarmMapper = class {
|
|
|
1249
1249
|
}));
|
|
1250
1250
|
}));
|
|
1251
1251
|
this._subscriptions.add(_swarm.disconnected.on((peerId) => {
|
|
1252
|
-
var
|
|
1253
|
-
(
|
|
1252
|
+
var _a2;
|
|
1253
|
+
(_a2 = this._connectionSubscriptions.get(peerId)) == null ? void 0 : _a2();
|
|
1254
1254
|
this._connectionSubscriptions.delete(peerId);
|
|
1255
1255
|
this._update();
|
|
1256
1256
|
}));
|
|
@@ -1314,8 +1314,8 @@ var ConnectionLog = class {
|
|
|
1314
1314
|
this.update = new import_async5.Event();
|
|
1315
1315
|
}
|
|
1316
1316
|
getSwarmInfo(swarmId) {
|
|
1317
|
-
var
|
|
1318
|
-
return (
|
|
1317
|
+
var _a2;
|
|
1318
|
+
return (_a2 = this._swarms.get(swarmId)) != null ? _a2 : (0, import_debug3.raise)(new Error(`Swarm not found: ${swarmId}`));
|
|
1319
1319
|
}
|
|
1320
1320
|
get swarms() {
|
|
1321
1321
|
return Array.from(this._swarms.values());
|
|
@@ -1369,8 +1369,8 @@ var NetworkManager = class {
|
|
|
1369
1369
|
this._transportFactory = transportFactory;
|
|
1370
1370
|
this._signalManager = signalManager;
|
|
1371
1371
|
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => {
|
|
1372
|
-
var
|
|
1373
|
-
return (
|
|
1372
|
+
var _a2;
|
|
1373
|
+
return (_a2 = this._swarms.get(topic)) == null ? void 0 : _a2.onSwarmEvent(event);
|
|
1374
1374
|
});
|
|
1375
1375
|
this._messenger = new import_messaging.Messenger({
|
|
1376
1376
|
signalManager: this._signalManager
|
|
@@ -1438,7 +1438,7 @@ var NetworkManager = class {
|
|
|
1438
1438
|
* Join the swarm.
|
|
1439
1439
|
*/
|
|
1440
1440
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1441
|
-
var
|
|
1441
|
+
var _a2;
|
|
1442
1442
|
(0, import_node_assert5.default)(import_keys7.PublicKey.isPublicKey(topic));
|
|
1443
1443
|
(0, import_node_assert5.default)(import_keys7.PublicKey.isPublicKey(peerId));
|
|
1444
1444
|
(0, import_node_assert5.default)(topology);
|
|
@@ -1479,7 +1479,7 @@ var NetworkManager = class {
|
|
|
1479
1479
|
}));
|
|
1480
1480
|
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1481
1481
|
this.topicsUpdated.emit();
|
|
1482
|
-
(
|
|
1482
|
+
(_a2 = this._connectionLog) == null ? void 0 : _a2.joinedSwarm(swarm);
|
|
1483
1483
|
(0, import_log6.log)("joined", {
|
|
1484
1484
|
topic: import_keys7.PublicKey.from(topic),
|
|
1485
1485
|
count: this._swarms.size
|
|
@@ -1497,7 +1497,7 @@ var NetworkManager = class {
|
|
|
1497
1497
|
* Close the connection.
|
|
1498
1498
|
*/
|
|
1499
1499
|
async leaveSwarm(topic) {
|
|
1500
|
-
var
|
|
1500
|
+
var _a2;
|
|
1501
1501
|
if (!this._swarms.has(topic)) {
|
|
1502
1502
|
return;
|
|
1503
1503
|
}
|
|
@@ -1517,7 +1517,7 @@ var NetworkManager = class {
|
|
|
1517
1517
|
const map = this._mappers.get(topic);
|
|
1518
1518
|
map.destroy();
|
|
1519
1519
|
this._mappers.delete(topic);
|
|
1520
|
-
(
|
|
1520
|
+
(_a2 = this._connectionLog) == null ? void 0 : _a2.leftSwarm(swarm);
|
|
1521
1521
|
await swarm.destroy();
|
|
1522
1522
|
this._swarms.delete(topic);
|
|
1523
1523
|
await this.topicsUpdated.emit();
|
|
@@ -1622,7 +1622,7 @@ var MemoryTransportFactory = {
|
|
|
1622
1622
|
};
|
|
1623
1623
|
var _MemoryTransport = class {
|
|
1624
1624
|
constructor(options) {
|
|
1625
|
-
var
|
|
1625
|
+
var _a2;
|
|
1626
1626
|
this.options = options;
|
|
1627
1627
|
this.closed = new import_async7.Event();
|
|
1628
1628
|
this.connected = new import_async7.Event();
|
|
@@ -1660,7 +1660,7 @@ var _MemoryTransport = class {
|
|
|
1660
1660
|
});
|
|
1661
1661
|
} else {
|
|
1662
1662
|
this._remote.wait({
|
|
1663
|
-
timeout: (
|
|
1663
|
+
timeout: (_a2 = this.options.timeout) != null ? _a2 : 1e3
|
|
1664
1664
|
}).then((remoteId) => {
|
|
1665
1665
|
if (this._destroyed) {
|
|
1666
1666
|
return;
|
|
@@ -1778,7 +1778,7 @@ try {
|
|
|
1778
1778
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1779
1779
|
var WebRTCTransport = class {
|
|
1780
1780
|
constructor(params) {
|
|
1781
|
-
var
|
|
1781
|
+
var _a2;
|
|
1782
1782
|
this.params = params;
|
|
1783
1783
|
this._closed = false;
|
|
1784
1784
|
this.closed = new import_async8.Event();
|
|
@@ -1801,7 +1801,7 @@ var WebRTCTransport = class {
|
|
|
1801
1801
|
});
|
|
1802
1802
|
this._peer = new import_simple_peer.default({
|
|
1803
1803
|
initiator: this.params.initiator,
|
|
1804
|
-
wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : (
|
|
1804
|
+
wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : (_a2 = wrtc) != null ? _a2 : (0, import_debug5.raise)(new Error("wrtc not available")),
|
|
1805
1805
|
config: this.params.webrtcConfig
|
|
1806
1806
|
});
|
|
1807
1807
|
this._peer.on("signal", async (data) => {
|
|
@@ -1838,10 +1838,10 @@ var WebRTCTransport = class {
|
|
|
1838
1838
|
this.closed.emit();
|
|
1839
1839
|
});
|
|
1840
1840
|
this._peer.on("error", async (err) => {
|
|
1841
|
-
var
|
|
1841
|
+
var _a3;
|
|
1842
1842
|
this.errors.raise(err);
|
|
1843
1843
|
try {
|
|
1844
|
-
if (typeof ((
|
|
1844
|
+
if (typeof ((_a3 = this._peer) == null ? void 0 : _a3._pc.getStats) === "function") {
|
|
1845
1845
|
this._peer._pc.getStats().then((stats) => {
|
|
1846
1846
|
import_log10.log.warn("report after webrtc error", {
|
|
1847
1847
|
config: this.params.webrtcConfig,
|
|
@@ -1893,8 +1893,8 @@ var WebRTCTransport = class {
|
|
|
1893
1893
|
this._peer.signal(signal.payload.data);
|
|
1894
1894
|
}
|
|
1895
1895
|
async _disconnectStreams() {
|
|
1896
|
-
var
|
|
1897
|
-
(_d = (_c = (_b = (
|
|
1896
|
+
var _a2, _b, _c, _d;
|
|
1897
|
+
(_d = (_c = (_b = (_a2 = this.params.stream).unpipe) == null ? void 0 : _b.call(_a2, this._peer)) == null ? void 0 : _c.unpipe) == null ? void 0 : _d.call(_c, this.params.stream);
|
|
1898
1898
|
}
|
|
1899
1899
|
};
|
|
1900
1900
|
|
|
@@ -1984,8 +1984,8 @@ var WebRTCTransportService = class {
|
|
|
1984
1984
|
await this.transports.get(proxyId).stream.push(payload);
|
|
1985
1985
|
}
|
|
1986
1986
|
async close({ proxyId }) {
|
|
1987
|
-
var
|
|
1988
|
-
await ((
|
|
1987
|
+
var _a2, _b;
|
|
1988
|
+
await ((_a2 = this.transports.get(proxyId)) == null ? void 0 : _a2.transport.destroy());
|
|
1989
1989
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
1990
1990
|
this.transports.delete(proxyId);
|
|
1991
1991
|
(0, import_log11.log)("Closed.", {}, {
|
|
@@ -2221,9 +2221,11 @@ var TestWireProtocol = class {
|
|
|
2221
2221
|
};
|
|
2222
2222
|
|
|
2223
2223
|
// packages/core/mesh/network-manager/src/testing/test-builder.ts
|
|
2224
|
+
var _a;
|
|
2225
|
+
var port = (_a = process.env.SIGNAL_PORT) != null ? _a : 4e3;
|
|
2224
2226
|
var TEST_SIGNAL_HOSTS = [
|
|
2225
2227
|
{
|
|
2226
|
-
server:
|
|
2228
|
+
server: `ws://localhost:${port}/.well-known/dx/signal`
|
|
2227
2229
|
}
|
|
2228
2230
|
];
|
|
2229
2231
|
var TestBuilder = class {
|
|
@@ -2291,16 +2293,16 @@ var TestPeer = class {
|
|
|
2291
2293
|
});
|
|
2292
2294
|
}
|
|
2293
2295
|
async open() {
|
|
2294
|
-
var
|
|
2296
|
+
var _a2, _b;
|
|
2295
2297
|
await this._networkManager.open();
|
|
2296
|
-
await ((
|
|
2298
|
+
await ((_a2 = this._proxy) == null ? void 0 : _a2.open());
|
|
2297
2299
|
await ((_b = this._service) == null ? void 0 : _b.open());
|
|
2298
2300
|
}
|
|
2299
2301
|
async close() {
|
|
2300
|
-
var
|
|
2302
|
+
var _a2, _b;
|
|
2301
2303
|
await Promise.all(Array.from(this._swarms.values()).map((swarm) => swarm.leave()));
|
|
2302
2304
|
this._swarms.clear();
|
|
2303
|
-
await ((
|
|
2305
|
+
await ((_a2 = this._proxy) == null ? void 0 : _a2.close());
|
|
2304
2306
|
await ((_b = this._service) == null ? void 0 : _b.close());
|
|
2305
2307
|
await this._networkManager.close();
|
|
2306
2308
|
}
|