@dxos/messaging 0.1.56-main.d0c207f → 0.1.56-main.d9d1c3e

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.
@@ -39,9 +39,9 @@ __export(src_exports, {
39
39
  module.exports = __toCommonJS(src_exports);
40
40
 
41
41
  // packages/core/mesh/messaging/src/messenger.ts
42
- var import_tiny_invariant = __toESM(require("tiny-invariant"));
43
42
  var import_async = require("@dxos/async");
44
43
  var import_context = require("@dxos/context");
44
+ var import_invariant = require("@dxos/invariant");
45
45
  var import_keys = require("@dxos/keys");
46
46
  var import_log = require("@dxos/log");
47
47
  var import_protocols = require("@dxos/protocols");
@@ -76,14 +76,14 @@ var Messenger = class {
76
76
  id: traceId
77
77
  }), {
78
78
  F: __dxlog_file,
79
- L: 63,
79
+ L: 62,
80
80
  S: this,
81
81
  C: (f, a) => f(...a)
82
82
  });
83
83
  this._ctx = new import_context.Context({
84
84
  onError: (err) => import_log.log.catch(err, void 0, {
85
85
  F: __dxlog_file,
86
- L: 65,
86
+ L: 64,
87
87
  S: this,
88
88
  C: (f, a) => f(...a)
89
89
  })
@@ -93,7 +93,7 @@ var Messenger = class {
93
93
  from: message.author
94
94
  }, {
95
95
  F: __dxlog_file,
96
- L: 69,
96
+ L: 68,
97
97
  S: this,
98
98
  C: (f, a) => f(...a)
99
99
  });
@@ -104,7 +104,7 @@ var Messenger = class {
104
104
  id: traceId
105
105
  }), {
106
106
  F: __dxlog_file,
107
- L: 74,
107
+ L: 73,
108
108
  S: this,
109
109
  C: (f, a) => f(...a)
110
110
  });
@@ -117,20 +117,36 @@ var Messenger = class {
117
117
  await this._ctx.dispose();
118
118
  }
119
119
  async sendMessage({ author, recipient, payload }) {
120
- (0, import_tiny_invariant.default)(!this._closed, "Closed");
120
+ (0, import_invariant.invariant)(!this._closed, "Closed", {
121
+ F: __dxlog_file,
122
+ L: 85,
123
+ S: this,
124
+ A: [
125
+ "!this._closed",
126
+ "'Closed'"
127
+ ]
128
+ });
121
129
  const messageContext = this._ctx.derive();
122
130
  const reliablePayload = {
123
131
  messageId: import_keys.PublicKey.random(),
124
132
  payload
125
133
  };
126
- (0, import_tiny_invariant.default)(!this._onAckCallbacks.has(reliablePayload.messageId));
134
+ (0, import_invariant.invariant)(!this._onAckCallbacks.has(reliablePayload.messageId), void 0, {
135
+ F: __dxlog_file,
136
+ L: 92,
137
+ S: this,
138
+ A: [
139
+ "!this._onAckCallbacks.has(reliablePayload.messageId!)",
140
+ ""
141
+ ]
142
+ });
127
143
  (0, import_log.log)("send message", {
128
144
  messageId: reliablePayload.messageId,
129
145
  author,
130
146
  recipient
131
147
  }, {
132
148
  F: __dxlog_file,
133
- L: 94,
149
+ L: 93,
134
150
  S: this,
135
151
  C: (f, a) => f(...a)
136
152
  });
@@ -145,7 +161,7 @@ var Messenger = class {
145
161
  messageId: reliablePayload.messageId
146
162
  }, {
147
163
  F: __dxlog_file,
148
- L: 108,
164
+ L: 107,
149
165
  S: this,
150
166
  C: (f, a) => f(...a)
151
167
  });
@@ -157,7 +173,7 @@ var Messenger = class {
157
173
  err
158
174
  }, {
159
175
  F: __dxlog_file,
160
- L: 110,
176
+ L: 109,
161
177
  S: this,
162
178
  C: (f, a) => f(...a)
163
179
  }));
@@ -167,7 +183,7 @@ var Messenger = class {
167
183
  messageId: reliablePayload.messageId
168
184
  }, {
169
185
  F: __dxlog_file,
170
- L: 119,
186
+ L: 118,
171
187
  S: this,
172
188
  C: (f, a) => f(...a)
173
189
  });
