@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.
@@ -172,7 +172,7 @@ var Messenger = class {
172
172
  async listen({ peerId, payloadType, onMessage }) {
173
173
  invariant(!this._closed, "Closed", {
174
174
  F: __dxlog_file,
175
- L: 150,
175
+ L: 149,
176
176
  S: this,
177
177
  A: [
178
178
  "!this._closed",
@@ -236,7 +236,7 @@ var Messenger = class {
236
236
  async _handleReliablePayload({ author, recipient, payload }) {
237
237
  invariant(payload.type_url === "dxos.mesh.messaging.ReliablePayload", void 0, {
238
238
  F: __dxlog_file,
239
- L: 211,
239
+ L: 210,
240
240
  S: this,
241
241
  A: [
242
242
  "payload.type_url === 'dxos.mesh.messaging.ReliablePayload'",
@@ -250,7 +250,7 @@ var Messenger = class {
250
250
  messageId: reliablePayload.messageId
251
251
  }, {
252
252
  F: __dxlog_file,
253
- L: 214,
253
+ L: 213,
254
254
  S: this,
255
255
  C: (f, a) => f(...a)
256
256
  });
@@ -270,17 +270,16 @@ var Messenger = class {
270
270
  });
271
271
  }
272
272
  async _handleAcknowledgement({ payload }) {
273
- var _a;
274
273
  invariant(payload.type_url === "dxos.mesh.messaging.Acknowledgement", void 0, {
275
274
  F: __dxlog_file,
276
- L: 236,
275
+ L: 235,
277
276
  S: this,
278
277
  A: [
279
278
  "payload.type_url === 'dxos.mesh.messaging.Acknowledgement'",
280
279
  ""
281
280
  ]
282
281
  });
283
- (_a = this._onAckCallbacks.get(Acknowledgement.decode(payload.value).messageId)) == null ? void 0 : _a();
282
+ this._onAckCallbacks.get(Acknowledgement.decode(payload.value).messageId)?.();
284
283
  }
285
284
  async _sendAcknowledgement({ author, recipient, messageId }) {
286
285
  log("sending ACK", {
@@ -289,7 +288,7 @@ var Messenger = class {
289
288
  to: author
290
289
  }, {
291
290
  F: __dxlog_file,
292
- L: 249,
291
+ L: 248,
293
292
  S: this,
294
293
  C: (f, a) => f(...a)
295
294
  });
@@ -398,7 +397,6 @@ var SignalRPCClient = class {
398
397
  }
399
398
  });
400
399
  this._socket.onopen = async () => {
401
- var _a, _b, _c, _d;
402
400
  try {
403
401
  await this._rpc.open();
404
402
  log2(`RPC open ${this._url}`, void 0, {
@@ -407,32 +405,30 @@ var SignalRPCClient = class {
407
405
  S: this,
408
406
  C: (f, a) => f(...a)
409
407
  });
410
- (_b = (_a = this._callbacks).onConnected) == null ? void 0 : _b.call(_a);
408
+ this._callbacks.onConnected?.();
411
409
  this._connectTrigger.wake();
412
410
  } catch (err) {
413
- (_d = (_c = this._callbacks).onError) == null ? void 0 : _d.call(_c, err);
411
+ this._callbacks.onError?.(err);
414
412
  }
415
413
  };
416
414
  this._socket.onclose = async () => {
417
- var _a, _b;
418
415
  log2(`Disconnected ${this._url}`, void 0, {
419
416
  F: __dxlog_file2,
420
417
  L: 98,
421
418
  S: this,
422
419
  C: (f, a) => f(...a)
423
420
  });
424
- (_b = (_a = this._callbacks).onDisconnected) == null ? void 0 : _b.call(_a);
421
+ this._callbacks.onDisconnected?.();
425
422
  await this.close();
426
423
  };
427
424
  this._socket.onerror = async (event) => {
428
- var _a, _b, _c, _d, _e;
429
425
  if (this._closed) {
430
426
  return;
431
427
  }
432
- (_c = (_b = this._callbacks).onError) == null ? void 0 : _c.call(_b, (_a = event.error) != null ? _a : new Error(event.message));
428
+ this._callbacks.onError?.(event.error ?? new Error(event.message));
433
429
  this._connectTrigger.reset();
434
430
  try {
435
- await ((_d = this._rpc) == null ? void 0 : _d.close());
431
+ await this._rpc?.close();
436
432
  } catch (err) {
437
433
  log2.catch(err, void 0, {
438
434
  F: __dxlog_file2,
@@ -442,7 +438,7 @@ var SignalRPCClient = class {
442
438
  });
443
439
  }
444
440
  this._closed = true;
445
- log2.warn((_e = event.message) != null ? _e : "Socket error", {
441
+ log2.warn(event.message ?? "Socket error", {
446
442
  url: this._url
447
443
  }, {
448
444
  F: __dxlog_file2,
@@ -461,11 +457,10 @@ var SignalRPCClient = class {
461
457
  });
462
458
  }
463
459
  async close() {
464
- var _a, _b;
465
460
  this._closed = true;
466
461
  try {
467
- await ((_a = this._rpc) == null ? void 0 : _a.close());
468
- (_b = this._socket) == null ? void 0 : _b.close();
462
+ await this._rpc?.close();
463
+ this._socket?.close();
469
464
  } catch (err) {
470
465
  log2.warn("close error", err, {
471
466
  F: __dxlog_file2,
@@ -600,8 +595,8 @@ var SignalClient = class {
600
595
  this._onSwarmEvent = _onSwarmEvent;
601
596
  this._state = SignalState.CLOSED;
602
597
  this._reconnectAfter = DEFAULT_RECONNECT_TIMEOUT;
603
- this._connectionStarted = new Date();
604
- this._lastStateChange = new Date();
598
+ this._connectionStarted = /* @__PURE__ */ new Date();
599
+ this._lastStateChange = /* @__PURE__ */ new Date();
605
600
  this._clientReady = new Trigger2();
606
601
  this.statusChanged = new Event();
607
602
  this.commandTrace = new Event();
@@ -639,8 +634,7 @@ var SignalClient = class {
639
634
  }
640
635
  this._ctx = new Context2({
641
636
  onError: (err) => {
642
- var _a;
643
- if (this._state === SignalState.CLOSED || ((_a = this._ctx) == null ? void 0 : _a.disposed)) {
637
+ if (this._state === SignalState.CLOSED || this._ctx?.disposed) {
644
638
  return;
645
639
  }
646
640
  if (this._state === SignalState.CONNECTED) {
@@ -679,7 +673,6 @@ var SignalClient = class {
679
673
  });
680
674
  }
681
675
  async close() {
682
- var _a, _b;
683
676
  log3("closing...", void 0, {
684
677
  F: __dxlog_file3,
685
678
  L: 180,
@@ -691,9 +684,9 @@ var SignalClient = class {
691
684
  ].includes(this._state)) {
692
685
  return;
693
686
  }
694
- await ((_a = this._ctx) == null ? void 0 : _a.dispose());
687
+ await this._ctx?.dispose();
695
688
  this._clientReady.reset();
696
- await ((_b = this._client) == null ? void 0 : _b.close());
689
+ await this._client?.close();
697
690
  this._client = void 0;
698
691
  this._setState(SignalState.CLOSED);
699
692
  log3("closed", void 0, {
@@ -704,11 +697,10 @@ var SignalClient = class {
704
697
  });
705
698
  }
706
699
  getStatus() {
707
- var _a;
708
700
  return {
709
701
  host: this._host,
710
702
  state: this._state,
711
- error: (_a = this._lastError) == null ? void 0 : _a.message,
703
+ error: this._lastError?.message,
712
704
  reconnectIn: this._reconnectAfter,
713
705
  connectionStarted: this._connectionStarted,
714
706
  lastStateChange: this._lastStateChange
@@ -732,7 +724,6 @@ var SignalClient = class {
732
724
  this._reconcileTask.schedule();
733
725
  }
734
726
  async leave({ topic, peerId }) {
735
- var _a;
736
727
  this._performance.leaveCounter++;
737
728
  log3("leaving", {
738
729
  topic,
@@ -743,10 +734,10 @@ var SignalClient = class {
743
734
  S: this,
744
735
  C: (f, a) => f(...a)
745
736
  });
746
- (_a = this._swarmStreams.get({
737
+ this._swarmStreams.get({
747
738
  topic,
748
739
  peerId
749
- })) == null ? void 0 : _a.close();
740
+ })?.close();
750
741
  this._swarmStreams.delete({
751
742
  topic,
752
743
  peerId
@@ -785,7 +776,6 @@ var SignalClient = class {
785
776
  this._reconcileTask.schedule();
786
777
  }
787
778
  async unsubscribeMessages(peerId) {
788
- var _a;
789
779
  log3("unsubscribing from messages", {
790
780
  peerId
791
781
  }, {
@@ -797,7 +787,7 @@ var SignalClient = class {
797
787
  this._subscribedMessages.delete({
798
788
  peerId
799
789
  });
800
- (_a = this._messageStreams.get(peerId)) == null ? void 0 : _a.close();
790
+ this._messageStreams.get(peerId)?.close();
801
791
  this._messageStreams.delete(peerId);
802
792
  }
803
793
  _scheduleReconcileAfterError() {
@@ -807,7 +797,7 @@ var SignalClient = class {
807
797
  }
808
798
  _setState(newState) {
809
799
  this._state = newState;
810
- this._lastStateChange = new Date();
800
+ this._lastStateChange = /* @__PURE__ */ new Date();
811
801
  log3("signal state changed", {
812
802
  status: this.getStatus()
813
803
  }, {
@@ -837,17 +827,17 @@ var SignalClient = class {
837
827
  "'Client already created'"
838
828
  ]
839
829
  });
840
- this._connectionStarted = new Date();
830
+ this._connectionStarted = /* @__PURE__ */ new Date();
841
831
  this._connectionCtx = this._ctx.derive();
842
- this._connectionCtx.onDispose(() => {
832
+ this._connectionCtx.onDispose(async () => {
843
833
  log3("connection context disposed", void 0, {
844
834
  F: __dxlog_file3,
845
835
  L: 267,
846
836
  S: this,
847
837
  C: (f, a) => f(...a)
848
838
  });
849
- Array.from(this._swarmStreams.values()).forEach((stream) => stream.close());
850
- Array.from(this._messageStreams.values()).forEach((stream) => stream.close());
839
+ await Promise.all(Array.from(this._swarmStreams.values()).map((stream) => stream.close()));
840
+ await Promise.all(Array.from(this._messageStreams.values()).map((stream) => stream.close()));
851
841
  this._swarmStreams.clear();
852
842
  this._messageStreams.clear();
853
843
  });
@@ -920,7 +910,6 @@ var SignalClient = class {
920
910
  this._reconnectAfter = Math.min(this._reconnectAfter, MAX_RECONNECT_TIMEOUT);
921
911
  }
922
912
  async _reconnect() {
923
- var _a, _b;
924
913
  log3(`reconnecting in ${this._reconnectAfter}ms`, {
925
914
  state: this._state
926
915
  }, {
@@ -943,8 +932,8 @@ var SignalClient = class {
943
932
  return;
944
933
  }
945
934
  this._clientReady.reset();
946
- await ((_a = this._connectionCtx) == null ? void 0 : _a.dispose());
947
- (_b = this._client) == null ? void 0 : _b.close().catch(() => {
935
+ await this._connectionCtx?.dispose();
936
+ this._client?.close().catch(() => {
948
937
  });
949
938
  this._client = void 0;
950
939
  await cancelWithContext(this._ctx, sleep(this._reconnectAfter));
@@ -952,7 +941,6 @@ var SignalClient = class {
952
941
  this._createClient();
953
942
  }
954
943
  async _reconcileSwarmSubscriptions() {
955
- var _a;
956
944
  await asyncTimeout(cancelWithContext(this._connectionCtx, this._clientReady.wait()), 5e3);
957
945
  const client = this._client;
958
946
  invariant3(this._state === SignalState.CONNECTED, "Not connected to Signal Server", {
@@ -971,10 +959,10 @@ var SignalClient = class {
971
959
  })) {
972
960
  continue;
973
961
  }
974
- (_a = this._swarmStreams.get({
962
+ this._swarmStreams.get({
975
963
  topic,
976
964
  peerId
977
- })) == null ? void 0 : _a.close();
965
+ })?.close();
978
966
  this._swarmStreams.delete({
979
967
  topic,
980
968
  peerId
@@ -1012,7 +1000,6 @@ var SignalClient = class {
1012
1000
  }
1013
1001
  }
1014
1002
  async _reconcileMessageSubscriptions() {
1015
- var _a;
1016
1003
  await asyncTimeout(cancelWithContext(this._connectionCtx, this._clientReady.wait()), 5e3);
1017
1004
  const client = this._client;
1018
1005
  invariant3(this._state === SignalState.CONNECTED, "Not connected to Signal Server", {
@@ -1030,7 +1017,7 @@ var SignalClient = class {
1030
1017
  })) {
1031
1018
  continue;
1032
1019
  }
1033
- (_a = this._messageStreams.get(peerId)) == null ? void 0 : _a.close();
1020
+ this._messageStreams.get(peerId)?.close();
1034
1021
  this._messageStreams.delete(peerId);
1035
1022
  }
1036
1023
  for (const { peerId } of this._subscribedMessages.values()) {
@@ -1132,7 +1119,7 @@ var MemorySignalManager = class {
1132
1119
  swarmEvent: {
1133
1120
  peerAvailable: {
1134
1121
  peer: peerId.asUint8Array(),
1135
- since: new Date()
1122
+ since: /* @__PURE__ */ new Date()
1136
1123
  }
1137
1124
  }
1138
1125
  });
@@ -1143,7 +1130,7 @@ var MemorySignalManager = class {
1143
1130
  swarmEvent: {
1144
1131
  peerAvailable: {
1145
1132
  peer: peerId2.asUint8Array(),
1146
- since: new Date()
1133
+ since: /* @__PURE__ */ new Date()
1147
1134
  }
1148
1135
  }
1149
1136
  });
@@ -1302,15 +1289,14 @@ var MemorySignalManager = class {
1302
1289
  }
1303
1290
  };
1304
1291
  var dec = (payload) => {
1305
- var _a, _b, _c;
1306
1292
  if (!payload.type_url.endsWith("ReliablePayload")) {
1307
1293
  return {};
1308
1294
  }
1309
1295
  const relPayload = schema3.getCodecForType("dxos.mesh.messaging.ReliablePayload").decode(payload.value);
1310
- if (typeof ((_a = relPayload == null ? void 0 : relPayload.payload) == null ? void 0 : _a.data) === "object") {
1296
+ if (typeof relPayload?.payload?.data === "object") {
1311
1297
  return {
1312
- payload: Object.keys((_b = relPayload == null ? void 0 : relPayload.payload) == null ? void 0 : _b.data)[0],
1313
- sessionId: (_c = relPayload == null ? void 0 : relPayload.payload) == null ? void 0 : _c.sessionId
1298
+ payload: Object.keys(relPayload?.payload?.data)[0],
1299
+ sessionId: relPayload?.payload?.sessionId
1314
1300
  };
1315
1301
  }
1316
1302
  return {};