@dxos/network-manager 0.1.56-main.c19b7cd → 0.1.56-main.c277f68
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-FC6CWDES.mjs → chunk-WQ3YXGWP.mjs} +132 -141
- package/dist/lib/browser/chunk-WQ3YXGWP.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +23 -16
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +130 -139
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +152 -154
- 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/signal/swarm-messenger.d.ts +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +2 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +4 -3
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts +13 -2
- package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport.d.ts +3 -3
- package/dist/types/src/transport/webrtc-transport.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/connection-log.ts +2 -0
- package/src/signal/swarm-messenger.ts +2 -2
- package/src/swarm/connection-limiter.ts +1 -1
- package/src/swarm/connection.ts +12 -3
- package/src/swarm/peer.ts +8 -6
- package/src/swarm/swarm.ts +5 -5
- package/src/testing/test-builder.ts +9 -5
- package/src/testing/test-wire-protocol.ts +22 -2
- package/src/tests/memory-transport.test.ts +1 -1
- package/src/transport/webrtc-transport-proxy.ts +4 -4
- package/src/transport/webrtc-transport.ts +20 -6
- package/dist/lib/browser/chunk-FC6CWDES.mjs.map +0 -7
|
@@ -4,7 +4,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
4
4
|
}) : x)(function(x) {
|
|
5
5
|
if (typeof require !== "undefined")
|
|
6
6
|
return require.apply(this, arguments);
|
|
7
|
-
throw
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
@@ -92,7 +92,7 @@ var Connection = class {
|
|
|
92
92
|
initiator: this.initiator
|
|
93
93
|
}, {
|
|
94
94
|
F: __dxlog_file,
|
|
95
|
-
L:
|
|
95
|
+
L: 96,
|
|
96
96
|
S: this,
|
|
97
97
|
C: (f, a) => f(...a)
|
|
98
98
|
});
|
|
@@ -112,7 +112,7 @@ var Connection = class {
|
|
|
112
112
|
async openConnection() {
|
|
113
113
|
invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
114
114
|
F: __dxlog_file,
|
|
115
|
-
L:
|
|
115
|
+
L: 121,
|
|
116
116
|
S: this,
|
|
117
117
|
A: [
|
|
118
118
|
"this._state === ConnectionState.INITIAL",
|
|
@@ -123,7 +123,7 @@ var Connection = class {
|
|
|
123
123
|
id: this._instanceId
|
|
124
124
|
}), {
|
|
125
125
|
F: __dxlog_file,
|
|
126
|
-
L:
|
|
126
|
+
L: 122,
|
|
127
127
|
S: this,
|
|
128
128
|
C: (f, a) => f(...a)
|
|
129
129
|
});
|
|
@@ -135,7 +135,7 @@ var Connection = class {
|
|
|
135
135
|
initiator: this.initiator
|
|
136
136
|
}, {
|
|
137
137
|
F: __dxlog_file,
|
|
138
|
-
L:
|
|
138
|
+
L: 123,
|
|
139
139
|
S: this,
|
|
140
140
|
C: (f, a) => f(...a)
|
|
141
141
|
});
|
|
@@ -146,7 +146,7 @@ var Connection = class {
|
|
|
146
146
|
this._protocol.stream.on("close", () => {
|
|
147
147
|
log("protocol stream closed", void 0, {
|
|
148
148
|
F: __dxlog_file,
|
|
149
|
-
L:
|
|
149
|
+
L: 140,
|
|
150
150
|
S: this,
|
|
151
151
|
C: (f, a) => f(...a)
|
|
152
152
|
});
|
|
@@ -154,7 +154,7 @@ var Connection = class {
|
|
|
154
154
|
});
|
|
155
155
|
invariant(!this._transport, void 0, {
|
|
156
156
|
F: __dxlog_file,
|
|
157
|
-
L:
|
|
157
|
+
L: 144,
|
|
158
158
|
S: this,
|
|
159
159
|
A: [
|
|
160
160
|
"!this._transport",
|
|
@@ -174,6 +174,9 @@ var Connection = class {
|
|
|
174
174
|
this.close().catch((err) => this.errors.raise(err));
|
|
175
175
|
});
|
|
176
176
|
this._transport.errors.handle((err) => {
|
|
177
|
+
if (!this.closeReason) {
|
|
178
|
+
this.closeReason = err?.message;
|
|
179
|
+
}
|
|
177
180
|
if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
|
|
178
181
|
this.errors.raise(err);
|
|
179
182
|
}
|
|
@@ -186,13 +189,15 @@ var Connection = class {
|
|
|
186
189
|
id: this._instanceId
|
|
187
190
|
}), {
|
|
188
191
|
F: __dxlog_file,
|
|
189
|
-
L:
|
|
192
|
+
L: 176,
|
|
190
193
|
S: this,
|
|
191
194
|
C: (f, a) => f(...a)
|
|
192
195
|
});
|
|
193
196
|
}
|
|
194
|
-
async close() {
|
|
195
|
-
|
|
197
|
+
async close(err) {
|
|
198
|
+
if (!this.closeReason) {
|
|
199
|
+
this.closeReason = err?.message;
|
|
200
|
+
}
|
|
196
201
|
if (this._state === ConnectionState.CLOSED) {
|
|
197
202
|
return;
|
|
198
203
|
}
|
|
@@ -202,26 +207,26 @@ var Connection = class {
|
|
|
202
207
|
peerId: this.ownId
|
|
203
208
|
}, {
|
|
204
209
|
F: __dxlog_file,
|
|
205
|
-
L:
|
|
210
|
+
L: 191,
|
|
206
211
|
S: this,
|
|
207
212
|
C: (f, a) => f(...a)
|
|
208
213
|
});
|
|
209
214
|
try {
|
|
210
215
|
await this._protocol.destroy();
|
|
211
|
-
} catch (
|
|
212
|
-
log.catch(
|
|
216
|
+
} catch (err2) {
|
|
217
|
+
log.catch(err2, void 0, {
|
|
213
218
|
F: __dxlog_file,
|
|
214
|
-
L:
|
|
219
|
+
L: 197,
|
|
215
220
|
S: this,
|
|
216
221
|
C: (f, a) => f(...a)
|
|
217
222
|
});
|
|
218
223
|
}
|
|
219
224
|
try {
|
|
220
|
-
await
|
|
221
|
-
} catch (
|
|
222
|
-
log.catch(
|
|
225
|
+
await this._transport?.destroy();
|
|
226
|
+
} catch (err2) {
|
|
227
|
+
log.catch(err2, void 0, {
|
|
223
228
|
F: __dxlog_file,
|
|
224
|
-
L:
|
|
229
|
+
L: 204,
|
|
225
230
|
S: this,
|
|
226
231
|
C: (f, a) => f(...a)
|
|
227
232
|
});
|
|
@@ -230,7 +235,7 @@ var Connection = class {
|
|
|
230
235
|
peerId: this.ownId
|
|
231
236
|
}, {
|
|
232
237
|
F: __dxlog_file,
|
|
233
|
-
L:
|
|
238
|
+
L: 207,
|
|
234
239
|
S: this,
|
|
235
240
|
C: (f, a) => f(...a)
|
|
236
241
|
});
|
|
@@ -245,8 +250,10 @@ var Connection = class {
|
|
|
245
250
|
return;
|
|
246
251
|
}
|
|
247
252
|
try {
|
|
248
|
-
|
|
249
|
-
|
|
253
|
+
if (true) {
|
|
254
|
+
await cancelWithContext(this._ctx, sleep(this._signallingDelay));
|
|
255
|
+
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
256
|
+
}
|
|
250
257
|
const signals = [
|
|
251
258
|
...this._outgoingSignalBuffer
|
|
252
259
|
];
|
|
@@ -270,7 +277,7 @@ var Connection = class {
|
|
|
270
277
|
err
|
|
271
278
|
}, {
|
|
272
279
|
F: __dxlog_file,
|
|
273
|
-
L:
|
|
280
|
+
L: 243,
|
|
274
281
|
S: this,
|
|
275
282
|
C: (f, a) => f(...a)
|
|
276
283
|
});
|
|
@@ -281,10 +288,9 @@ var Connection = class {
|
|
|
281
288
|
* Receive a signal from the remote peer.
|
|
282
289
|
*/
|
|
283
290
|
async signal(msg) {
|
|
284
|
-
var _a, _b, _c;
|
|
285
291
|
invariant(msg.sessionId, void 0, {
|
|
286
292
|
F: __dxlog_file,
|
|
287
|
-
L:
|
|
293
|
+
L: 252,
|
|
288
294
|
S: this,
|
|
289
295
|
A: [
|
|
290
296
|
"msg.sessionId",
|
|
@@ -294,7 +300,7 @@ var Connection = class {
|
|
|
294
300
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
295
301
|
log("dropping signal for incorrect session id", void 0, {
|
|
296
302
|
F: __dxlog_file,
|
|
297
|
-
L:
|
|
303
|
+
L: 254,
|
|
298
304
|
S: this,
|
|
299
305
|
C: (f, a) => f(...a)
|
|
300
306
|
});
|
|
@@ -302,32 +308,32 @@ var Connection = class {
|
|
|
302
308
|
}
|
|
303
309
|
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
304
310
|
F: __dxlog_file,
|
|
305
|
-
L:
|
|
311
|
+
L: 257,
|
|
306
312
|
S: this,
|
|
307
313
|
A: [
|
|
308
314
|
"msg.data.signal || msg.data.signalBatch",
|
|
309
315
|
""
|
|
310
316
|
]
|
|
311
317
|
});
|
|
312
|
-
invariant(
|
|
318
|
+
invariant(msg.author?.equals(this.remoteId), void 0, {
|
|
313
319
|
F: __dxlog_file,
|
|
314
|
-
L:
|
|
320
|
+
L: 258,
|
|
315
321
|
S: this,
|
|
316
322
|
A: [
|
|
317
323
|
"msg.author?.equals(this.remoteId)",
|
|
318
324
|
""
|
|
319
325
|
]
|
|
320
326
|
});
|
|
321
|
-
invariant(
|
|
327
|
+
invariant(msg.recipient?.equals(this.ownId), void 0, {
|
|
322
328
|
F: __dxlog_file,
|
|
323
|
-
L:
|
|
329
|
+
L: 259,
|
|
324
330
|
S: this,
|
|
325
331
|
A: [
|
|
326
332
|
"msg.recipient?.equals(this.ownId)",
|
|
327
333
|
""
|
|
328
334
|
]
|
|
329
335
|
});
|
|
330
|
-
const signals = msg.data.signalBatch ?
|
|
336
|
+
const signals = msg.data.signalBatch ? msg.data.signalBatch.signals ?? [] : [
|
|
331
337
|
msg.data.signal
|
|
332
338
|
];
|
|
333
339
|
for (const signal of signals) {
|
|
@@ -341,7 +347,7 @@ var Connection = class {
|
|
|
341
347
|
msg: msg.data
|
|
342
348
|
}, {
|
|
343
349
|
F: __dxlog_file,
|
|
344
|
-
L:
|
|
350
|
+
L: 268,
|
|
345
351
|
S: this,
|
|
346
352
|
C: (f, a) => f(...a)
|
|
347
353
|
});
|
|
@@ -349,7 +355,7 @@ var Connection = class {
|
|
|
349
355
|
} else {
|
|
350
356
|
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
351
357
|
F: __dxlog_file,
|
|
352
|
-
L:
|
|
358
|
+
L: 271,
|
|
353
359
|
S: this,
|
|
354
360
|
A: [
|
|
355
361
|
"this._transport",
|
|
@@ -362,7 +368,7 @@ var Connection = class {
|
|
|
362
368
|
msg: msg.data
|
|
363
369
|
}, {
|
|
364
370
|
F: __dxlog_file,
|
|
365
|
-
L:
|
|
371
|
+
L: 272,
|
|
366
372
|
S: this,
|
|
367
373
|
C: (f, a) => f(...a)
|
|
368
374
|
});
|
|
@@ -377,13 +383,13 @@ var Connection = class {
|
|
|
377
383
|
peerId: this.ownId
|
|
378
384
|
}, {
|
|
379
385
|
F: __dxlog_file,
|
|
380
|
-
L:
|
|
386
|
+
L: 279,
|
|
381
387
|
S: this,
|
|
382
388
|
C: (f, a) => f(...a)
|
|
383
389
|
});
|
|
384
390
|
invariant(state !== this._state, "Already in this state.", {
|
|
385
391
|
F: __dxlog_file,
|
|
386
|
-
L:
|
|
392
|
+
L: 280,
|
|
387
393
|
S: this,
|
|
388
394
|
A: [
|
|
389
395
|
"state !== this._state",
|
|
@@ -417,7 +423,6 @@ var SwarmMessenger = class {
|
|
|
417
423
|
this._topic = topic;
|
|
418
424
|
}
|
|
419
425
|
async receiveMessage({ author, recipient, payload }) {
|
|
420
|
-
var _a, _b, _c, _d;
|
|
421
426
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
422
427
|
return;
|
|
423
428
|
}
|
|
@@ -435,21 +440,21 @@ var SwarmMessenger = class {
|
|
|
435
440
|
S: this,
|
|
436
441
|
C: (f, a) => f(...a)
|
|
437
442
|
});
|
|
438
|
-
if (
|
|
443
|
+
if (message.data?.offer) {
|
|
439
444
|
await this._handleOffer({
|
|
440
445
|
author,
|
|
441
446
|
recipient,
|
|
442
447
|
message
|
|
443
448
|
});
|
|
444
|
-
} else if (
|
|
449
|
+
} else if (message.data?.answer) {
|
|
445
450
|
await this._resolveAnswers(message);
|
|
446
|
-
} else if (
|
|
451
|
+
} else if (message.data?.signal) {
|
|
447
452
|
await this._handleSignal({
|
|
448
453
|
author,
|
|
449
454
|
recipient,
|
|
450
455
|
message
|
|
451
456
|
});
|
|
452
|
-
} else if (
|
|
457
|
+
} else if (message.data?.signalBatch) {
|
|
453
458
|
await this._handleSignal({
|
|
454
459
|
author,
|
|
455
460
|
recipient,
|
|
@@ -467,8 +472,7 @@ var SwarmMessenger = class {
|
|
|
467
472
|
}
|
|
468
473
|
}
|
|
469
474
|
async signal(message) {
|
|
470
|
-
|
|
471
|
-
invariant2(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message", {
|
|
475
|
+
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
472
476
|
F: __dxlog_file2,
|
|
473
477
|
L: 85,
|
|
474
478
|
S: this,
|
|
@@ -500,11 +504,10 @@ var SwarmMessenger = class {
|
|
|
500
504
|
});
|
|
501
505
|
}
|
|
502
506
|
async _sendReliableMessage({ author, recipient, message }) {
|
|
503
|
-
var _a;
|
|
504
507
|
const networkMessage = {
|
|
505
508
|
...message,
|
|
506
509
|
// Setting unique message_id if it not specified yet.
|
|
507
|
-
messageId:
|
|
510
|
+
messageId: message.messageId ?? PublicKey2.random()
|
|
508
511
|
};
|
|
509
512
|
log2("sending", {
|
|
510
513
|
from: author,
|
|
@@ -526,8 +529,7 @@ var SwarmMessenger = class {
|
|
|
526
529
|
});
|
|
527
530
|
}
|
|
528
531
|
async _resolveAnswers(message) {
|
|
529
|
-
|
|
530
|
-
invariant2((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId", {
|
|
532
|
+
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
531
533
|
F: __dxlog_file2,
|
|
532
534
|
L: 135,
|
|
533
535
|
S: this,
|
|
@@ -539,7 +541,7 @@ var SwarmMessenger = class {
|
|
|
539
541
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
540
542
|
if (offerRecord) {
|
|
541
543
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
542
|
-
invariant2(
|
|
544
|
+
invariant2(message.data?.answer, "No answer", {
|
|
543
545
|
F: __dxlog_file2,
|
|
544
546
|
L: 139,
|
|
545
547
|
S: this,
|
|
@@ -664,6 +666,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
664
666
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
665
667
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
666
668
|
var Peer = class {
|
|
669
|
+
// TODO(burdon): Convert to map?
|
|
667
670
|
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
668
671
|
this.id = id;
|
|
669
672
|
this.topic = topic;
|
|
@@ -683,7 +686,6 @@ var Peer = class {
|
|
|
683
686
|
* Respond to remote offer.
|
|
684
687
|
*/
|
|
685
688
|
async onOffer(message) {
|
|
686
|
-
var _a;
|
|
687
689
|
const remoteId = message.author;
|
|
688
690
|
if (this.connection || this.initiating) {
|
|
689
691
|
if (remoteId.toHex() < this.localPeerId.toHex()) {
|
|
@@ -691,15 +693,15 @@ var Peer = class {
|
|
|
691
693
|
localPeerId: this.id,
|
|
692
694
|
topic: this.topic,
|
|
693
695
|
remotePeerId: this.localPeerId,
|
|
694
|
-
sessionId:
|
|
696
|
+
sessionId: this.connection?.sessionId
|
|
695
697
|
}, {
|
|
696
698
|
F: __dxlog_file3,
|
|
697
|
-
L:
|
|
699
|
+
L: 108,
|
|
698
700
|
S: this,
|
|
699
701
|
C: (f, a) => f(...a)
|
|
700
702
|
});
|
|
701
703
|
if (this.connection) {
|
|
702
|
-
await this.closeConnection();
|
|
704
|
+
await this.closeConnection(new Error("Connection displaced by remote initiator."));
|
|
703
705
|
}
|
|
704
706
|
} else {
|
|
705
707
|
return {
|
|
@@ -711,7 +713,7 @@ var Peer = class {
|
|
|
711
713
|
if (!this.connection) {
|
|
712
714
|
invariant3(message.sessionId, void 0, {
|
|
713
715
|
F: __dxlog_file3,
|
|
714
|
-
L:
|
|
716
|
+
L: 128,
|
|
715
717
|
S: this,
|
|
716
718
|
A: [
|
|
717
719
|
"message.sessionId",
|
|
@@ -731,12 +733,12 @@ var Peer = class {
|
|
|
731
733
|
err
|
|
732
734
|
}, {
|
|
733
735
|
F: __dxlog_file3,
|
|
734
|
-
L:
|
|
736
|
+
L: 136,
|
|
735
737
|
S: this,
|
|
736
738
|
C: (f, a) => f(...a)
|
|
737
739
|
});
|
|
738
740
|
}
|
|
739
|
-
await this.closeConnection();
|
|
741
|
+
await this.closeConnection(err);
|
|
740
742
|
}
|
|
741
743
|
return {
|
|
742
744
|
accept: true
|
|
@@ -753,7 +755,7 @@ var Peer = class {
|
|
|
753
755
|
async initiateConnection() {
|
|
754
756
|
invariant3(!this.initiating, "Initiation in progress.", {
|
|
755
757
|
F: __dxlog_file3,
|
|
756
|
-
L:
|
|
758
|
+
L: 153,
|
|
757
759
|
S: this,
|
|
758
760
|
A: [
|
|
759
761
|
"!this.initiating",
|
|
@@ -762,7 +764,7 @@ var Peer = class {
|
|
|
762
764
|
});
|
|
763
765
|
invariant3(!this.connection, "Already connected.", {
|
|
764
766
|
F: __dxlog_file3,
|
|
765
|
-
L:
|
|
767
|
+
L: 154,
|
|
766
768
|
S: this,
|
|
767
769
|
A: [
|
|
768
770
|
"!this.connection",
|
|
@@ -777,7 +779,7 @@ var Peer = class {
|
|
|
777
779
|
sessionId
|
|
778
780
|
}, {
|
|
779
781
|
F: __dxlog_file3,
|
|
780
|
-
L:
|
|
782
|
+
L: 156,
|
|
781
783
|
S: this,
|
|
782
784
|
C: (f, a) => f(...a)
|
|
783
785
|
});
|
|
@@ -801,14 +803,14 @@ var Peer = class {
|
|
|
801
803
|
remoteId: this.id
|
|
802
804
|
}, {
|
|
803
805
|
F: __dxlog_file3,
|
|
804
|
-
L:
|
|
806
|
+
L: 171,
|
|
805
807
|
S: this,
|
|
806
808
|
C: (f, a) => f(...a)
|
|
807
809
|
});
|
|
808
810
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
809
811
|
log3("ignoring response", void 0, {
|
|
810
812
|
F: __dxlog_file3,
|
|
811
|
-
L:
|
|
813
|
+
L: 173,
|
|
812
814
|
S: this,
|
|
813
815
|
C: (f, a) => f(...a)
|
|
814
816
|
});
|
|
@@ -828,11 +830,11 @@ var Peer = class {
|
|
|
828
830
|
remoteId: this.id
|
|
829
831
|
}, {
|
|
830
832
|
F: __dxlog_file3,
|
|
831
|
-
L:
|
|
833
|
+
L: 184,
|
|
832
834
|
S: this,
|
|
833
835
|
C: (f, a) => f(...a)
|
|
834
836
|
});
|
|
835
|
-
await this.closeConnection();
|
|
837
|
+
await this.closeConnection(err);
|
|
836
838
|
throw err;
|
|
837
839
|
} finally {
|
|
838
840
|
this.initiating = false;
|
|
@@ -843,7 +845,6 @@ var Peer = class {
|
|
|
843
845
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
844
846
|
*/
|
|
845
847
|
_createConnection(initiator, sessionId) {
|
|
846
|
-
var _a;
|
|
847
848
|
log3("creating connection", {
|
|
848
849
|
topic: this.topic,
|
|
849
850
|
peerId: this.localPeerId,
|
|
@@ -852,13 +853,13 @@ var Peer = class {
|
|
|
852
853
|
sessionId
|
|
853
854
|
}, {
|
|
854
855
|
F: __dxlog_file3,
|
|
855
|
-
L:
|
|
856
|
+
L: 198,
|
|
856
857
|
S: this,
|
|
857
858
|
C: (f, a) => f(...a)
|
|
858
859
|
});
|
|
859
860
|
invariant3(!this.connection, "Already connected.", {
|
|
860
861
|
F: __dxlog_file3,
|
|
861
|
-
L:
|
|
862
|
+
L: 205,
|
|
862
863
|
S: this,
|
|
863
864
|
A: [
|
|
864
865
|
"!this.connection",
|
|
@@ -882,7 +883,7 @@ var Peer = class {
|
|
|
882
883
|
this._transportFactory
|
|
883
884
|
);
|
|
884
885
|
this._callbacks.onInitiated(connection);
|
|
885
|
-
void
|
|
886
|
+
void this._connectionCtx?.dispose();
|
|
886
887
|
this._connectionCtx = this._ctx.derive();
|
|
887
888
|
connection.stateChanged.on((state) => {
|
|
888
889
|
switch (state) {
|
|
@@ -899,7 +900,7 @@ var Peer = class {
|
|
|
899
900
|
initiator
|
|
900
901
|
}, {
|
|
901
902
|
F: __dxlog_file3,
|
|
902
|
-
L:
|
|
903
|
+
L: 231,
|
|
903
904
|
S: this,
|
|
904
905
|
C: (f, a) => f(...a)
|
|
905
906
|
});
|
|
@@ -913,13 +914,13 @@ var Peer = class {
|
|
|
913
914
|
initiator
|
|
914
915
|
}, {
|
|
915
916
|
F: __dxlog_file3,
|
|
916
|
-
L:
|
|
917
|
+
L: 242,
|
|
917
918
|
S: this,
|
|
918
919
|
C: (f, a) => f(...a)
|
|
919
920
|
});
|
|
920
921
|
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
921
922
|
F: __dxlog_file3,
|
|
922
|
-
L:
|
|
923
|
+
L: 243,
|
|
923
924
|
S: this,
|
|
924
925
|
A: [
|
|
925
926
|
"this.connection === connection",
|
|
@@ -934,7 +935,7 @@ var Peer = class {
|
|
|
934
935
|
initiator
|
|
935
936
|
}, {
|
|
936
937
|
F: __dxlog_file3,
|
|
937
|
-
L:
|
|
938
|
+
L: 245,
|
|
938
939
|
S: this,
|
|
939
940
|
C: (f, a) => f(...a)
|
|
940
941
|
});
|
|
@@ -964,7 +965,7 @@ var Peer = class {
|
|
|
964
965
|
err
|
|
965
966
|
}, {
|
|
966
967
|
F: __dxlog_file3,
|
|
967
|
-
L:
|
|
968
|
+
L: 279,
|
|
968
969
|
S: this,
|
|
969
970
|
C: (f, a) => f(...a)
|
|
970
971
|
});
|
|
@@ -977,16 +978,16 @@ var Peer = class {
|
|
|
977
978
|
err
|
|
978
979
|
}, {
|
|
979
980
|
F: __dxlog_file3,
|
|
980
|
-
L:
|
|
981
|
+
L: 280,
|
|
981
982
|
S: this,
|
|
982
983
|
C: (f, a) => f(...a)
|
|
983
984
|
});
|
|
984
|
-
void this.closeConnection();
|
|
985
|
+
void this.closeConnection(err);
|
|
985
986
|
});
|
|
986
987
|
this.connection = connection;
|
|
987
988
|
return connection;
|
|
988
989
|
}
|
|
989
|
-
async closeConnection() {
|
|
990
|
+
async closeConnection(err) {
|
|
990
991
|
if (!this.connection) {
|
|
991
992
|
return;
|
|
992
993
|
}
|
|
@@ -996,17 +997,17 @@ var Peer = class {
|
|
|
996
997
|
sessionId: connection.sessionId
|
|
997
998
|
}, {
|
|
998
999
|
F: __dxlog_file3,
|
|
999
|
-
L:
|
|
1000
|
+
L: 303,
|
|
1000
1001
|
S: this,
|
|
1001
1002
|
C: (f, a) => f(...a)
|
|
1002
1003
|
});
|
|
1003
|
-
await connection.close();
|
|
1004
|
+
await connection.close(err);
|
|
1004
1005
|
log3("closed", {
|
|
1005
1006
|
peerId: this.id,
|
|
1006
1007
|
sessionId: connection.sessionId
|
|
1007
1008
|
}, {
|
|
1008
1009
|
F: __dxlog_file3,
|
|
1009
|
-
L:
|
|
1010
|
+
L: 309,
|
|
1010
1011
|
S: this,
|
|
1011
1012
|
C: (f, a) => f(...a)
|
|
1012
1013
|
});
|
|
@@ -1017,7 +1018,7 @@ var Peer = class {
|
|
|
1017
1018
|
message
|
|
1018
1019
|
}, {
|
|
1019
1020
|
F: __dxlog_file3,
|
|
1020
|
-
L:
|
|
1021
|
+
L: 314,
|
|
1021
1022
|
S: this,
|
|
1022
1023
|
C: (f, a) => f(...a)
|
|
1023
1024
|
});
|
|
@@ -1026,18 +1027,17 @@ var Peer = class {
|
|
|
1026
1027
|
await this.connection.signal(message);
|
|
1027
1028
|
}
|
|
1028
1029
|
async destroy() {
|
|
1029
|
-
var _a;
|
|
1030
1030
|
await this._ctx.dispose();
|
|
1031
1031
|
log3("Destroying peer", {
|
|
1032
1032
|
peerId: this.id,
|
|
1033
1033
|
topic: this.topic
|
|
1034
1034
|
}, {
|
|
1035
1035
|
F: __dxlog_file3,
|
|
1036
|
-
L:
|
|
1036
|
+
L: 324,
|
|
1037
1037
|
S: this,
|
|
1038
1038
|
C: (f, a) => f(...a)
|
|
1039
1039
|
});
|
|
1040
|
-
await
|
|
1040
|
+
await this?.connection?.close();
|
|
1041
1041
|
}
|
|
1042
1042
|
};
|
|
1043
1043
|
_ts_decorate2([
|
|
@@ -1082,9 +1082,9 @@ var Swarm = class {
|
|
|
1082
1082
|
this._transportFactory = _transportFactory;
|
|
1083
1083
|
this._label = _label;
|
|
1084
1084
|
this._connectionLimiter = _connectionLimiter;
|
|
1085
|
-
this._peers = new ComplexMap2(PublicKey4.hash);
|
|
1086
1085
|
this._ctx = new Context4();
|
|
1087
1086
|
this._listeningHandle = void 0;
|
|
1087
|
+
this._peers = new ComplexMap2(PublicKey4.hash);
|
|
1088
1088
|
this._instanceId = PublicKey4.random().toHex();
|
|
1089
1089
|
this.connectionAdded = new Event2();
|
|
1090
1090
|
this.disconnected = new Event2();
|
|
@@ -1167,14 +1167,13 @@ var Swarm = class {
|
|
|
1167
1167
|
});
|
|
1168
1168
|
}
|
|
1169
1169
|
async destroy() {
|
|
1170
|
-
var _a;
|
|
1171
1170
|
log4("destroying...", void 0, {
|
|
1172
1171
|
F: __dxlog_file4,
|
|
1173
1172
|
L: 140,
|
|
1174
1173
|
S: this,
|
|
1175
1174
|
C: (f, a) => f(...a)
|
|
1176
1175
|
});
|
|
1177
|
-
await
|
|
1176
|
+
await this._listeningHandle?.unsubscribe();
|
|
1178
1177
|
this._listeningHandle = void 0;
|
|
1179
1178
|
await this._ctx.dispose();
|
|
1180
1179
|
await this._topology.destroy();
|
|
@@ -1214,7 +1213,6 @@ var Swarm = class {
|
|
|
1214
1213
|
this._topology.update();
|
|
1215
1214
|
}
|
|
1216
1215
|
onSwarmEvent(swarmEvent) {
|
|
1217
|
-
var _a;
|
|
1218
1216
|
log4("swarm event", {
|
|
1219
1217
|
swarmEvent
|
|
1220
1218
|
}, {
|
|
@@ -1250,7 +1248,7 @@ var Swarm = class {
|
|
|
1250
1248
|
const peer = this._peers.get(PublicKey4.from(swarmEvent.peerLeft.peer));
|
|
1251
1249
|
if (peer) {
|
|
1252
1250
|
peer.advertizing = false;
|
|
1253
|
-
if (
|
|
1251
|
+
if (peer.connection?.state !== ConnectionState.CONNECTED) {
|
|
1254
1252
|
void this._destroyPeer(peer.id).catch((err) => log4.catch(err, void 0, {
|
|
1255
1253
|
F: __dxlog_file4,
|
|
1256
1254
|
L: 188,
|
|
@@ -1263,7 +1261,6 @@ var Swarm = class {
|
|
|
1263
1261
|
this._topology.update();
|
|
1264
1262
|
}
|
|
1265
1263
|
async onOffer(message) {
|
|
1266
|
-
var _a, _b;
|
|
1267
1264
|
log4("offer", {
|
|
1268
1265
|
message
|
|
1269
1266
|
}, {
|
|
@@ -1292,7 +1289,7 @@ var Swarm = class {
|
|
|
1292
1289
|
""
|
|
1293
1290
|
]
|
|
1294
1291
|
});
|
|
1295
|
-
if (!
|
|
1292
|
+
if (!message.recipient?.equals(this._ownPeerId)) {
|
|
1296
1293
|
log4("rejecting offer with incorrect peerId", {
|
|
1297
1294
|
message
|
|
1298
1295
|
}, {
|
|
@@ -1305,7 +1302,7 @@ var Swarm = class {
|
|
|
1305
1302
|
accept: false
|
|
1306
1303
|
};
|
|
1307
1304
|
}
|
|
1308
|
-
if (!
|
|
1305
|
+
if (!message.topic?.equals(this._topic)) {
|
|
1309
1306
|
log4("rejecting offer with incorrect topic", {
|
|
1310
1307
|
message
|
|
1311
1308
|
}, {
|
|
@@ -1324,7 +1321,6 @@ var Swarm = class {
|
|
|
1324
1321
|
return answer;
|
|
1325
1322
|
}
|
|
1326
1323
|
async onSignal(message) {
|
|
1327
|
-
var _a, _b;
|
|
1328
1324
|
log4("signal", {
|
|
1329
1325
|
message
|
|
1330
1326
|
}, {
|
|
@@ -1342,7 +1338,7 @@ var Swarm = class {
|
|
|
1342
1338
|
});
|
|
1343
1339
|
return;
|
|
1344
1340
|
}
|
|
1345
|
-
invariant4(
|
|
1341
|
+
invariant4(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1346
1342
|
F: __dxlog_file4,
|
|
1347
1343
|
L: 227,
|
|
1348
1344
|
S: this,
|
|
@@ -1351,7 +1347,7 @@ var Swarm = class {
|
|
|
1351
1347
|
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1352
1348
|
]
|
|
1353
1349
|
});
|
|
1354
|
-
invariant4(
|
|
1350
|
+
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1355
1351
|
F: __dxlog_file4,
|
|
1356
1352
|
L: 231,
|
|
1357
1353
|
S: this,
|
|
@@ -1563,8 +1559,7 @@ var SwarmMapper = class {
|
|
|
1563
1559
|
}));
|
|
1564
1560
|
}));
|
|
1565
1561
|
this._subscriptions.add(_swarm.disconnected.on((peerId) => {
|
|
1566
|
-
|
|
1567
|
-
(_a = this._connectionSubscriptions.get(peerId)) == null ? void 0 : _a();
|
|
1562
|
+
this._connectionSubscriptions.get(peerId)?.();
|
|
1568
1563
|
this._connectionSubscriptions.delete(peerId);
|
|
1569
1564
|
this._update();
|
|
1570
1565
|
}));
|
|
@@ -1619,7 +1614,7 @@ import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
|
1619
1614
|
import { log as log6 } from "@dxos/log";
|
|
1620
1615
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
1621
1616
|
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
1622
|
-
var MAX_CONCURRENT_INITIATING_CONNECTIONS =
|
|
1617
|
+
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
|
|
1623
1618
|
var ConnectionLimiter = class {
|
|
1624
1619
|
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
1625
1620
|
this._ctx = new Context5();
|
|
@@ -1714,8 +1709,7 @@ var ConnectionLog = class {
|
|
|
1714
1709
|
this.update = new Event4();
|
|
1715
1710
|
}
|
|
1716
1711
|
getSwarmInfo(swarmId) {
|
|
1717
|
-
|
|
1718
|
-
return (_a = this._swarms.get(swarmId)) != null ? _a : raise(new Error(`Swarm not found: ${swarmId}`));
|
|
1712
|
+
return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
|
|
1719
1713
|
}
|
|
1720
1714
|
get swarms() {
|
|
1721
1715
|
return Array.from(this._swarms.values());
|
|
@@ -1731,9 +1725,9 @@ var ConnectionLog = class {
|
|
|
1731
1725
|
this._swarms.set(PublicKey7.from(swarm._instanceId), info);
|
|
1732
1726
|
this.update.emit();
|
|
1733
1727
|
swarm.connectionAdded.on((connection) => {
|
|
1734
|
-
var _a, _b;
|
|
1735
1728
|
const connectionInfo = {
|
|
1736
1729
|
state: ConnectionState.INITIAL,
|
|
1730
|
+
closeReason: connection.closeReason,
|
|
1737
1731
|
remotePeerId: connection.remoteId,
|
|
1738
1732
|
sessionId: connection.sessionId,
|
|
1739
1733
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
@@ -1744,13 +1738,14 @@ var ConnectionLog = class {
|
|
|
1744
1738
|
this.update.emit();
|
|
1745
1739
|
connection.stateChanged.on((state) => {
|
|
1746
1740
|
connectionInfo.state = state;
|
|
1741
|
+
connectionInfo.closeReason = connection.closeReason;
|
|
1747
1742
|
connectionInfo.events.push({
|
|
1748
1743
|
type: EventType.CONNECTION_STATE_CHANGED,
|
|
1749
1744
|
newState: state
|
|
1750
1745
|
});
|
|
1751
1746
|
this.update.emit();
|
|
1752
1747
|
});
|
|
1753
|
-
|
|
1748
|
+
connection.protocol?.stats?.on((stats) => {
|
|
1754
1749
|
connectionInfo.streams = stats.channels;
|
|
1755
1750
|
this.update.emit();
|
|
1756
1751
|
});
|
|
@@ -1785,10 +1780,7 @@ var NetworkManager = class {
|
|
|
1785
1780
|
this._instanceId = PublicKey8.random().toHex();
|
|
1786
1781
|
this._transportFactory = transportFactory;
|
|
1787
1782
|
this._signalManager = signalManager;
|
|
1788
|
-
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) =>
|
|
1789
|
-
var _a;
|
|
1790
|
-
return (_a = this._swarms.get(topic)) == null ? void 0 : _a.onSwarmEvent(event);
|
|
1791
|
-
});
|
|
1783
|
+
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => this._swarms.get(topic)?.onSwarmEvent(event));
|
|
1792
1784
|
this._messenger = new Messenger({
|
|
1793
1785
|
signalManager: this._signalManager
|
|
1794
1786
|
});
|
|
@@ -1856,7 +1848,6 @@ var NetworkManager = class {
|
|
|
1856
1848
|
* Join the swarm.
|
|
1857
1849
|
*/
|
|
1858
1850
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1859
|
-
var _a;
|
|
1860
1851
|
invariant6(PublicKey8.isPublicKey(topic), void 0, {
|
|
1861
1852
|
F: __dxlog_file7,
|
|
1862
1853
|
L: 157,
|
|
@@ -1930,7 +1921,7 @@ var NetworkManager = class {
|
|
|
1930
1921
|
C: (f, a) => f(...a)
|
|
1931
1922
|
}));
|
|
1932
1923
|
this.topicsUpdated.emit();
|
|
1933
|
-
|
|
1924
|
+
this._connectionLog?.joinedSwarm(swarm);
|
|
1934
1925
|
log7("joined", {
|
|
1935
1926
|
topic: PublicKey8.from(topic),
|
|
1936
1927
|
count: this._swarms.size
|
|
@@ -1948,7 +1939,6 @@ var NetworkManager = class {
|
|
|
1948
1939
|
* Close the connection.
|
|
1949
1940
|
*/
|
|
1950
1941
|
async leaveSwarm(topic) {
|
|
1951
|
-
var _a;
|
|
1952
1942
|
if (!this._swarms.has(topic)) {
|
|
1953
1943
|
return;
|
|
1954
1944
|
}
|
|
@@ -1968,7 +1958,7 @@ var NetworkManager = class {
|
|
|
1968
1958
|
const map = this._mappers.get(topic);
|
|
1969
1959
|
map.destroy();
|
|
1970
1960
|
this._mappers.delete(topic);
|
|
1971
|
-
|
|
1961
|
+
this._connectionLog?.leftSwarm(swarm);
|
|
1972
1962
|
await swarm.destroy();
|
|
1973
1963
|
this._swarms.delete(topic);
|
|
1974
1964
|
await this.topicsUpdated.emit();
|
|
@@ -2289,9 +2279,12 @@ var createStreamDelay = (delay) => {
|
|
|
2289
2279
|
var MemoryTransportFactory = {
|
|
2290
2280
|
createTransport: (params) => new MemoryTransport(params)
|
|
2291
2281
|
};
|
|
2292
|
-
var
|
|
2282
|
+
var MemoryTransport = class _MemoryTransport {
|
|
2283
|
+
static {
|
|
2284
|
+
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2285
|
+
this._connections = new ComplexMap7(PublicKey9.hash);
|
|
2286
|
+
}
|
|
2293
2287
|
constructor(options) {
|
|
2294
|
-
var _a;
|
|
2295
2288
|
this.options = options;
|
|
2296
2289
|
this.closed = new Event6();
|
|
2297
2290
|
this.connected = new Event6();
|
|
@@ -2337,7 +2330,7 @@ var _MemoryTransport = class {
|
|
|
2337
2330
|
});
|
|
2338
2331
|
} else {
|
|
2339
2332
|
this._remote.wait({
|
|
2340
|
-
timeout:
|
|
2333
|
+
timeout: this.options.timeout ?? 1e3
|
|
2341
2334
|
}).then((remoteId) => {
|
|
2342
2335
|
if (this._destroyed) {
|
|
2343
2336
|
return;
|
|
@@ -2424,7 +2417,7 @@ var _MemoryTransport = class {
|
|
|
2424
2417
|
S: this,
|
|
2425
2418
|
C: (f, a) => f(...a)
|
|
2426
2419
|
});
|
|
2427
|
-
if (!
|
|
2420
|
+
if (!payload?.transportId) {
|
|
2428
2421
|
return;
|
|
2429
2422
|
}
|
|
2430
2423
|
const transportId = payload.transportId;
|
|
@@ -2434,9 +2427,6 @@ var _MemoryTransport = class {
|
|
|
2434
2427
|
}
|
|
2435
2428
|
}
|
|
2436
2429
|
};
|
|
2437
|
-
var MemoryTransport = _MemoryTransport;
|
|
2438
|
-
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2439
|
-
MemoryTransport._connections = new ComplexMap7(PublicKey9.hash);
|
|
2440
2430
|
_ts_decorate4([
|
|
2441
2431
|
logInfo2
|
|
2442
2432
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
@@ -2457,43 +2447,47 @@ import { trace as trace4 } from "@dxos/protocols";
|
|
|
2457
2447
|
var wrtc = null;
|
|
2458
2448
|
try {
|
|
2459
2449
|
wrtc = __require("@koush/wrtc");
|
|
2460
|
-
} catch
|
|
2450
|
+
} catch {
|
|
2461
2451
|
}
|
|
2462
2452
|
|
|
2463
2453
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
2464
2454
|
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
2465
2455
|
var WebRTCTransport = class {
|
|
2466
2456
|
constructor(params) {
|
|
2467
|
-
var _a;
|
|
2468
2457
|
this.params = params;
|
|
2458
|
+
this._instanceId = PublicKey10.random().toHex();
|
|
2469
2459
|
this._closed = false;
|
|
2470
2460
|
this.closed = new Event7();
|
|
2471
2461
|
this.connected = new Event7();
|
|
2472
2462
|
this.errors = new ErrorStream4();
|
|
2473
|
-
this._instanceId = PublicKey10.random().toHex();
|
|
2474
2463
|
log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.begin({
|
|
2475
2464
|
id: this._instanceId
|
|
2476
2465
|
}), {
|
|
2477
2466
|
F: __dxlog_file12,
|
|
2478
|
-
L:
|
|
2467
|
+
L: 44,
|
|
2479
2468
|
S: this,
|
|
2480
2469
|
C: (f, a) => f(...a)
|
|
2481
2470
|
});
|
|
2482
2471
|
log11("created connection", params, {
|
|
2483
2472
|
F: __dxlog_file12,
|
|
2484
|
-
L:
|
|
2473
|
+
L: 45,
|
|
2485
2474
|
S: this,
|
|
2486
2475
|
C: (f, a) => f(...a)
|
|
2487
2476
|
});
|
|
2488
2477
|
this._peer = new SimplePeerConstructor({
|
|
2489
2478
|
initiator: this.params.initiator,
|
|
2490
|
-
|
|
2491
|
-
|
|
2479
|
+
config: this.params.webrtcConfig,
|
|
2480
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createDataChannel
|
|
2481
|
+
channelConfig: {
|
|
2482
|
+
protocol: "dxos.mesh"
|
|
2483
|
+
},
|
|
2484
|
+
// Custom WebRTC implementation (for Node); otherwise get-browser-rtc.
|
|
2485
|
+
wrtc: SimplePeerConstructor.WEBRTC_SUPPORT ? void 0 : wrtc ?? raise2(new Error("wrtc not available"))
|
|
2492
2486
|
});
|
|
2493
2487
|
this._peer.on("signal", async (data) => {
|
|
2494
2488
|
log11("signal", data, {
|
|
2495
2489
|
F: __dxlog_file12,
|
|
2496
|
-
L:
|
|
2490
|
+
L: 62,
|
|
2497
2491
|
S: this,
|
|
2498
2492
|
C: (f, a) => f(...a)
|
|
2499
2493
|
});
|
|
@@ -2506,7 +2500,7 @@ var WebRTCTransport = class {
|
|
|
2506
2500
|
this._peer.on("connect", () => {
|
|
2507
2501
|
log11("connected", void 0, {
|
|
2508
2502
|
F: __dxlog_file12,
|
|
2509
|
-
L:
|
|
2503
|
+
L: 67,
|
|
2510
2504
|
S: this,
|
|
2511
2505
|
C: (f, a) => f(...a)
|
|
2512
2506
|
});
|
|
@@ -2516,7 +2510,7 @@ var WebRTCTransport = class {
|
|
|
2516
2510
|
this._peer.on("close", async () => {
|
|
2517
2511
|
log11("closed", void 0, {
|
|
2518
2512
|
F: __dxlog_file12,
|
|
2519
|
-
L:
|
|
2513
|
+
L: 73,
|
|
2520
2514
|
S: this,
|
|
2521
2515
|
C: (f, a) => f(...a)
|
|
2522
2516
|
});
|
|
@@ -2524,23 +2518,22 @@ var WebRTCTransport = class {
|
|
|
2524
2518
|
this.closed.emit();
|
|
2525
2519
|
});
|
|
2526
2520
|
this._peer.on("error", async (err) => {
|
|
2527
|
-
var _a2;
|
|
2528
2521
|
this.errors.raise(err);
|
|
2529
2522
|
try {
|
|
2530
|
-
if (typeof
|
|
2523
|
+
if (typeof this._peer?._pc.getStats === "function") {
|
|
2531
2524
|
this._peer._pc.getStats().then((stats) => {
|
|
2532
2525
|
log11.warn("report after webrtc error", {
|
|
2533
2526
|
config: this.params.webrtcConfig,
|
|
2534
2527
|
stats
|
|
2535
2528
|
}, {
|
|
2536
2529
|
F: __dxlog_file12,
|
|
2537
|
-
L:
|
|
2530
|
+
L: 85,
|
|
2538
2531
|
S: this,
|
|
2539
2532
|
C: (f, a) => f(...a)
|
|
2540
2533
|
});
|
|
2541
2534
|
});
|
|
2542
2535
|
}
|
|
2543
|
-
} catch
|
|
2536
|
+
} catch {
|
|
2544
2537
|
}
|
|
2545
2538
|
await this.destroy();
|
|
2546
2539
|
});
|
|
@@ -2548,7 +2541,7 @@ var WebRTCTransport = class {
|
|
|
2548
2541
|
id: this._instanceId
|
|
2549
2542
|
}), {
|
|
2550
2543
|
F: __dxlog_file12,
|
|
2551
|
-
L:
|
|
2544
|
+
L: 95,
|
|
2552
2545
|
S: this,
|
|
2553
2546
|
C: (f, a) => f(...a)
|
|
2554
2547
|
});
|
|
@@ -2556,7 +2549,7 @@ var WebRTCTransport = class {
|
|
|
2556
2549
|
async destroy() {
|
|
2557
2550
|
log11("closing...", void 0, {
|
|
2558
2551
|
F: __dxlog_file12,
|
|
2559
|
-
L:
|
|
2552
|
+
L: 99,
|
|
2560
2553
|
S: this,
|
|
2561
2554
|
C: (f, a) => f(...a)
|
|
2562
2555
|
});
|
|
@@ -2566,7 +2559,7 @@ var WebRTCTransport = class {
|
|
|
2566
2559
|
this.closed.emit();
|
|
2567
2560
|
log11("closed", void 0, {
|
|
2568
2561
|
F: __dxlog_file12,
|
|
2569
|
-
L:
|
|
2562
|
+
L: 104,
|
|
2570
2563
|
S: this,
|
|
2571
2564
|
C: (f, a) => f(...a)
|
|
2572
2565
|
});
|
|
@@ -2577,7 +2570,7 @@ var WebRTCTransport = class {
|
|
|
2577
2570
|
}
|
|
2578
2571
|
invariant11(signal.payload.data, "Signal message must contain signal data.", {
|
|
2579
2572
|
F: __dxlog_file12,
|
|
2580
|
-
L:
|
|
2573
|
+
L: 112,
|
|
2581
2574
|
S: this,
|
|
2582
2575
|
A: [
|
|
2583
2576
|
"signal.payload.data",
|
|
@@ -2587,8 +2580,7 @@ var WebRTCTransport = class {
|
|
|
2587
2580
|
this._peer.signal(signal.payload.data);
|
|
2588
2581
|
}
|
|
2589
2582
|
async _disconnectStreams() {
|
|
2590
|
-
|
|
2591
|
-
(_d = (_c = (_b = (_a = this.params.stream).unpipe) == null ? void 0 : _b.call(_a, this._peer)) == null ? void 0 : _c.unpipe) == null ? void 0 : _d.call(_c, this.params.stream);
|
|
2583
|
+
this.params.stream.unpipe?.(this._peer)?.unpipe?.(this.params.stream);
|
|
2592
2584
|
}
|
|
2593
2585
|
};
|
|
2594
2586
|
var createWebRTCTransportFactory = (webrtcConfig) => ({
|
|
@@ -2716,9 +2708,8 @@ var WebRTCTransportService = class {
|
|
|
2716
2708
|
}
|
|
2717
2709
|
}
|
|
2718
2710
|
async close({ proxyId }) {
|
|
2719
|
-
|
|
2720
|
-
await
|
|
2721
|
-
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2711
|
+
await this.transports.get(proxyId)?.transport.destroy();
|
|
2712
|
+
await this.transports.get(proxyId)?.stream.end();
|
|
2722
2713
|
this.transports.delete(proxyId);
|
|
2723
2714
|
log12("Closed.", void 0, {
|
|
2724
2715
|
F: __dxlog_file13,
|
|
@@ -2747,9 +2738,9 @@ var WebRTCTransportProxy = class {
|
|
|
2747
2738
|
this._proxyId = PublicKey12.random();
|
|
2748
2739
|
this._ctx = new Context6();
|
|
2749
2740
|
this.closed = new Event8();
|
|
2750
|
-
this._closed = false;
|
|
2751
2741
|
this.connected = new Event8();
|
|
2752
2742
|
this.errors = new ErrorStream5();
|
|
2743
|
+
this._closed = false;
|
|
2753
2744
|
this._serviceStream = this._params.bridgeService.open({
|
|
2754
2745
|
proxyId: this._proxyId,
|
|
2755
2746
|
initiator: this._params.initiator
|
|
@@ -2825,7 +2816,7 @@ var WebRTCTransportProxy = class {
|
|
|
2825
2816
|
if (this._closed) {
|
|
2826
2817
|
return;
|
|
2827
2818
|
}
|
|
2828
|
-
this._serviceStream.close();
|
|
2819
|
+
await this._serviceStream.close();
|
|
2829
2820
|
try {
|
|
2830
2821
|
await this._params.bridgeService.close({
|
|
2831
2822
|
proxyId: this._proxyId
|
|
@@ -2846,7 +2837,7 @@ var WebRTCTransportProxy = class {
|
|
|
2846
2837
|
*/
|
|
2847
2838
|
// TODO(burdon): Option on close method.
|
|
2848
2839
|
forceClose() {
|
|
2849
|
-
this._serviceStream.close();
|
|
2840
|
+
void this._serviceStream.close();
|
|
2850
2841
|
this.closed.emit();
|
|
2851
2842
|
this._closed = true;
|
|
2852
2843
|
}
|
|
@@ -2927,4 +2918,4 @@ export {
|
|
|
2927
2918
|
WebRTCTransportProxyFactory,
|
|
2928
2919
|
createTeleportProtocolFactory
|
|
2929
2920
|
};
|
|
2930
|
-
//# sourceMappingURL=chunk-
|
|
2921
|
+
//# sourceMappingURL=chunk-WQ3YXGWP.mjs.map
|