@dxos/messaging 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/index.mjs +38 -52
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +38 -52
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/messenger.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/messenger.test.ts +2 -3
- package/src/messenger.ts +0 -1
- package/src/signal-client/signal-client.ts +3 -3
package/dist/lib/node/index.cjs
CHANGED
|
@@ -210,7 +210,7 @@ var Messenger = class {
|
|
|
210
210
|
async listen({ peerId, payloadType, onMessage }) {
|
|
211
211
|
(0, import_invariant.invariant)(!this._closed, "Closed", {
|
|
212
212
|
F: __dxlog_file,
|
|
213
|
-
L:
|
|
213
|
+
L: 149,
|
|
214
214
|
S: this,
|
|
215
215
|
A: [
|
|
216
216
|
"!this._closed",
|
|
@@ -274,7 +274,7 @@ var Messenger = class {
|
|
|
274
274
|
async _handleReliablePayload({ author, recipient, payload }) {
|
|
275
275
|
(0, import_invariant.invariant)(payload.type_url === "dxos.mesh.messaging.ReliablePayload", void 0, {
|
|
276
276
|
F: __dxlog_file,
|
|
277
|
-
L:
|
|
277
|
+
L: 210,
|
|
278
278
|
S: this,
|
|
279
279
|
A: [
|
|
280
280
|
"payload.type_url === 'dxos.mesh.messaging.ReliablePayload'",
|
|
@@ -288,7 +288,7 @@ var Messenger = class {
|
|
|
288
288
|
messageId: reliablePayload.messageId
|
|
289
289
|
}, {
|
|
290
290
|
F: __dxlog_file,
|
|
291
|
-
L:
|
|
291
|
+
L: 213,
|
|
292
292
|
S: this,
|
|
293
293
|
C: (f, a) => f(...a)
|
|
294
294
|
});
|
|
@@ -308,17 +308,16 @@ var Messenger = class {
|
|
|
308
308
|
});
|
|
309
309
|
}
|
|
310
310
|
async _handleAcknowledgement({ payload }) {
|
|
311
|
-
var _a;
|
|
312
311
|
(0, import_invariant.invariant)(payload.type_url === "dxos.mesh.messaging.Acknowledgement", void 0, {
|
|
313
312
|
F: __dxlog_file,
|
|
314
|
-
L:
|
|
313
|
+
L: 235,
|
|
315
314
|
S: this,
|
|
316
315
|
A: [
|
|
317
316
|
"payload.type_url === 'dxos.mesh.messaging.Acknowledgement'",
|
|
318
317
|
""
|
|
319
318
|
]
|
|
320
319
|
});
|
|
321
|
-
|
|
320
|
+
this._onAckCallbacks.get(Acknowledgement.decode(payload.value).messageId)?.();
|
|
322
321
|
}
|
|
323
322
|
async _sendAcknowledgement({ author, recipient, messageId }) {
|
|
324
323
|
(0, import_log.log)("sending ACK", {
|
|
@@ -327,7 +326,7 @@ var Messenger = class {
|
|
|
327
326
|
to: author
|
|
328
327
|
}, {
|
|
329
328
|
F: __dxlog_file,
|
|
330
|
-
L:
|
|
329
|
+
L: 248,
|
|
331
330
|
S: this,
|
|
332
331
|
C: (f, a) => f(...a)
|
|
333
332
|
});
|
|
@@ -436,7 +435,6 @@ var SignalRPCClient = class {
|
|
|
436
435
|
}
|
|
437
436
|
});
|
|
438
437
|
this._socket.onopen = async () => {
|
|
439
|
-
var _a, _b, _c, _d;
|
|
440
438
|
try {
|
|
441
439
|
await this._rpc.open();
|
|
442
440
|
(0, import_log2.log)(`RPC open ${this._url}`, void 0, {
|
|
@@ -445,32 +443,30 @@ var SignalRPCClient = class {
|
|
|
445
443
|
S: this,
|
|
446
444
|
C: (f, a) => f(...a)
|
|
447
445
|
});
|
|
448
|
-
|
|
446
|
+
this._callbacks.onConnected?.();
|
|
449
447
|
this._connectTrigger.wake();
|
|
450
448
|
} catch (err) {
|
|
451
|
-
|
|
449
|
+
this._callbacks.onError?.(err);
|
|
452
450
|
}
|
|
453
451
|
};
|
|
454
452
|
this._socket.onclose = async () => {
|
|
455
|
-
var _a, _b;
|
|
456
453
|
(0, import_log2.log)(`Disconnected ${this._url}`, void 0, {
|
|
457
454
|
F: __dxlog_file2,
|
|
458
455
|
L: 98,
|
|
459
456
|
S: this,
|
|
460
457
|
C: (f, a) => f(...a)
|
|
461
458
|
});
|
|
462
|
-
|
|
459
|
+
this._callbacks.onDisconnected?.();
|
|
463
460
|
await this.close();
|
|
464
461
|
};
|
|
465
462
|
this._socket.onerror = async (event) => {
|
|
466
|
-
var _a, _b, _c, _d, _e;
|
|
467
463
|
if (this._closed) {
|
|
468
464
|
return;
|
|
469
465
|
}
|
|
470
|
-
|
|
466
|
+
this._callbacks.onError?.(event.error ?? new Error(event.message));
|
|
471
467
|
this._connectTrigger.reset();
|
|
472
468
|
try {
|
|
473
|
-
await
|
|
469
|
+
await this._rpc?.close();
|
|
474
470
|
} catch (err) {
|
|
475
471
|
import_log2.log.catch(err, void 0, {
|
|
476
472
|
F: __dxlog_file2,
|
|
@@ -480,7 +476,7 @@ var SignalRPCClient = class {
|
|
|
480
476
|
});
|
|
481
477
|
}
|
|
482
478
|
this._closed = true;
|
|
483
|
-
import_log2.log.warn(
|
|
479
|
+
import_log2.log.warn(event.message ?? "Socket error", {
|
|
484
480
|
url: this._url
|
|
485
481
|
}, {
|
|
486
482
|
F: __dxlog_file2,
|
|
@@ -499,11 +495,10 @@ var SignalRPCClient = class {
|
|
|
499
495
|
});
|
|
500
496
|
}
|
|
501
497
|
async close() {
|
|
502
|
-
var _a, _b;
|
|
503
498
|
this._closed = true;
|
|
504
499
|
try {
|
|
505
|
-
await
|
|
506
|
-
|
|
500
|
+
await this._rpc?.close();
|
|
501
|
+
this._socket?.close();
|
|
507
502
|
} catch (err) {
|
|
508
503
|
import_log2.log.warn("close error", err, {
|
|
509
504
|
F: __dxlog_file2,
|
|
@@ -638,8 +633,8 @@ var SignalClient = class {
|
|
|
638
633
|
this._onSwarmEvent = _onSwarmEvent;
|
|
639
634
|
this._state = import_signal.SignalState.CLOSED;
|
|
640
635
|
this._reconnectAfter = DEFAULT_RECONNECT_TIMEOUT;
|
|
641
|
-
this._connectionStarted = new Date();
|
|
642
|
-
this._lastStateChange = new Date();
|
|
636
|
+
this._connectionStarted = /* @__PURE__ */ new Date();
|
|
637
|
+
this._lastStateChange = /* @__PURE__ */ new Date();
|
|
643
638
|
this._clientReady = new import_async3.Trigger();
|
|
644
639
|
this.statusChanged = new import_async3.Event();
|
|
645
640
|
this.commandTrace = new import_async3.Event();
|
|
@@ -677,8 +672,7 @@ var SignalClient = class {
|
|
|
677
672
|
}
|
|
678
673
|
this._ctx = new import_context2.Context({
|
|
679
674
|
onError: (err) => {
|
|
680
|
-
|
|
681
|
-
if (this._state === import_signal.SignalState.CLOSED || ((_a = this._ctx) == null ? void 0 : _a.disposed)) {
|
|
675
|
+
if (this._state === import_signal.SignalState.CLOSED || this._ctx?.disposed) {
|
|
682
676
|
return;
|
|
683
677
|
}
|
|
684
678
|
if (this._state === import_signal.SignalState.CONNECTED) {
|
|
@@ -717,7 +711,6 @@ var SignalClient = class {
|
|
|
717
711
|
});
|
|
718
712
|
}
|
|
719
713
|
async close() {
|
|
720
|
-
var _a, _b;
|
|
721
714
|
(0, import_log3.log)("closing...", void 0, {
|
|
722
715
|
F: __dxlog_file3,
|
|
723
716
|
L: 180,
|
|
@@ -729,9 +722,9 @@ var SignalClient = class {
|
|
|
729
722
|
].includes(this._state)) {
|
|
730
723
|
return;
|
|
731
724
|
}
|
|
732
|
-
await
|
|
725
|
+
await this._ctx?.dispose();
|
|
733
726
|
this._clientReady.reset();
|
|
734
|
-
await
|
|
727
|
+
await this._client?.close();
|
|
735
728
|
this._client = void 0;
|
|
736
729
|
this._setState(import_signal.SignalState.CLOSED);
|
|
737
730
|
(0, import_log3.log)("closed", void 0, {
|
|
@@ -742,11 +735,10 @@ var SignalClient = class {
|
|
|
742
735
|
});
|
|
743
736
|
}
|
|
744
737
|
getStatus() {
|
|
745
|
-
var _a;
|
|
746
738
|
return {
|
|
747
739
|
host: this._host,
|
|
748
740
|
state: this._state,
|
|
749
|
-
error:
|
|
741
|
+
error: this._lastError?.message,
|
|
750
742
|
reconnectIn: this._reconnectAfter,
|
|
751
743
|
connectionStarted: this._connectionStarted,
|
|
752
744
|
lastStateChange: this._lastStateChange
|
|
@@ -770,7 +762,6 @@ var SignalClient = class {
|
|
|
770
762
|
this._reconcileTask.schedule();
|
|
771
763
|
}
|
|
772
764
|
async leave({ topic, peerId }) {
|
|
773
|
-
var _a;
|
|
774
765
|
this._performance.leaveCounter++;
|
|
775
766
|
(0, import_log3.log)("leaving", {
|
|
776
767
|
topic,
|
|
@@ -781,10 +772,10 @@ var SignalClient = class {
|
|
|
781
772
|
S: this,
|
|
782
773
|
C: (f, a) => f(...a)
|
|
783
774
|
});
|
|
784
|
-
|
|
775
|
+
this._swarmStreams.get({
|
|
785
776
|
topic,
|
|
786
777
|
peerId
|
|
787
|
-
})
|
|
778
|
+
})?.close();
|
|
788
779
|
this._swarmStreams.delete({
|
|
789
780
|
topic,
|
|
790
781
|
peerId
|
|
@@ -823,7 +814,6 @@ var SignalClient = class {
|
|
|
823
814
|
this._reconcileTask.schedule();
|
|
824
815
|
}
|
|
825
816
|
async unsubscribeMessages(peerId) {
|
|
826
|
-
var _a;
|
|
827
817
|
(0, import_log3.log)("unsubscribing from messages", {
|
|
828
818
|
peerId
|
|
829
819
|
}, {
|
|
@@ -835,7 +825,7 @@ var SignalClient = class {
|
|
|
835
825
|
this._subscribedMessages.delete({
|
|
836
826
|
peerId
|
|
837
827
|
});
|
|
838
|
-
|
|
828
|
+
this._messageStreams.get(peerId)?.close();
|
|
839
829
|
this._messageStreams.delete(peerId);
|
|
840
830
|
}
|
|
841
831
|
_scheduleReconcileAfterError() {
|
|
@@ -845,7 +835,7 @@ var SignalClient = class {
|
|
|
845
835
|
}
|
|
846
836
|
_setState(newState) {
|
|
847
837
|
this._state = newState;
|
|
848
|
-
this._lastStateChange = new Date();
|
|
838
|
+
this._lastStateChange = /* @__PURE__ */ new Date();
|
|
849
839
|
(0, import_log3.log)("signal state changed", {
|
|
850
840
|
status: this.getStatus()
|
|
851
841
|
}, {
|
|
@@ -875,17 +865,17 @@ var SignalClient = class {
|
|
|
875
865
|
"'Client already created'"
|
|
876
866
|
]
|
|
877
867
|
});
|
|
878
|
-
this._connectionStarted = new Date();
|
|
868
|
+
this._connectionStarted = /* @__PURE__ */ new Date();
|
|
879
869
|
this._connectionCtx = this._ctx.derive();
|
|
880
|
-
this._connectionCtx.onDispose(() => {
|
|
870
|
+
this._connectionCtx.onDispose(async () => {
|
|
881
871
|
(0, import_log3.log)("connection context disposed", void 0, {
|
|
882
872
|
F: __dxlog_file3,
|
|
883
873
|
L: 267,
|
|
884
874
|
S: this,
|
|
885
875
|
C: (f, a) => f(...a)
|
|
886
876
|
});
|
|
887
|
-
Array.from(this._swarmStreams.values()).
|
|
888
|
-
Array.from(this._messageStreams.values()).
|
|
877
|
+
await Promise.all(Array.from(this._swarmStreams.values()).map((stream) => stream.close()));
|
|
878
|
+
await Promise.all(Array.from(this._messageStreams.values()).map((stream) => stream.close()));
|
|
889
879
|
this._swarmStreams.clear();
|
|
890
880
|
this._messageStreams.clear();
|
|
891
881
|
});
|
|
@@ -958,7 +948,6 @@ var SignalClient = class {
|
|
|
958
948
|
this._reconnectAfter = Math.min(this._reconnectAfter, MAX_RECONNECT_TIMEOUT);
|
|
959
949
|
}
|
|
960
950
|
async _reconnect() {
|
|
961
|
-
var _a, _b;
|
|
962
951
|
(0, import_log3.log)(`reconnecting in ${this._reconnectAfter}ms`, {
|
|
963
952
|
state: this._state
|
|
964
953
|
}, {
|
|
@@ -981,8 +970,8 @@ var SignalClient = class {
|
|
|
981
970
|
return;
|
|
982
971
|
}
|
|
983
972
|
this._clientReady.reset();
|
|
984
|
-
await
|
|
985
|
-
|
|
973
|
+
await this._connectionCtx?.dispose();
|
|
974
|
+
this._client?.close().catch(() => {
|
|
986
975
|
});
|
|
987
976
|
this._client = void 0;
|
|
988
977
|
await (0, import_context2.cancelWithContext)(this._ctx, (0, import_async3.sleep)(this._reconnectAfter));
|
|
@@ -990,7 +979,6 @@ var SignalClient = class {
|
|
|
990
979
|
this._createClient();
|
|
991
980
|
}
|
|
992
981
|
async _reconcileSwarmSubscriptions() {
|
|
993
|
-
var _a;
|
|
994
982
|
await (0, import_async3.asyncTimeout)((0, import_context2.cancelWithContext)(this._connectionCtx, this._clientReady.wait()), 5e3);
|
|
995
983
|
const client = this._client;
|
|
996
984
|
(0, import_invariant3.invariant)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server", {
|
|
@@ -1009,10 +997,10 @@ var SignalClient = class {
|
|
|
1009
997
|
})) {
|
|
1010
998
|
continue;
|
|
1011
999
|
}
|
|
1012
|
-
|
|
1000
|
+
this._swarmStreams.get({
|
|
1013
1001
|
topic,
|
|
1014
1002
|
peerId
|
|
1015
|
-
})
|
|
1003
|
+
})?.close();
|
|
1016
1004
|
this._swarmStreams.delete({
|
|
1017
1005
|
topic,
|
|
1018
1006
|
peerId
|
|
@@ -1050,7 +1038,6 @@ var SignalClient = class {
|
|
|
1050
1038
|
}
|
|
1051
1039
|
}
|
|
1052
1040
|
async _reconcileMessageSubscriptions() {
|
|
1053
|
-
var _a;
|
|
1054
1041
|
await (0, import_async3.asyncTimeout)((0, import_context2.cancelWithContext)(this._connectionCtx, this._clientReady.wait()), 5e3);
|
|
1055
1042
|
const client = this._client;
|
|
1056
1043
|
(0, import_invariant3.invariant)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server", {
|
|
@@ -1068,7 +1055,7 @@ var SignalClient = class {
|
|
|
1068
1055
|
})) {
|
|
1069
1056
|
continue;
|
|
1070
1057
|
}
|
|
1071
|
-
|
|
1058
|
+
this._messageStreams.get(peerId)?.close();
|
|
1072
1059
|
this._messageStreams.delete(peerId);
|
|
1073
1060
|
}
|
|
1074
1061
|
for (const { peerId } of this._subscribedMessages.values()) {
|
|
@@ -1170,7 +1157,7 @@ var MemorySignalManager = class {
|
|
|
1170
1157
|
swarmEvent: {
|
|
1171
1158
|
peerAvailable: {
|
|
1172
1159
|
peer: peerId.asUint8Array(),
|
|
1173
|
-
since: new Date()
|
|
1160
|
+
since: /* @__PURE__ */ new Date()
|
|
1174
1161
|
}
|
|
1175
1162
|
}
|
|
1176
1163
|
});
|
|
@@ -1181,7 +1168,7 @@ var MemorySignalManager = class {
|
|
|
1181
1168
|
swarmEvent: {
|
|
1182
1169
|
peerAvailable: {
|
|
1183
1170
|
peer: peerId2.asUint8Array(),
|
|
1184
|
-
since: new Date()
|
|
1171
|
+
since: /* @__PURE__ */ new Date()
|
|
1185
1172
|
}
|
|
1186
1173
|
}
|
|
1187
1174
|
});
|
|
@@ -1340,15 +1327,14 @@ var MemorySignalManager = class {
|
|
|
1340
1327
|
}
|
|
1341
1328
|
};
|
|
1342
1329
|
var dec = (payload) => {
|
|
1343
|
-
var _a, _b, _c;
|
|
1344
1330
|
if (!payload.type_url.endsWith("ReliablePayload")) {
|
|
1345
1331
|
return {};
|
|
1346
1332
|
}
|
|
1347
1333
|
const relPayload = import_protocols4.schema.getCodecForType("dxos.mesh.messaging.ReliablePayload").decode(payload.value);
|
|
1348
|
-
if (typeof
|
|
1334
|
+
if (typeof relPayload?.payload?.data === "object") {
|
|
1349
1335
|
return {
|
|
1350
|
-
payload: Object.keys(
|
|
1351
|
-
sessionId:
|
|
1336
|
+
payload: Object.keys(relPayload?.payload?.data)[0],
|
|
1337
|
+
sessionId: relPayload?.payload?.sessionId
|
|
1352
1338
|
};
|
|
1353
1339
|
}
|
|
1354
1340
|
return {};
|