@dxos/messaging 0.3.8-next.f4e0086 → 0.3.9-main.14901ff
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/index.mjs +20 -10
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +108 -124
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/signal-manager/websocket-signal-manager.ts +6 -3
package/dist/lib/node/index.cjs
CHANGED
|
@@ -26,19 +26,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
29
|
+
var node_exports = {};
|
|
30
|
+
__export(node_exports, {
|
|
33
31
|
MemorySignalManager: () => MemorySignalManager,
|
|
34
32
|
MemorySignalManagerContext: () => MemorySignalManagerContext,
|
|
35
33
|
Messenger: () => Messenger,
|
|
36
34
|
SignalClient: () => SignalClient,
|
|
37
35
|
WebsocketSignalManager: () => WebsocketSignalManager
|
|
38
36
|
});
|
|
39
|
-
module.exports = __toCommonJS(
|
|
40
|
-
|
|
41
|
-
// packages/core/mesh/messaging/src/messenger.ts
|
|
37
|
+
module.exports = __toCommonJS(node_exports);
|
|
42
38
|
var import_async = require("@dxos/async");
|
|
43
39
|
var import_context = require("@dxos/context");
|
|
44
40
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -46,26 +42,45 @@ var import_keys = require("@dxos/keys");
|
|
|
46
42
|
var import_log = require("@dxos/log");
|
|
47
43
|
var import_protocols = require("@dxos/protocols");
|
|
48
44
|
var import_util = require("@dxos/util");
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
var import_async2 = require("@dxos/async");
|
|
46
|
+
var import_context2 = require("@dxos/context");
|
|
47
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
48
|
+
var import_keys2 = require("@dxos/keys");
|
|
49
|
+
var import_log2 = require("@dxos/log");
|
|
50
|
+
var import_protocols2 = require("@dxos/protocols");
|
|
51
|
+
var import_signal = require("@dxos/protocols/proto/dxos/mesh/signal");
|
|
52
|
+
var import_util2 = require("@dxos/util");
|
|
53
|
+
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
54
|
+
var import_async3 = require("@dxos/async");
|
|
55
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
56
|
+
var import_keys3 = require("@dxos/keys");
|
|
57
|
+
var import_log3 = require("@dxos/log");
|
|
58
|
+
var import_protocols3 = require("@dxos/protocols");
|
|
59
|
+
var import_rpc = require("@dxos/rpc");
|
|
60
|
+
var import_async4 = require("@dxos/async");
|
|
61
|
+
var import_context3 = require("@dxos/context");
|
|
62
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
63
|
+
var import_keys4 = require("@dxos/keys");
|
|
64
|
+
var import_log4 = require("@dxos/log");
|
|
65
|
+
var import_protocols4 = require("@dxos/protocols");
|
|
66
|
+
var import_util3 = require("@dxos/util");
|
|
67
|
+
var import_async5 = require("@dxos/async");
|
|
68
|
+
var import_context4 = require("@dxos/context");
|
|
69
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
70
|
+
var import_keys5 = require("@dxos/keys");
|
|
71
|
+
var import_log5 = require("@dxos/log");
|
|
72
|
+
var import_protocols5 = require("@dxos/protocols");
|
|
51
73
|
var MESSAGE_TIMEOUT = 1e4;
|
|
52
|
-
|
|
53
|
-
// packages/core/mesh/messaging/src/messenger.ts
|
|
54
74
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/messenger.ts";
|
|
55
75
|
var ReliablePayload = import_protocols.schema.getCodecForType("dxos.mesh.messaging.ReliablePayload");
|
|
56
76
|
var Acknowledgement = import_protocols.schema.getCodecForType("dxos.mesh.messaging.Acknowledgement");
|
|
57
77
|
var RECEIVED_MESSAGES_GC_INTERVAL = 12e4;
|
|
58
78
|
var Messenger = class {
|
|
59
79
|
constructor({ signalManager, retryDelay = 300 }) {
|
|
60
|
-
// { peerId, payloadType } => listeners set
|
|
61
80
|
this._listeners = new import_util.ComplexMap(({ peerId, payloadType }) => peerId.toHex() + payloadType);
|
|
62
|
-
// peerId => listeners set
|
|
63
81
|
this._defaultListeners = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
64
82
|
this._onAckCallbacks = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
65
83
|
this._receivedMessages = new import_util.ComplexSet(import_keys.PublicKey.hash);
|
|
66
|
-
/**
|
|
67
|
-
* Keys scheduled to be cleared from _receivedMessages on the next iteration.
|
|
68
|
-
*/
|
|
69
84
|
this._toClear = new import_util.ComplexSet(import_keys.PublicKey.hash);
|
|
70
85
|
this._closed = true;
|
|
71
86
|
this._signalManager = signalManager;
|
|
@@ -392,32 +407,13 @@ var Messenger = class {
|
|
|
392
407
|
}
|
|
393
408
|
}
|
|
394
409
|
};
|
|
395
|
-
|
|
396
|
-
// packages/core/mesh/messaging/src/signal-client/signal-client.ts
|
|
397
|
-
var import_async3 = require("@dxos/async");
|
|
398
|
-
var import_context2 = require("@dxos/context");
|
|
399
|
-
var import_invariant3 = require("@dxos/invariant");
|
|
400
|
-
var import_keys3 = require("@dxos/keys");
|
|
401
|
-
var import_log3 = require("@dxos/log");
|
|
402
|
-
var import_protocols3 = require("@dxos/protocols");
|
|
403
|
-
var import_signal = require("@dxos/protocols/proto/dxos/mesh/signal");
|
|
404
|
-
var import_util2 = require("@dxos/util");
|
|
405
|
-
|
|
406
|
-
// packages/core/mesh/messaging/src/signal-client/signal-rpc-client.ts
|
|
407
|
-
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
408
|
-
var import_async2 = require("@dxos/async");
|
|
409
|
-
var import_invariant2 = require("@dxos/invariant");
|
|
410
|
-
var import_keys2 = require("@dxos/keys");
|
|
411
|
-
var import_log2 = require("@dxos/log");
|
|
412
|
-
var import_protocols2 = require("@dxos/protocols");
|
|
413
|
-
var import_rpc = require("@dxos/rpc");
|
|
414
410
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-client/signal-rpc-client.ts";
|
|
415
411
|
var SignalRPCClient = class {
|
|
416
412
|
constructor({ url, callbacks = {} }) {
|
|
417
|
-
this._connectTrigger = new
|
|
413
|
+
this._connectTrigger = new import_async3.Trigger();
|
|
418
414
|
this._closed = false;
|
|
419
|
-
const traceId =
|
|
420
|
-
|
|
415
|
+
const traceId = import_keys3.PublicKey.random().toHex();
|
|
416
|
+
import_log3.log.trace("dxos.mesh.signal-rpc-client.constructor", import_protocols3.trace.begin({
|
|
421
417
|
id: traceId
|
|
422
418
|
}), {
|
|
423
419
|
F: __dxlog_file2,
|
|
@@ -430,7 +426,7 @@ var SignalRPCClient = class {
|
|
|
430
426
|
this._socket = new import_isomorphic_ws.default(this._url);
|
|
431
427
|
this._rpc = (0, import_rpc.createProtoRpcPeer)({
|
|
432
428
|
requested: {
|
|
433
|
-
Signal:
|
|
429
|
+
Signal: import_protocols3.schema.getService("dxos.mesh.signal.Signal")
|
|
434
430
|
},
|
|
435
431
|
noHandshake: true,
|
|
436
432
|
port: {
|
|
@@ -441,7 +437,7 @@ var SignalRPCClient = class {
|
|
|
441
437
|
try {
|
|
442
438
|
this._socket.send(msg);
|
|
443
439
|
} catch (err) {
|
|
444
|
-
|
|
440
|
+
import_log3.log.warn("send error", err, {
|
|
445
441
|
F: __dxlog_file2,
|
|
446
442
|
L: 68,
|
|
447
443
|
S: this,
|
|
@@ -466,7 +462,7 @@ var SignalRPCClient = class {
|
|
|
466
462
|
this._socket.onopen = async () => {
|
|
467
463
|
try {
|
|
468
464
|
await this._rpc.open();
|
|
469
|
-
(0,
|
|
465
|
+
(0, import_log3.log)(`RPC open ${this._url}`, void 0, {
|
|
470
466
|
F: __dxlog_file2,
|
|
471
467
|
L: 89,
|
|
472
468
|
S: this,
|
|
@@ -479,7 +475,7 @@ var SignalRPCClient = class {
|
|
|
479
475
|
}
|
|
480
476
|
};
|
|
481
477
|
this._socket.onclose = async () => {
|
|
482
|
-
(0,
|
|
478
|
+
(0, import_log3.log)(`Disconnected ${this._url}`, void 0, {
|
|
483
479
|
F: __dxlog_file2,
|
|
484
480
|
L: 98,
|
|
485
481
|
S: this,
|
|
@@ -497,7 +493,7 @@ var SignalRPCClient = class {
|
|
|
497
493
|
try {
|
|
498
494
|
await this._rpc?.close();
|
|
499
495
|
} catch (err) {
|
|
500
|
-
|
|
496
|
+
import_log3.log.catch(err, void 0, {
|
|
501
497
|
F: __dxlog_file2,
|
|
502
498
|
L: 115,
|
|
503
499
|
S: this,
|
|
@@ -505,7 +501,7 @@ var SignalRPCClient = class {
|
|
|
505
501
|
});
|
|
506
502
|
}
|
|
507
503
|
this._closed = true;
|
|
508
|
-
|
|
504
|
+
import_log3.log.warn(event.message ?? "Socket error", {
|
|
509
505
|
url: this._url
|
|
510
506
|
}, {
|
|
511
507
|
F: __dxlog_file2,
|
|
@@ -514,7 +510,7 @@ var SignalRPCClient = class {
|
|
|
514
510
|
C: (f, a) => f(...a)
|
|
515
511
|
});
|
|
516
512
|
};
|
|
517
|
-
|
|
513
|
+
import_log3.log.trace("dxos.mesh.signal-rpc-client.constructor", import_protocols3.trace.end({
|
|
518
514
|
id: traceId
|
|
519
515
|
}), {
|
|
520
516
|
F: __dxlog_file2,
|
|
@@ -529,7 +525,7 @@ var SignalRPCClient = class {
|
|
|
529
525
|
await this._rpc?.close();
|
|
530
526
|
this._socket?.close();
|
|
531
527
|
} catch (err) {
|
|
532
|
-
|
|
528
|
+
import_log3.log.warn("close error", err, {
|
|
533
529
|
F: __dxlog_file2,
|
|
534
530
|
L: 131,
|
|
535
531
|
S: this,
|
|
@@ -538,7 +534,7 @@ var SignalRPCClient = class {
|
|
|
538
534
|
}
|
|
539
535
|
}
|
|
540
536
|
async join({ topic, peerId }) {
|
|
541
|
-
(0,
|
|
537
|
+
(0, import_log3.log)("join", {
|
|
542
538
|
topic,
|
|
543
539
|
peerId
|
|
544
540
|
}, {
|
|
@@ -548,7 +544,7 @@ var SignalRPCClient = class {
|
|
|
548
544
|
C: (f, a) => f(...a)
|
|
549
545
|
});
|
|
550
546
|
await this._connectTrigger.wait();
|
|
551
|
-
(0,
|
|
547
|
+
(0, import_invariant3.invariant)(!this._closed, "SignalRPCClient is closed", {
|
|
552
548
|
F: __dxlog_file2,
|
|
553
549
|
L: 138,
|
|
554
550
|
S: this,
|
|
@@ -557,7 +553,7 @@ var SignalRPCClient = class {
|
|
|
557
553
|
"'SignalRPCClient is closed'"
|
|
558
554
|
]
|
|
559
555
|
});
|
|
560
|
-
(0,
|
|
556
|
+
(0, import_invariant3.invariant)(this._rpc, "Rpc is not initialized", {
|
|
561
557
|
F: __dxlog_file2,
|
|
562
558
|
L: 139,
|
|
563
559
|
S: this,
|
|
@@ -574,7 +570,7 @@ var SignalRPCClient = class {
|
|
|
574
570
|
return swarmStream;
|
|
575
571
|
}
|
|
576
572
|
async receiveMessages(peerId) {
|
|
577
|
-
(0,
|
|
573
|
+
(0, import_log3.log)("receiveMessages", {
|
|
578
574
|
peerId
|
|
579
575
|
}, {
|
|
580
576
|
F: __dxlog_file2,
|
|
@@ -582,7 +578,7 @@ var SignalRPCClient = class {
|
|
|
582
578
|
S: this,
|
|
583
579
|
C: (f, a) => f(...a)
|
|
584
580
|
});
|
|
585
|
-
(0,
|
|
581
|
+
(0, import_invariant3.invariant)(!this._closed, "SignalRPCClient is closed", {
|
|
586
582
|
F: __dxlog_file2,
|
|
587
583
|
L: 150,
|
|
588
584
|
S: this,
|
|
@@ -592,7 +588,7 @@ var SignalRPCClient = class {
|
|
|
592
588
|
]
|
|
593
589
|
});
|
|
594
590
|
await this._connectTrigger.wait();
|
|
595
|
-
(0,
|
|
591
|
+
(0, import_invariant3.invariant)(this._rpc, "Rpc is not initialized", {
|
|
596
592
|
F: __dxlog_file2,
|
|
597
593
|
L: 152,
|
|
598
594
|
S: this,
|
|
@@ -608,7 +604,7 @@ var SignalRPCClient = class {
|
|
|
608
604
|
return messageStream;
|
|
609
605
|
}
|
|
610
606
|
async sendMessage({ author, recipient, payload }) {
|
|
611
|
-
(0,
|
|
607
|
+
(0, import_log3.log)("sendMessage", {
|
|
612
608
|
author,
|
|
613
609
|
recipient,
|
|
614
610
|
payload
|
|
@@ -618,7 +614,7 @@ var SignalRPCClient = class {
|
|
|
618
614
|
S: this,
|
|
619
615
|
C: (f, a) => f(...a)
|
|
620
616
|
});
|
|
621
|
-
(0,
|
|
617
|
+
(0, import_invariant3.invariant)(!this._closed, "SignalRPCClient is closed", {
|
|
622
618
|
F: __dxlog_file2,
|
|
623
619
|
L: 162,
|
|
624
620
|
S: this,
|
|
@@ -628,7 +624,7 @@ var SignalRPCClient = class {
|
|
|
628
624
|
]
|
|
629
625
|
});
|
|
630
626
|
await this._connectTrigger.wait();
|
|
631
|
-
(0,
|
|
627
|
+
(0, import_invariant3.invariant)(this._rpc, "Rpc is not initialized", {
|
|
632
628
|
F: __dxlog_file2,
|
|
633
629
|
L: 164,
|
|
634
630
|
S: this,
|
|
@@ -644,8 +640,6 @@ var SignalRPCClient = class {
|
|
|
644
640
|
});
|
|
645
641
|
}
|
|
646
642
|
};
|
|
647
|
-
|
|
648
|
-
// packages/core/mesh/messaging/src/signal-client/signal-client.ts
|
|
649
643
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-client/signal-client.ts";
|
|
650
644
|
var DEFAULT_RECONNECT_TIMEOUT = 100;
|
|
651
645
|
var MAX_RECONNECT_TIMEOUT = 5e3;
|
|
@@ -664,15 +658,15 @@ var SignalClient = class {
|
|
|
664
658
|
this._reconnectAfter = DEFAULT_RECONNECT_TIMEOUT;
|
|
665
659
|
this._connectionStarted = /* @__PURE__ */ new Date();
|
|
666
660
|
this._lastStateChange = /* @__PURE__ */ new Date();
|
|
667
|
-
this._clientReady = new
|
|
668
|
-
this.statusChanged = new
|
|
669
|
-
this.commandTrace = new
|
|
661
|
+
this._clientReady = new import_async2.Trigger();
|
|
662
|
+
this.statusChanged = new import_async2.Event();
|
|
663
|
+
this.commandTrace = new import_async2.Event();
|
|
670
664
|
this._swarmStreams = new import_util2.ComplexMap(({ topic, peerId }) => topic.toHex() + peerId.toHex());
|
|
671
665
|
this._joinedTopics = new import_util2.ComplexSet(({ topic, peerId }) => topic.toHex() + peerId.toHex());
|
|
672
666
|
this._messageStreams = new import_util2.ComplexMap((key) => key.toHex());
|
|
673
667
|
this._subscribedMessages = new import_util2.ComplexSet(({ peerId }) => peerId.toHex());
|
|
674
|
-
this._reconciled = new
|
|
675
|
-
this._instanceId =
|
|
668
|
+
this._reconciled = new import_async2.Event();
|
|
669
|
+
this._instanceId = import_keys2.PublicKey.random().toHex();
|
|
676
670
|
this._performance = {
|
|
677
671
|
sentMessages: 0,
|
|
678
672
|
receivedMessages: 0,
|
|
@@ -685,7 +679,7 @@ var SignalClient = class {
|
|
|
685
679
|
}
|
|
686
680
|
}
|
|
687
681
|
open() {
|
|
688
|
-
|
|
682
|
+
import_log2.log.trace("dxos.mesh.signal-client.open", import_protocols2.trace.begin({
|
|
689
683
|
id: this._instanceId
|
|
690
684
|
}), {
|
|
691
685
|
F: __dxlog_file3,
|
|
@@ -705,7 +699,7 @@ var SignalClient = class {
|
|
|
705
699
|
return;
|
|
706
700
|
}
|
|
707
701
|
if (this._state === import_signal.SignalState.CONNECTED) {
|
|
708
|
-
|
|
702
|
+
import_log2.log.warn("SignalClient error:", err, {
|
|
709
703
|
F: __dxlog_file3,
|
|
710
704
|
L: 147,
|
|
711
705
|
S: this,
|
|
@@ -715,22 +709,22 @@ var SignalClient = class {
|
|
|
715
709
|
this._scheduleReconcileAfterError();
|
|
716
710
|
}
|
|
717
711
|
});
|
|
718
|
-
this._reconcileTask = new
|
|
712
|
+
this._reconcileTask = new import_async2.DeferredTask(this._ctx, async () => {
|
|
719
713
|
await this._reconcileSwarmSubscriptions();
|
|
720
714
|
await this._reconcileMessageSubscriptions();
|
|
721
715
|
this._reconciled.emit();
|
|
722
716
|
});
|
|
723
|
-
(0,
|
|
717
|
+
(0, import_async2.scheduleTaskInterval)(this._ctx, async () => {
|
|
724
718
|
if (this._state === import_signal.SignalState.CONNECTED) {
|
|
725
719
|
this._reconcileTask.schedule();
|
|
726
720
|
}
|
|
727
721
|
}, RECONCILE_INTERVAL);
|
|
728
|
-
this._reconnectTask = new
|
|
722
|
+
this._reconnectTask = new import_async2.DeferredTask(this._ctx, async () => {
|
|
729
723
|
await this._reconnect();
|
|
730
724
|
});
|
|
731
725
|
this._setState(import_signal.SignalState.CONNECTING);
|
|
732
726
|
this._createClient();
|
|
733
|
-
|
|
727
|
+
import_log2.log.trace("dxos.mesh.signal-client.open", import_protocols2.trace.end({
|
|
734
728
|
id: this._instanceId
|
|
735
729
|
}), {
|
|
736
730
|
F: __dxlog_file3,
|
|
@@ -740,7 +734,7 @@ var SignalClient = class {
|
|
|
740
734
|
});
|
|
741
735
|
}
|
|
742
736
|
async close() {
|
|
743
|
-
(0,
|
|
737
|
+
(0, import_log2.log)("closing...", void 0, {
|
|
744
738
|
F: __dxlog_file3,
|
|
745
739
|
L: 180,
|
|
746
740
|
S: this,
|
|
@@ -756,7 +750,7 @@ var SignalClient = class {
|
|
|
756
750
|
await this._client?.close();
|
|
757
751
|
this._client = void 0;
|
|
758
752
|
this._setState(import_signal.SignalState.CLOSED);
|
|
759
|
-
(0,
|
|
753
|
+
(0, import_log2.log)("closed", void 0, {
|
|
760
754
|
F: __dxlog_file3,
|
|
761
755
|
L: 191,
|
|
762
756
|
S: this,
|
|
@@ -774,7 +768,7 @@ var SignalClient = class {
|
|
|
774
768
|
};
|
|
775
769
|
}
|
|
776
770
|
async join({ topic, peerId }) {
|
|
777
|
-
(0,
|
|
771
|
+
(0, import_log2.log)("joining", {
|
|
778
772
|
topic,
|
|
779
773
|
peerId
|
|
780
774
|
}, {
|
|
@@ -792,7 +786,7 @@ var SignalClient = class {
|
|
|
792
786
|
}
|
|
793
787
|
async leave({ topic, peerId }) {
|
|
794
788
|
this._performance.leaveCounter++;
|
|
795
|
-
(0,
|
|
789
|
+
(0, import_log2.log)("leaving", {
|
|
796
790
|
topic,
|
|
797
791
|
peerId
|
|
798
792
|
}, {
|
|
@@ -817,7 +811,7 @@ var SignalClient = class {
|
|
|
817
811
|
async sendMessage(msg) {
|
|
818
812
|
this._performance.sentMessages++;
|
|
819
813
|
await this._clientReady.wait();
|
|
820
|
-
(0,
|
|
814
|
+
(0, import_invariant2.invariant)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server", {
|
|
821
815
|
F: __dxlog_file3,
|
|
822
816
|
L: 224,
|
|
823
817
|
S: this,
|
|
@@ -829,7 +823,7 @@ var SignalClient = class {
|
|
|
829
823
|
await this._client.sendMessage(msg);
|
|
830
824
|
}
|
|
831
825
|
async subscribeMessages(peerId) {
|
|
832
|
-
(0,
|
|
826
|
+
(0, import_log2.log)("subscribing to messages", {
|
|
833
827
|
peerId
|
|
834
828
|
}, {
|
|
835
829
|
F: __dxlog_file3,
|
|
@@ -843,7 +837,7 @@ var SignalClient = class {
|
|
|
843
837
|
this._reconcileTask.schedule();
|
|
844
838
|
}
|
|
845
839
|
async unsubscribeMessages(peerId) {
|
|
846
|
-
(0,
|
|
840
|
+
(0, import_log2.log)("unsubscribing from messages", {
|
|
847
841
|
peerId
|
|
848
842
|
}, {
|
|
849
843
|
F: __dxlog_file3,
|
|
@@ -858,14 +852,14 @@ var SignalClient = class {
|
|
|
858
852
|
this._messageStreams.delete(peerId);
|
|
859
853
|
}
|
|
860
854
|
_scheduleReconcileAfterError() {
|
|
861
|
-
(0,
|
|
855
|
+
(0, import_async2.scheduleTask)(this._ctx, () => {
|
|
862
856
|
this._reconcileTask.schedule();
|
|
863
857
|
}, ERROR_RECONCILE_DELAY);
|
|
864
858
|
}
|
|
865
859
|
_setState(newState) {
|
|
866
860
|
this._state = newState;
|
|
867
861
|
this._lastStateChange = /* @__PURE__ */ new Date();
|
|
868
|
-
(0,
|
|
862
|
+
(0, import_log2.log)("signal state changed", {
|
|
869
863
|
status: this.getStatus()
|
|
870
864
|
}, {
|
|
871
865
|
F: __dxlog_file3,
|
|
@@ -876,7 +870,7 @@ var SignalClient = class {
|
|
|
876
870
|
this.statusChanged.emit(this.getStatus());
|
|
877
871
|
}
|
|
878
872
|
_createClient() {
|
|
879
|
-
(0,
|
|
873
|
+
(0, import_log2.log)("creating client", {
|
|
880
874
|
host: this._host,
|
|
881
875
|
state: this._state
|
|
882
876
|
}, {
|
|
@@ -885,7 +879,7 @@ var SignalClient = class {
|
|
|
885
879
|
S: this,
|
|
886
880
|
C: (f, a) => f(...a)
|
|
887
881
|
});
|
|
888
|
-
(0,
|
|
882
|
+
(0, import_invariant2.invariant)(!this._client, "Client already created", {
|
|
889
883
|
F: __dxlog_file3,
|
|
890
884
|
L: 260,
|
|
891
885
|
S: this,
|
|
@@ -897,7 +891,7 @@ var SignalClient = class {
|
|
|
897
891
|
this._connectionStarted = /* @__PURE__ */ new Date();
|
|
898
892
|
this._connectionCtx = this._ctx.derive();
|
|
899
893
|
this._connectionCtx.onDispose(async () => {
|
|
900
|
-
(0,
|
|
894
|
+
(0, import_log2.log)("connection context disposed", void 0, {
|
|
901
895
|
F: __dxlog_file3,
|
|
902
896
|
L: 267,
|
|
903
897
|
S: this,
|
|
@@ -913,7 +907,7 @@ var SignalClient = class {
|
|
|
913
907
|
url: this._host,
|
|
914
908
|
callbacks: {
|
|
915
909
|
onConnected: () => {
|
|
916
|
-
(0,
|
|
910
|
+
(0, import_log2.log)("socket connected", void 0, {
|
|
917
911
|
F: __dxlog_file3,
|
|
918
912
|
L: 279,
|
|
919
913
|
S: this,
|
|
@@ -926,7 +920,7 @@ var SignalClient = class {
|
|
|
926
920
|
this._reconcileTask.schedule();
|
|
927
921
|
},
|
|
928
922
|
onDisconnected: () => {
|
|
929
|
-
(0,
|
|
923
|
+
(0, import_log2.log)("socket disconnected", {
|
|
930
924
|
state: this._state
|
|
931
925
|
}, {
|
|
932
926
|
F: __dxlog_file3,
|
|
@@ -945,7 +939,7 @@ var SignalClient = class {
|
|
|
945
939
|
this._reconnectTask.schedule();
|
|
946
940
|
},
|
|
947
941
|
onError: (error) => {
|
|
948
|
-
(0,
|
|
942
|
+
(0, import_log2.log)("socket error", {
|
|
949
943
|
error,
|
|
950
944
|
state: this._state
|
|
951
945
|
}, {
|
|
@@ -977,7 +971,7 @@ var SignalClient = class {
|
|
|
977
971
|
this._reconnectAfter = Math.min(this._reconnectAfter, MAX_RECONNECT_TIMEOUT);
|
|
978
972
|
}
|
|
979
973
|
async _reconnect() {
|
|
980
|
-
(0,
|
|
974
|
+
(0, import_log2.log)(`reconnecting in ${this._reconnectAfter}ms`, {
|
|
981
975
|
state: this._state
|
|
982
976
|
}, {
|
|
983
977
|
F: __dxlog_file3,
|
|
@@ -987,7 +981,7 @@ var SignalClient = class {
|
|
|
987
981
|
});
|
|
988
982
|
this._performance.reconnectCounter++;
|
|
989
983
|
if (this._state === import_signal.SignalState.RECONNECTING) {
|
|
990
|
-
|
|
984
|
+
import_log2.log.warn("Signal api already reconnecting.", void 0, {
|
|
991
985
|
F: __dxlog_file3,
|
|
992
986
|
L: 334,
|
|
993
987
|
S: this,
|
|
@@ -1003,14 +997,14 @@ var SignalClient = class {
|
|
|
1003
997
|
this._client?.close().catch(() => {
|
|
1004
998
|
});
|
|
1005
999
|
this._client = void 0;
|
|
1006
|
-
await (0, import_context2.cancelWithContext)(this._ctx, (0,
|
|
1000
|
+
await (0, import_context2.cancelWithContext)(this._ctx, (0, import_async2.sleep)(this._reconnectAfter));
|
|
1007
1001
|
this._setState(import_signal.SignalState.RECONNECTING);
|
|
1008
1002
|
this._createClient();
|
|
1009
1003
|
}
|
|
1010
1004
|
async _reconcileSwarmSubscriptions() {
|
|
1011
|
-
await (0,
|
|
1005
|
+
await (0, import_async2.asyncTimeout)((0, import_context2.cancelWithContext)(this._connectionCtx, this._clientReady.wait()), 5e3);
|
|
1012
1006
|
const client = this._client;
|
|
1013
|
-
(0,
|
|
1007
|
+
(0, import_invariant2.invariant)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server", {
|
|
1014
1008
|
F: __dxlog_file3,
|
|
1015
1009
|
L: 359,
|
|
1016
1010
|
S: this,
|
|
@@ -1042,12 +1036,12 @@ var SignalClient = class {
|
|
|
1042
1036
|
})) {
|
|
1043
1037
|
continue;
|
|
1044
1038
|
}
|
|
1045
|
-
const swarmStream = await (0,
|
|
1039
|
+
const swarmStream = await (0, import_async2.asyncTimeout)((0, import_context2.cancelWithContext)(this._connectionCtx, client.join({
|
|
1046
1040
|
topic,
|
|
1047
1041
|
peerId
|
|
1048
1042
|
})), 5e3);
|
|
1049
1043
|
swarmStream.subscribe(async (swarmEvent) => {
|
|
1050
|
-
(0,
|
|
1044
|
+
(0, import_log2.log)("swarm event", {
|
|
1051
1045
|
swarmEvent
|
|
1052
1046
|
}, {
|
|
1053
1047
|
F: __dxlog_file3,
|
|
@@ -1067,9 +1061,9 @@ var SignalClient = class {
|
|
|
1067
1061
|
}
|
|
1068
1062
|
}
|
|
1069
1063
|
async _reconcileMessageSubscriptions() {
|
|
1070
|
-
await (0,
|
|
1064
|
+
await (0, import_async2.asyncTimeout)((0, import_context2.cancelWithContext)(this._connectionCtx, this._clientReady.wait()), 5e3);
|
|
1071
1065
|
const client = this._client;
|
|
1072
|
-
(0,
|
|
1066
|
+
(0, import_invariant2.invariant)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server", {
|
|
1073
1067
|
F: __dxlog_file3,
|
|
1074
1068
|
L: 399,
|
|
1075
1069
|
S: this,
|
|
@@ -1091,12 +1085,12 @@ var SignalClient = class {
|
|
|
1091
1085
|
if (this._messageStreams.has(peerId)) {
|
|
1092
1086
|
continue;
|
|
1093
1087
|
}
|
|
1094
|
-
const messageStream = await (0,
|
|
1088
|
+
const messageStream = await (0, import_async2.asyncTimeout)((0, import_context2.cancelWithContext)(this._connectionCtx, client.receiveMessages(peerId)), 5e3);
|
|
1095
1089
|
messageStream.subscribe(async (message) => {
|
|
1096
1090
|
this._performance.receivedMessages++;
|
|
1097
1091
|
await this._onMessage({
|
|
1098
|
-
author:
|
|
1099
|
-
recipient:
|
|
1092
|
+
author: import_keys2.PublicKey.from(message.author),
|
|
1093
|
+
recipient: import_keys2.PublicKey.from(message.recipient),
|
|
1100
1094
|
payload: message.payload
|
|
1101
1095
|
});
|
|
1102
1096
|
});
|
|
@@ -1104,23 +1098,11 @@ var SignalClient = class {
|
|
|
1104
1098
|
}
|
|
1105
1099
|
}
|
|
1106
1100
|
};
|
|
1107
|
-
|
|
1108
|
-
// packages/core/mesh/messaging/src/signal-manager/memory-signal-manager.ts
|
|
1109
|
-
var import_async4 = require("@dxos/async");
|
|
1110
|
-
var import_context3 = require("@dxos/context");
|
|
1111
|
-
var import_invariant4 = require("@dxos/invariant");
|
|
1112
|
-
var import_keys4 = require("@dxos/keys");
|
|
1113
|
-
var import_log4 = require("@dxos/log");
|
|
1114
|
-
var import_protocols4 = require("@dxos/protocols");
|
|
1115
|
-
var import_util3 = require("@dxos/util");
|
|
1116
1101
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-manager/memory-signal-manager.ts";
|
|
1117
1102
|
var MemorySignalManagerContext = class {
|
|
1118
1103
|
constructor() {
|
|
1119
|
-
// Swarm messages.
|
|
1120
1104
|
this.swarmEvent = new import_async4.Event();
|
|
1121
|
-
// Mapping from topic to set of peers.
|
|
1122
1105
|
this.swarms = new import_util3.ComplexMap(import_keys4.PublicKey.hash);
|
|
1123
|
-
// Map of connections for each peer for signaling.
|
|
1124
1106
|
this.connections = new import_util3.ComplexMap(import_keys4.PublicKey.hash);
|
|
1125
1107
|
}
|
|
1126
1108
|
};
|
|
@@ -1367,14 +1349,6 @@ var dec = (payload) => {
|
|
|
1367
1349
|
}
|
|
1368
1350
|
return {};
|
|
1369
1351
|
};
|
|
1370
|
-
|
|
1371
|
-
// packages/core/mesh/messaging/src/signal-manager/websocket-signal-manager.ts
|
|
1372
|
-
var import_async5 = require("@dxos/async");
|
|
1373
|
-
var import_context4 = require("@dxos/context");
|
|
1374
|
-
var import_invariant5 = require("@dxos/invariant");
|
|
1375
|
-
var import_keys5 = require("@dxos/keys");
|
|
1376
|
-
var import_log5 = require("@dxos/log");
|
|
1377
|
-
var import_protocols5 = require("@dxos/protocols");
|
|
1378
1352
|
function _ts_decorate(decorators, target, key, desc) {
|
|
1379
1353
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1380
1354
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1566,7 +1540,7 @@ var WebsocketSignalManager = class {
|
|
|
1566
1540
|
payload
|
|
1567
1541
|
}).catch((err) => {
|
|
1568
1542
|
if (err instanceof import_protocols5.RateLimitExceededError) {
|
|
1569
|
-
|
|
1543
|
+
import_log5.log.info("WSS rate limit exceeded", {
|
|
1570
1544
|
err
|
|
1571
1545
|
}, {
|
|
1572
1546
|
F: __dxlog_file5,
|
|
@@ -1574,8 +1548,8 @@ var WebsocketSignalManager = class {
|
|
|
1574
1548
|
S: this,
|
|
1575
1549
|
C: (f, a) => f(...a)
|
|
1576
1550
|
});
|
|
1577
|
-
} else {
|
|
1578
|
-
|
|
1551
|
+
} else if (err instanceof import_protocols5.TimeoutError || err.constructor.name === "TimeoutError") {
|
|
1552
|
+
import_log5.log.info("WSS sendMessage timeout", {
|
|
1579
1553
|
err
|
|
1580
1554
|
}, {
|
|
1581
1555
|
F: __dxlog_file5,
|
|
@@ -1584,6 +1558,16 @@ var WebsocketSignalManager = class {
|
|
|
1584
1558
|
C: (f, a) => f(...a)
|
|
1585
1559
|
});
|
|
1586
1560
|
void this.checkServerFailure(serverName);
|
|
1561
|
+
} else {
|
|
1562
|
+
import_log5.log.info(`error sending to ${serverName}`, {
|
|
1563
|
+
err
|
|
1564
|
+
}, {
|
|
1565
|
+
F: __dxlog_file5,
|
|
1566
|
+
L: 143,
|
|
1567
|
+
S: this,
|
|
1568
|
+
C: (f, a) => f(...a)
|
|
1569
|
+
});
|
|
1570
|
+
void this.checkServerFailure(serverName);
|
|
1587
1571
|
}
|
|
1588
1572
|
});
|
|
1589
1573
|
});
|
|
@@ -1593,7 +1577,7 @@ var WebsocketSignalManager = class {
|
|
|
1593
1577
|
if (failureCount > MAX_SERVER_FAILURES) {
|
|
1594
1578
|
import_log5.log.warn(`Too many failures sending to ${serverName} (${failureCount} > ${MAX_SERVER_FAILURES}), restarting`, void 0, {
|
|
1595
1579
|
F: __dxlog_file5,
|
|
1596
|
-
L:
|
|
1580
|
+
L: 154,
|
|
1597
1581
|
S: this,
|
|
1598
1582
|
C: (f, a) => f(...a)
|
|
1599
1583
|
});
|
|
@@ -1606,13 +1590,13 @@ var WebsocketSignalManager = class {
|
|
|
1606
1590
|
async subscribeMessages(peerId) {
|
|
1607
1591
|
(0, import_log5.log)(`Subscribed for message stream peerId=${peerId}`, void 0, {
|
|
1608
1592
|
F: __dxlog_file5,
|
|
1609
|
-
L:
|
|
1593
|
+
L: 163,
|
|
1610
1594
|
S: this,
|
|
1611
1595
|
C: (f, a) => f(...a)
|
|
1612
1596
|
});
|
|
1613
1597
|
(0, import_invariant5.invariant)(this._opened, "Closed", {
|
|
1614
1598
|
F: __dxlog_file5,
|
|
1615
|
-
L:
|
|
1599
|
+
L: 164,
|
|
1616
1600
|
S: this,
|
|
1617
1601
|
A: [
|
|
1618
1602
|
"this._opened",
|
|
@@ -1624,13 +1608,13 @@ var WebsocketSignalManager = class {
|
|
|
1624
1608
|
async unsubscribeMessages(peerId) {
|
|
1625
1609
|
(0, import_log5.log)(`Subscribed for message stream peerId=${peerId}`, void 0, {
|
|
1626
1610
|
F: __dxlog_file5,
|
|
1627
|
-
L:
|
|
1611
|
+
L: 170,
|
|
1628
1612
|
S: this,
|
|
1629
1613
|
C: (f, a) => f(...a)
|
|
1630
1614
|
});
|
|
1631
1615
|
(0, import_invariant5.invariant)(this._opened, "Closed", {
|
|
1632
1616
|
F: __dxlog_file5,
|
|
1633
|
-
L:
|
|
1617
|
+
L: 171,
|
|
1634
1618
|
S: this,
|
|
1635
1619
|
A: [
|
|
1636
1620
|
"this._opened",
|
|
@@ -1643,7 +1627,7 @@ var WebsocketSignalManager = class {
|
|
|
1643
1627
|
this._ctx = new import_context4.Context({
|
|
1644
1628
|
onError: (err) => import_log5.log.catch(err, void 0, {
|
|
1645
1629
|
F: __dxlog_file5,
|
|
1646
|
-
L:
|
|
1630
|
+
L: 178,
|
|
1647
1631
|
S: this,
|
|
1648
1632
|
C: (f, a) => f(...a)
|
|
1649
1633
|
})
|