@@ -192,7 +208,15 @@ var Messenger = class {
192
208
  * @param payloadType if not specified, onMessage will be subscribed to all types of messages.
193
209
  */
194
210
  async listen({ peerId, payloadType, onMessage }) {
195
- (0, import_tiny_invariant.default)(!this._closed, "Closed");
211
+ (0, import_invariant.invariant)(!this._closed, "Closed", {
212
+ F: __dxlog_file,
213
+ L: 150,
214
+ S: this,
215
+ A: [
216
+ "!this._closed",
217
+ "'Closed'"
218
+ ]
219
+ });
196
220
  await this._signalManager.subscribeMessages(peerId);
197
221
  let listeners;
198
222
  if (!payloadType) {
@@ -248,7 +272,15 @@ var Messenger = class {
248
272
  }
249
273
  }
250
274
  async _handleReliablePayload({ author, recipient, payload }) {
251
- (0, import_tiny_invariant.default)(payload.type_url === "dxos.mesh.messaging.ReliablePayload");
275
+ (0, import_invariant.invariant)(payload.type_url === "dxos.mesh.messaging.ReliablePayload", void 0, {
276
+ F: __dxlog_file,
277
+ L: 211,
278
+ S: this,
279
+ A: [
280
+ "payload.type_url === 'dxos.mesh.messaging.ReliablePayload'",
281
+ ""
282
+ ]
283
+ });
252
284
  const reliablePayload = ReliablePayload.decode(payload.value, {
253
285
  preserveAny: true
254
286
  });
@@ -256,7 +288,7 @@ var Messenger = class {
256
288
  messageId: reliablePayload.messageId
257
289
  }, {
258
290
  F: __dxlog_file,
259
- L: 215,
291
+ L: 214,
260
292
  S: this,
261
293
  C: (f, a) => f(...a)
262
294
  });
@@ -277,7 +309,15 @@ var Messenger = class {
277
309
  }
278
310
  async _handleAcknowledgement({ payload }) {
279
311
  var _a;
280
- (0, import_tiny_invariant.default)(payload.type_url === "dxos.mesh.messaging.Acknowledgement");
312
+ (0, import_invariant.invariant)(payload.type_url === "dxos.mesh.messaging.Acknowledgement", void 0, {
313
+ F: __dxlog_file,
314
+ L: 236,
315
+ S: this,
316
+ A: [
317
+ "payload.type_url === 'dxos.mesh.messaging.Acknowledgement'",
318
+ ""
319
+ ]
320
+ });
281
321
  (_a = this._onAckCallbacks.get(Acknowledgement.decode(payload.value).messageId)) == null ? void 0 : _a();
282
322
  }
283
323
  async _sendAcknowledgement({ author, recipient, messageId }) {
@@ -287,7 +327,7 @@ var Messenger = class {
287
327
  to: author
288
328
  }, {
289
329
  F: __dxlog_file,
290
- L: 250,
330
+ L: 249,
291
331
  S: this,
292
332
  C: (f, a) => f(...a)
293
333
  });
@@ -326,9 +366,9 @@ var Messenger = class {
326
366
  };
327
367
 
328
368
  // packages/core/mesh/messaging/src/signal-client/signal-client.ts
329
- var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
330
369
  var import_async3 = require("@dxos/async");
331
370
  var import_context2 = require("@dxos/context");
371
+ var import_invariant3 = require("@dxos/invariant");
332
372
  var import_keys3 = require("@dxos/keys");
333
373
  var import_log3 = require("@dxos/log");
334
374
  var import_protocols3 = require("@dxos/protocols");
@@ -337,8 +377,8 @@ var import_util2 = require("@dxos/util");
337
377
 
338
378
  // packages/core/mesh/messaging/src/signal-client/signal-rpc-client.ts
339
379
  var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
340
- var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
341
380
  var import_async2 = require("@dxos/async");
381
+ var import_invariant2 = require("@dxos/invariant");
342
382
  var import_keys2 = require("@dxos/keys");
343
383
  var import_log2 = require("@dxos/log");
344
384
  var import_protocols2 = require("@dxos/protocols");
@@ -484,8 +524,24 @@ var SignalRPCClient = class {
484
524
  C: (f, a) => f(...a)
485
525
  });
486
526
  await this._connectTrigger.wait();
487
- (0, import_tiny_invariant2.default)(!this._closed, "SignalRPCClient is closed");
488
- (0, import_tiny_invariant2.default)(this._rpc, "Rpc is not initialized");
527
+ (0, import_invariant2.invariant)(!this._closed, "SignalRPCClient is closed", {
528
+ F: __dxlog_file2,
529
+ L: 138,
530
+ S: this,
531
+ A: [
532
+ "!this._closed",
533
+ "'SignalRPCClient is closed'"
534
+ ]
535
+ });
536
+ (0, import_invariant2.invariant)(this._rpc, "Rpc is not initialized", {
537
+ F: __dxlog_file2,
538
+ L: 139,
539
+ S: this,
540
+ A: [
541
+ "this._rpc",
542
+ "'Rpc is not initialized'"
543
+ ]
544
+ });
489
545
  const swarmStream = this._rpc.rpc.Signal.join({
490
546
  swarm: topic.asUint8Array(),
491
547
  peer: peerId.asUint8Array()
@@ -502,9 +558,25 @@ var SignalRPCClient = class {
502
558
  S: this,
503
559
  C: (f, a) => f(...a)
504
560
  });
505
- (0, import_tiny_invariant2.default)(!this._closed, "SignalRPCClient is closed");
561
+ (0, import_invariant2.invariant)(!this._closed, "SignalRPCClient is closed", {
562
+ F: __dxlog_file2,
563
+ L: 150,
564
+ S: this,
565
+ A: [
566
+ "!this._closed",
567
+ "'SignalRPCClient is closed'"
568
+ ]
569
+ });
506
570
  await this._connectTrigger.wait();
507
- (0, import_tiny_invariant2.default)(this._rpc, "Rpc is not initialized");
571
+ (0, import_invariant2.invariant)(this._rpc, "Rpc is not initialized", {
572
+ F: __dxlog_file2,
573
+ L: 152,
574
+ S: this,
575
+ A: [
576
+ "this._rpc",
577
+ "'Rpc is not initialized'"
578
+ ]
579
+ });
508
580
  const messageStream = this._rpc.rpc.Signal.receiveMessages({
509
581
  peer: peerId.asUint8Array()
510
582
  });
@@ -522,9 +594,25 @@ var SignalRPCClient = class {
522
594
  S: this,
523
595
  C: (f, a) => f(...a)
524
596
  });
525
- (0, import_tiny_invariant2.default)(!this._closed, "SignalRPCClient is closed");
597
+ (0, import_invariant2.invariant)(!this._closed, "SignalRPCClient is closed", {
598
+ F: __dxlog_file2,
599
+ L: 162,
600
+ S: this,
601
+ A: [
602
+ "!this._closed",
603
+ "'SignalRPCClient is closed'"
604
+ ]
605
+ });
526
606
  await this._connectTrigger.wait();
527
- (0, import_tiny_invariant2.default)(this._rpc, "Rpc is not initialized");
607
+ (0, import_invariant2.invariant)(this._rpc, "Rpc is not initialized", {
608
+ F: __dxlog_file2,
609
+ L: 164,
610
+ S: this,
611
+ A: [
612
+ "this._rpc",
613
+ "'Rpc is not initialized'"
614
+ ]
615
+ });
528
616
  await this._rpc.rpc.Signal.sendMessage({
529
617
  author: author.asUint8Array(),
530
618
  recipient: recipient.asUint8Array(),
@@ -577,7 +665,7 @@ var SignalClient = class {
577
665
  id: this._instanceId
578
666
  }), {
579
667
  F: __dxlog_file3,
580
- L: 136,
668
+ L: 135,
581
669
  S: this,
582
670
  C: (f, a) => f(...a)
583
671
  });
@@ -596,7 +684,7 @@ var SignalClient = class {
596
684
  if (this._state === import_signal.SignalState.CONNECTED) {
597
685
  import_log3.log.warn("SignalClient error:", err, {
598
686
  F: __dxlog_file3,
599
- L: 148,
687
+ L: 147,
600
688
  S: this,
601
689
  C: (f, a) => f(...a)
602
690
  });
@@ -623,7 +711,7 @@ var SignalClient = class {
623
711
  id: this._instanceId
624
712
  }), {
625
713
  F: __dxlog_file3,
626
- L: 177,
714
+ L: 176,
627
715
  S: this,
628
716
  C: (f, a) => f(...a)
629
717
  });
@@ -632,7 +720,7 @@ var SignalClient = class {
632
720
  var _a, _b;
633
721
  (0, import_log3.log)("closing...", void 0, {
634
722
  F: __dxlog_file3,
635
- L: 181,
723
+ L: 180,
636
724
  S: this,
637
725
  C: (f, a) => f(...a)
638
726
  });
@@ -648,7 +736,7 @@ var SignalClient = class {
648
736
  this._setState(import_signal.SignalState.CLOSED);
649
737
  (0, import_log3.log)("closed", void 0, {
650
738
  F: __dxlog_file3,
651
- L: 192,
739
+ L: 191,
652
740
  S: this,
653
741
  C: (f, a) => f(...a)
654
742
  });
@@ -670,7 +758,7 @@ var SignalClient = class {
670
758
  peerId
671
759
  }, {
672
760
  F: __dxlog_file3,
673
- L: 207,
761
+ L: 206,
674
762
  S: this,
675
763
  C: (f, a) => f(...a)
676
764
  });
@@ -689,7 +777,7 @@ var SignalClient = class {
689
777
  peerId
690
778
  }, {
691
779
  F: __dxlog_file3,
692
- L: 215,
780
+ L: 214,
693
781
  S: this,
694
782
  C: (f, a) => f(...a)
695
783
  });
@@ -709,7 +797,15 @@ var SignalClient = class {
709
797
  async sendMessage(msg) {
710
798
  this._performance.sentMessages++;
711
799
  await this._clientReady.wait();
712
- (0, import_tiny_invariant3.default)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server");
800
+ (0, import_invariant3.invariant)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server", {
801
+ F: __dxlog_file3,
802
+ L: 224,
803
+ S: this,
804
+ A: [
805
+ "this._state === SignalState.CONNECTED",
806
+ "'Not connected to Signal Server'"
807
+ ]
808
+ });
713
809
  await this._client.sendMessage(msg);
714
810
  }
715
811
  async subscribeMessages(peerId) {
@@ -717,7 +813,7 @@ var SignalClient = class {
717
813
  peerId
718
814
  }, {
719
815
  F: __dxlog_file3,
720
- L: 230,
816
+ L: 229,
721
817
  S: this,
722
818
  C: (f, a) => f(...a)
723
819
  });
@@ -732,7 +828,7 @@ var SignalClient = class {
732
828
  peerId
733
829
  }, {
734
830
  F: __dxlog_file3,
735
- L: 236,
831
+ L: 235,
736
832
  S: this,
737
833
  C: (f, a) => f(...a)
738
834
  });
@@ -754,7 +850,7 @@ var SignalClient = class {
754
850
  status: this.getStatus()
755
851
  }, {
756
852
  F: __dxlog_file3,
757
- L: 255,
853
+ L: 254,
758
854
  S: this,
759
855
  C: (f, a) => f(...a)
760
856
  });
@@ -766,17 +862,25 @@ var SignalClient = class {
766
862
  state: this._state
767
863
  }, {
768
864
  F: __dxlog_file3,
769
- L: 260,
865
+ L: 259,
770
866
  S: this,
771
867
  C: (f, a) => f(...a)
772
868
  });
773
- (0, import_tiny_invariant3.default)(!this._client, "Client already created");
869
+ (0, import_invariant3.invariant)(!this._client, "Client already created", {
870
+ F: __dxlog_file3,
871
+ L: 260,
872
+ S: this,
873
+ A: [
874
+ "!this._client",
875
+ "'Client already created'"
876
+ ]
877
+ });
774
878
  this._connectionStarted = new Date();
775
879
  this._connectionCtx = this._ctx.derive();
776
880
  this._connectionCtx.onDispose(() => {
777
881
  (0, import_log3.log)("connection context disposed", void 0, {
778
882
  F: __dxlog_file3,
779
- L: 268,
883
+ L: 267,
780
884
  S: this,
781
885
  C: (f, a) => f(...a)
782
886
  });
@@ -792,7 +896,7 @@ var SignalClient = class {
792
896
  onConnected: () => {
793
897
  (0, import_log3.log)("socket connected", void 0, {
794
898
  F: __dxlog_file3,
795
- L: 280,
899
+ L: 279,
796
900
  S: this,
797
901
  C: (f, a) => f(...a)
798
902
  });
@@ -807,7 +911,7 @@ var SignalClient = class {
807
911
  state: this._state
808
912
  }, {
809
913
  F: __dxlog_file3,
810
- L: 289,
914
+ L: 288,
811
915
  S: this,
812
916
  C: (f, a) => f(...a)
813
917
  });
@@ -827,7 +931,7 @@ var SignalClient = class {
827
931
  state: this._state
828
932
  }, {
829
933
  F: __dxlog_file3,
830
- L: 304,
934
+ L: 303,
831
935
  S: this,
832
936
  C: (f, a) => f(...a)
833
937
  });
@@ -859,7 +963,7 @@ var SignalClient = class {
859
963
  state: this._state
860
964
  }, {
861
965
  F: __dxlog_file3,
862
- L: 331,
966
+ L: 330,
863
967
  S: this,
864
968
  C: (f, a) => f(...a)
865
969
  });
@@ -867,7 +971,7 @@ var SignalClient = class {
867
971
  if (this._state === import_signal.SignalState.RECONNECTING) {
868
972
  import_log3.log.warn("Signal api already reconnecting.", void 0, {
869
973
  F: __dxlog_file3,
870
- L: 335,
974
+ L: 334,
871
975
  S: this,
872
976
  C: (f, a) => f(...a)
873
977
  });
@@ -889,7 +993,15 @@ var SignalClient = class {
889
993
  var _a;
890
994
  await (0, import_async3.asyncTimeout)((0, import_context2.cancelWithContext)(this._connectionCtx, this._clientReady.wait()), 5e3);
891
995
  const client = this._client;
892
- (0, import_tiny_invariant3.default)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server");
996
+ (0, import_invariant3.invariant)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server", {
997
+ F: __dxlog_file3,
998
+ L: 359,
999
+ S: this,
1000
+ A: [
1001
+ "this._state === SignalState.CONNECTED",
1002
+ "'Not connected to Signal Server'"
1003
+ ]
1004
+ });
893
1005
  for (const { topic, peerId } of this._swarmStreams.keys()) {
894
1006
  if (this._joinedTopics.has({
895
1007
  topic,
@@ -922,7 +1034,7 @@ var SignalClient = class {
922
1034
  swarmEvent
923
1035
  }, {
924
1036
  F: __dxlog_file3,
925
- L: 387,
1037
+ L: 386,
926
1038
  S: this,
927
1039
  C: (f, a) => f(...a)
928
1040
  });
@@ -941,7 +1053,15 @@ var SignalClient = class {
941
1053
  var _a;
942
1054
  await (0, import_async3.asyncTimeout)((0, import_context2.cancelWithContext)(this._connectionCtx, this._clientReady.wait()), 5e3);
943
1055
  const client = this._client;
944
- (0, import_tiny_invariant3.default)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server");
1056
+ (0, import_invariant3.invariant)(this._state === import_signal.SignalState.CONNECTED, "Not connected to Signal Server", {
1057
+ F: __dxlog_file3,
1058
+ L: 399,
1059
+ S: this,
1060
+ A: [
1061
+ "this._state === SignalState.CONNECTED",
1062
+ "'Not connected to Signal Server'"
1063
+ ]
1064
+ });
945
1065
  for (const peerId of this._messageStreams.keys()) {
946
1066
  if (this._subscribedMessages.has({
947
1067
  peerId
@@ -970,11 +1090,12 @@ var SignalClient = class {
970
1090
  };
971
1091
 
972
1092
  // packages/core/mesh/messaging/src/signal-manager/memory-signal-manager.ts
973
- var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
974
1093
  var import_async4 = require("@dxos/async");
975
1094
  var import_context3 = require("@dxos/context");
1095
+ var import_invariant4 = require("@dxos/invariant");
976
1096
  var import_keys4 = require("@dxos/keys");
977
1097
  var import_log4 = require("@dxos/log");
1098
+ var import_protocols4 = require("@dxos/protocols");
978
1099
  var import_util3 = require("@dxos/util");
979
1100
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-manager/memory-signal-manager.ts";
980
1101
  var MemorySignalManagerContext = class {
@@ -996,6 +1117,7 @@ var MemorySignalManager = class {
996
1117
  this.swarmEvent = new import_async4.Event();
997
1118
  this.onMessage = new import_async4.Event();
998
1119
  this._joinedSwarms = new import_util3.ComplexSet(({ topic, peerId }) => topic.toHex() + peerId.toHex());
1120
+ this._freezeTrigger = new import_async4.Trigger().wake();
999
1121
  this._ctx = new import_context3.Context();
1000
1122
  this._ctx.onDispose(this._context.swarmEvent.on((data) => this.swarmEvent.emit(data)));
1001
1123
  }
@@ -1026,7 +1148,15 @@ var MemorySignalManager = class {
1026
1148
  return [];
1027
1149
  }
1028
1150
  async join({ topic, peerId }) {
1029
- (0, import_tiny_invariant4.default)(!this._ctx.disposed, "Closed");
1151
+ (0, import_invariant4.invariant)(!this._ctx.disposed, "Closed", {
1152
+ F: __dxlog_file4,
1153
+ L: 104,
1154
+ S: this,
1155
+ A: [
1156
+ "!this._ctx.disposed",
1157
+ "'Closed'"
1158
+ ]
1159
+ });
1030
1160
  this._joinedSwarms.add({
1031
1161
  topic,
1032
1162
  peerId
@@ -1059,7 +1189,15 @@ var MemorySignalManager = class {
1059
1189
  }
1060
1190
  }
1061
1191
  async leave({ topic, peerId }) {
1062
- (0, import_tiny_invariant4.default)(!this._ctx.disposed, "Closed");
1192
+ (0, import_invariant4.invariant)(!this._ctx.disposed, "Closed", {
1193
+ F: __dxlog_file4,
1194
+ L: 140,
1195
+ S: this,
1196
+ A: [
1197
+ "!this._ctx.disposed",
1198
+ "'Closed'"
1199
+ ]
1200
+ });
1063
1201
  this._joinedSwarms.delete({
1064
1202
  topic,
1065
1203
  peerId
@@ -1079,35 +1217,105 @@ var MemorySignalManager = class {
1079
1217
  });
1080
1218
  }
1081
1219
  async sendMessage({ author, recipient, payload }) {
1082
- var _a;
1083
- (0, import_tiny_invariant4.default)(recipient);
1084
- (0, import_tiny_invariant4.default)(!this._ctx.disposed, "Closed");
1085
- if (!this._context.connections.has(recipient)) {
1220
+ (0, import_log4.log)("send message", {
1221
+ author,
1222
+ recipient,
1223
+ ...dec(payload)
1224
+ }, {
1225
+ F: __dxlog_file4,
1226
+ L: 160,
1227
+ S: this,
1228
+ C: (f, a) => f(...a)
1229
+ });
1230
+ (0, import_invariant4.invariant)(recipient, void 0, {
1231
+ F: __dxlog_file4,
1232
+ L: 162,
1233
+ S: this,
1234
+ A: [
1235
+ "recipient",
1236
+ ""
1237
+ ]
1238
+ });
1239
+ (0, import_invariant4.invariant)(!this._ctx.disposed, "Closed", {
1240
+ F: __dxlog_file4,
1241
+ L: 163,
1242
+ S: this,
1243
+ A: [
1244
+ "!this._ctx.disposed",
1245
+ "'Closed'"
1246
+ ]
1247
+ });
1248
+ await this._freezeTrigger.wait();
1249
+ const remote = this._context.connections.get(recipient);
1250
+ if (!remote) {
1086
1251
  import_log4.log.warn("recipient is not subscribed for messages", {
1087
1252
  author,
1088
1253
  recipient
1089
1254
  }, {
1090
1255
  F: __dxlog_file4,
1091
- L: 160,
1256
+ L: 169,
1092
1257
  S: this,
1093
1258
  C: (f, a) => f(...a)
1094
1259
  });
1095
1260
  return;
1096
1261
  }
1097
- if (!((_a = this._context.connections.get(recipient)) == null ? void 0 : _a._ctx.disposed)) {
1098
- this._context.connections.get(recipient).onMessage.emit({
1262
+ if (remote._ctx.disposed) {
1263
+ import_log4.log.warn("recipient is disposed", {
1264
+ author,
1265
+ recipient
1266
+ }, {
1267
+ F: __dxlog_file4,
1268
+ L: 174,
1269
+ S: this,
1270
+ C: (f, a) => f(...a)
1271
+ });
1272
+ return;
1273
+ }
1274
+ remote._freezeTrigger.wait().then(() => {
1275
+ if (remote._ctx.disposed) {
1276
+ import_log4.log.warn("recipient is disposed", {
1277
+ author,
1278
+ recipient
1279
+ }, {
1280
+ F: __dxlog_file4,
1281
+ L: 182,
1282
+ S: this,
1283
+ C: (f, a) => f(...a)
1284
+ });
1285
+ return;
1286
+ }
1287
+ (0, import_log4.log)("receive message", {
1288
+ author,
1289
+ recipient,
1290
+ ...dec(payload)
1291
+ }, {
1292
+ F: __dxlog_file4,
1293
+ L: 186,
1294
+ S: this,
1295
+ C: (f, a) => f(...a)
1296
+ });
1297
+ remote.onMessage.emit({
1099
1298
  author,
1100
1299
  recipient,
1101
1300
  payload
1102
1301
  });
1103
- }
1302
+ }).catch((err) => {
1303
+ import_log4.log.error("error while waiting for freeze", {
1304
+ err
1305
+ }, {
1306
+ F: __dxlog_file4,
1307
+ L: 191,
1308
+ S: this,
1309
+ C: (f, a) => f(...a)
1310
+ });
1311
+ });
1104
1312
  }
1105
1313
  async subscribeMessages(peerId) {
1106
1314
  (0, import_log4.log)("subscribing", {
1107
1315
  peerId
1108
1316
  }, {
1109
1317
  F: __dxlog_file4,
1110
- L: 170,
1318
+ L: 196,
1111
1319
  S: this,
1112
1320
  C: (f, a) => f(...a)
1113
1321
  });
@@ -1118,21 +1326,41 @@ var MemorySignalManager = class {
1118
1326
  peerId
1119
1327
  }, {
1120
1328
  F: __dxlog_file4,
1121
- L: 175,
1329
+ L: 201,
1122
1330
  S: this,
1123
1331
  C: (f, a) => f(...a)
1124
1332
  });
1125
1333
  this._context.connections.delete(peerId);
1126
1334
  }
1335
+ freeze() {
1336
+ this._freezeTrigger.reset();
1337
+ }
1338
+ unfreeze() {
1339
+ this._freezeTrigger.wake();
1340
+ }
1341
+ };
1342
+ var dec = (payload) => {
1343
+ var _a, _b, _c;
1344
+ if (!payload.type_url.endsWith("ReliablePayload")) {
1345
+ return {};
1346
+ }
1347
+ const relPayload = import_protocols4.schema.getCodecForType("dxos.mesh.messaging.ReliablePayload").decode(payload.value);
1348
+ if (typeof ((_a = relPayload == null ? void 0 : relPayload.payload) == null ? void 0 : _a.data) === "object") {
1349
+ return {
1350
+ payload: Object.keys((_b = relPayload == null ? void 0 : relPayload.payload) == null ? void 0 : _b.data)[0],
1351
+ sessionId: (_c = relPayload == null ? void 0 : relPayload.payload) == null ? void 0 : _c.sessionId
1352
+ };
1353
+ }
1354
+ return {};
1127
1355
  };
1128
1356
 
1129
1357
  // packages/core/mesh/messaging/src/signal-manager/websocket-signal-manager.ts
1130
- var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
1131
1358
  var import_async5 = require("@dxos/async");
1132
1359
  var import_context4 = require("@dxos/context");
1360
+ var import_invariant5 = require("@dxos/invariant");
1133
1361
  var import_keys5 = require("@dxos/keys");
1134
1362
  var import_log5 = require("@dxos/log");
1135
- var import_protocols4 = require("@dxos/protocols");
1363
+ var import_protocols5 = require("@dxos/protocols");
1136
1364
  function _ts_decorate(decorators, target, key, desc) {
1137
1365
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1138
1366
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1159,7 +1387,7 @@ var WebsocketSignalManager = class {
1159
1387
  hosts: this._hosts
1160
1388
  }, {
1161
1389
  F: __dxlog_file5,
1162
- L: 47,
1390
+ L: 46,
1163
1391
  S: this,
1164
1392
  C: (f, a) => f(...a)
1165
1393
  });
@@ -1181,15 +1409,15 @@ var WebsocketSignalManager = class {
1181
1409
  hosts: this._hosts
1182
1410
  }, {
1183
1411
  F: __dxlog_file5,
1184
- L: 69,
1412
+ L: 68,
1185
1413
  S: this,
1186
1414
  C: (f, a) => f(...a)
1187
1415
  });
1188
- import_log5.log.trace("dxos.mesh.websocket-signal-manager.open", import_protocols4.trace.begin({
1416
+ import_log5.log.trace("dxos.mesh.websocket-signal-manager.open", import_protocols5.trace.begin({
1189
1417
  id: this._instanceId
1190
1418
  }), {
1191
1419
  F: __dxlog_file5,
1192
- L: 70,
1420
+ L: 69,
1193
1421
  S: this,
1194
1422
  C: (f, a) => f(...a)
1195
1423
  });
@@ -1198,11 +1426,11 @@ var WebsocketSignalManager = class {
1198
1426
  ...this._servers.values()
1199
1427
  ].forEach((server) => server.open());
1200
1428
  this._opened = true;
1201
- import_log5.log.trace("dxos.mesh.websocket-signal-manager.open", import_protocols4.trace.end({
1429
+ import_log5.log.trace("dxos.mesh.websocket-signal-manager.open", import_protocols5.trace.end({
1202
1430
  id: this._instanceId
1203
1431
  }), {
1204
1432
  F: __dxlog_file5,
1205
- L: 77,
1433
+ L: 76,
1206
1434
  S: this,
1207
1435
  C: (f, a) => f(...a)
1208
1436
  });
@@ -1224,11 +1452,19 @@ var WebsocketSignalManager = class {
1224
1452
  peerId
1225
1453
  }, {
1226
1454
  F: __dxlog_file5,
1227
- L: 97,
1455
+ L: 96,
1228
1456
  S: this,
1229
1457
  C: (f, a) => f(...a)
1230
1458
  });
1231
- (0, import_tiny_invariant5.default)(this._opened, "Closed");
1459
+ (0, import_invariant5.invariant)(this._opened, "Closed", {
1460
+ F: __dxlog_file5,
1461
+ L: 97,
1462
+ S: this,
1463
+ A: [
1464
+ "this._opened",
1465
+ "'Closed'"
1466
+ ]
1467
+ });
1232
1468
  await this._forEachServer((server) => server.join({
1233
1469
  topic,
1234
1470
  peerId
@@ -1240,11 +1476,19 @@ var WebsocketSignalManager = class {
1240
1476
  peerId
1241
1477
  }, {
1242
1478
  F: __dxlog_file5,
1243
- L: 104,
1479
+ L: 103,
1244
1480
  S: this,
1245
1481
  C: (f, a) => f(...a)
1246
1482
  });
1247
- (0, import_tiny_invariant5.default)(this._opened, "Closed");
1483
+ (0, import_invariant5.invariant)(this._opened, "Closed", {
1484
+ F: __dxlog_file5,
1485
+ L: 104,
1486
+ S: this,
1487
+ A: [
1488
+ "this._opened",
1489
+ "'Closed'"
1490
+ ]
1491
+ });
1248
1492
  await this._forEachServer((server) => server.leave({
1249
1493
  topic,
1250
1494
  peerId
@@ -1253,11 +1497,19 @@ var WebsocketSignalManager = class {
1253
1497
  async sendMessage({ author, recipient, payload }) {
1254
1498
  (0, import_log5.log)(`Signal ${recipient}`, void 0, {
1255
1499
  F: __dxlog_file5,
1256
- L: 119,
1500
+ L: 118,
1257
1501
  S: this,
1258
1502
  C: (f, a) => f(...a)
1259
1503
  });
1260
- (0, import_tiny_invariant5.default)(this._opened, "Closed");
1504
+ (0, import_invariant5.invariant)(this._opened, "Closed", {
1505
+ F: __dxlog_file5,
1506
+ L: 119,
1507
+ S: this,
1508
+ A: [
1509
+ "this._opened",
1510
+ "'Closed'"
1511
+ ]
1512
+ });
1261
1513
  void this._forEachServer(async (server) => {
1262
1514
  void server.sendMessage({
1263
1515
  author,
@@ -1265,7 +1517,7 @@ var WebsocketSignalManager = class {
1265
1517
  payload
1266
1518
  }).catch((err) => (0, import_log5.log)(err, void 0, {
1267
1519
  F: __dxlog_file5,
1268
- L: 123,
1520
+ L: 122,
1269
1521
  S: this,
1270
1522
  C: (f, a) => f(...a)
1271
1523
  }));
@@ -1274,28 +1526,44 @@ var WebsocketSignalManager = class {
1274
1526
  async subscribeMessages(peerId) {
1275
1527
  (0, import_log5.log)(`Subscribed for message stream peerId=${peerId}`, void 0, {
1276
1528
  F: __dxlog_file5,
1277
- L: 128,
1529
+ L: 127,
1278
1530
  S: this,
1279
1531
  C: (f, a) => f(...a)
1280
1532
  });
1281
- (0, import_tiny_invariant5.default)(this._opened, "Closed");
1533
+ (0, import_invariant5.invariant)(this._opened, "Closed", {
1534
+ F: __dxlog_file5,
1535
+ L: 128,
1536
+ S: this,
1537
+ A: [
1538
+ "this._opened",
1539
+ "'Closed'"
1540
+ ]
1541
+ });
1282
1542
  await this._forEachServer(async (server) => server.subscribeMessages(peerId));
1283
1543
  }
1284
1544
  async unsubscribeMessages(peerId) {
1285
1545
  (0, import_log5.log)(`Subscribed for message stream peerId=${peerId}`, void 0, {
1286
1546
  F: __dxlog_file5,
1287
- L: 135,
1547
+ L: 134,
1288
1548
  S: this,
1289
1549
  C: (f, a) => f(...a)
1290
1550
  });
1291
- (0, import_tiny_invariant5.default)(this._opened, "Closed");
1551
+ (0, import_invariant5.invariant)(this._opened, "Closed", {
1552
+ F: __dxlog_file5,
1553
+ L: 135,
1554
+ S: this,
1555
+ A: [
1556
+ "this._opened",
1557
+ "'Closed'"
1558
+ ]
1559
+ });
1292
1560
  await this._forEachServer(async (server) => server.unsubscribeMessages(peerId));
1293
1561
  }
1294
1562
  _initContext() {
1295
1563
  this._ctx = new import_context4.Context({
1296
1564
  onError: (err) => import_log5.log.catch(err, void 0, {
1297
1565
  F: __dxlog_file5,
1298
- L: 143,
1566
+ L: 142,
1299
1567
  S: this,
1300
1568
  C: (f, a) => f(...a)
1301
1569
  })