@dxos/network-manager 0.1.58-main.7858df5 → 0.1.58-main.822e4fc

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.
@@ -197,7 +197,7 @@ var Connection = class {
197
197
  this.closeReason = err?.message;
198
198
  }
199
199
  if (err instanceof ConnectionResetError) {
200
- log("aborting due to transport ConnectionResetError", void 0, {
200
+ log.warn("aborting due to transport ConnectionResetError", void 0, {
201
201
  F: __dxlog_file,
202
202
  L: 197,
203
203
  S: this,
@@ -205,7 +205,7 @@ var Connection = class {
205
205
  });
206
206
  this.abort().catch((err2) => this.errors.raise(err2));
207
207
  } else if (err instanceof ConnectivityError) {
208
- log("aborting due to transport ConnectivityError", void 0, {
208
+ log.warn("aborting due to transport ConnectivityError", void 0, {
209
209
  F: __dxlog_file,
210
210
  L: 200,
211
211
  S: this,
@@ -213,7 +213,7 @@ var Connection = class {
213
213
  });
214
214
  this.abort().catch((err2) => this.errors.raise(err2));
215
215
  } else if (err instanceof UnknownProtocolError) {
216
- log("unsure what to do for UnknownProtocolError", {
216
+ log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
217
217
  err
218
218
  }, {
219
219
  F: __dxlog_file,
@@ -244,14 +244,14 @@ var Connection = class {
244
244
  err
245
245
  }, {
246
246
  F: __dxlog_file,
247
- L: 224,
247
+ L: 225,
248
248
  S: this,
249
249
  C: (f, a) => f(...a)
250
250
  });
251
251
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
252
252
  log(`abort ignored: already ${this._state}`, this.closeReason, {
253
253
  F: __dxlog_file,
254
- L: 226,
254
+ L: 227,
255
255
  S: this,
256
256
  C: (f, a) => f(...a)
257
257
  });
@@ -267,7 +267,7 @@ var Connection = class {
267
267
  proto: this._protocol
268
268
  }, {
269
269
  F: __dxlog_file,
270
- L: 239,
270
+ L: 240,
271
271
  S: this,
272
272
  C: (f, a) => f(...a)
273
273
  });
@@ -275,7 +275,7 @@ var Connection = class {
275
275
  } catch (err2) {
276
276
  log.catch(err2, void 0, {
277
277
  F: __dxlog_file,
278
- L: 242,
278
+ L: 243,
279
279
  S: this,
280
280
  C: (f, a) => f(...a)
281
281
  });
@@ -285,7 +285,7 @@ var Connection = class {
285
285
  } catch (err2) {
286
286
  log.catch(err2, void 0, {
287
287
  F: __dxlog_file,
288
- L: 249,
288
+ L: 250,
289
289
  S: this,
290
290
  C: (f, a) => f(...a)
291
291
  });
@@ -295,7 +295,7 @@ var Connection = class {
295
295
  } catch (err2) {
296
296
  log.catch(err2, void 0, {
297
297
  F: __dxlog_file,
298
- L: 255,
298
+ L: 256,
299
299
  S: this,
300
300
  C: (f, a) => f(...a)
301
301
  });
@@ -316,7 +316,7 @@ var Connection = class {
316
316
  peerId: this.ownId
317
317
  }, {
318
318
  F: __dxlog_file,
319
- L: 277,
319
+ L: 278,
320
320
  S: this,
321
321
  C: (f, a) => f(...a)
322
322
  });
@@ -326,7 +326,7 @@ var Connection = class {
326
326
  } catch (err2) {
327
327
  log.catch(err2, void 0, {
328
328
  F: __dxlog_file,
329
- L: 284,
329
+ L: 285,
330
330
  S: this,
331
331
  C: (f, a) => f(...a)
332
332
  });
@@ -336,7 +336,7 @@ var Connection = class {
336
336
  } catch (err2) {
337
337
  log.catch(err2, void 0, {
338
338
  F: __dxlog_file,
339
- L: 291,
339
+ L: 292,
340
340
  S: this,
341
341
  C: (f, a) => f(...a)
342
342
  });
@@ -346,7 +346,7 @@ var Connection = class {
346
346
  peerId: this.ownId
347
347
  }, {
348
348
  F: __dxlog_file,
349
- L: 295,
349
+ L: 296,
350
350
  S: this,
351
351
  C: (f, a) => f(...a)
352
352
  });
@@ -389,7 +389,7 @@ var Connection = class {
389
389
  err
390
390
  }, {
391
391
  F: __dxlog_file,
392
- L: 332,
392
+ L: 333,
393
393
  S: this,
394
394
  C: (f, a) => f(...a)
395
395
  });
@@ -402,7 +402,7 @@ var Connection = class {
402
402
  async signal(msg) {
403
403
  invariant(msg.sessionId, void 0, {
404
404
  F: __dxlog_file,
405
- L: 341,
405
+ L: 342,
406
406
  S: this,
407
407
  A: [
408
408
  "msg.sessionId",
@@ -412,7 +412,7 @@ var Connection = class {
412
412
  if (!msg.sessionId.equals(this.sessionId)) {
413
413
  log("dropping signal for incorrect session id", void 0, {
414
414
  F: __dxlog_file,
415
- L: 343,
415
+ L: 344,
416
416
  S: this,
417
417
  C: (f, a) => f(...a)
418
418
  });
@@ -420,7 +420,7 @@ var Connection = class {
420
420
  }
421
421
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
422
422
  F: __dxlog_file,
423
- L: 346,
423
+ L: 347,
424
424
  S: this,
425
425
  A: [
426
426
  "msg.data.signal || msg.data.signalBatch",
@@ -429,7 +429,7 @@ var Connection = class {
429
429
  });
430
430
  invariant(msg.author?.equals(this.remoteId), void 0, {
431
431
  F: __dxlog_file,
432
- L: 347,
432
+ L: 348,
433
433
  S: this,
434
434
  A: [
435
435
  "msg.author?.equals(this.remoteId)",
@@ -438,7 +438,7 @@ var Connection = class {
438
438
  });
439
439
  invariant(msg.recipient?.equals(this.ownId), void 0, {
440
440
  F: __dxlog_file,
441
- L: 348,
441
+ L: 349,
442
442
  S: this,
443
443
  A: [
444
444
  "msg.recipient?.equals(this.ownId)",
@@ -462,7 +462,7 @@ var Connection = class {
462
462
  msg: msg.data
463
463
  }, {
464
464
  F: __dxlog_file,
465
- L: 357,
465
+ L: 358,
466
466
  S: this,
467
467
  C: (f, a) => f(...a)
468
468
  });
@@ -470,7 +470,7 @@ var Connection = class {
470
470
  } else {
471
471
  invariant(this._transport, "Connection not ready to accept signals.", {
472
472
  F: __dxlog_file,
473
- L: 360,
473
+ L: 361,
474
474
  S: this,
475
475
  A: [
476
476
  "this._transport",
@@ -483,7 +483,7 @@ var Connection = class {
483
483
  msg: msg.data
484
484
  }, {
485
485
  F: __dxlog_file,
486
- L: 361,
486
+ L: 362,
487
487
  S: this,
488
488
  C: (f, a) => f(...a)
489
489
  });
@@ -501,13 +501,13 @@ var Connection = class {
501
501
  peerId: this.ownId
502
502
  }, {
503
503
  F: __dxlog_file,
504
- L: 372,
504
+ L: 373,
505
505
  S: this,
506
506
  C: (f, a) => f(...a)
507
507
  });
508
508
  invariant(state !== this._state, "Already in this state.", {
509
509
  F: __dxlog_file,
510
- L: 373,
510
+ L: 374,
511
511
  S: this,
512
512
  A: [
513
513
  "state !== this._state",
@@ -814,6 +814,20 @@ var Peer = class {
814
814
  */
815
815
  async onOffer(message) {
816
816
  const remoteId = message.author;
817
+ if (this.connection && ![
818
+ ConnectionState.CREATED,
819
+ ConnectionState.INITIAL
820
+ ].includes(this.connection.state)) {
821
+ log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
822
+ F: __dxlog_file3,
823
+ L: 112,
824
+ S: this,
825
+ C: (f, a) => f(...a)
826
+ });
827
+ return {
828
+ accept: false
829
+ };
830
+ }
817
831
  if (this.connection || this.initiating) {
818
832
  if (remoteId.toHex() < this.localPeerId.toHex()) {
819
833
  log3("close local connection", {
@@ -823,7 +837,7 @@ var Peer = class {
823
837
  sessionId: this.connection?.sessionId
824
838
  }, {
825
839
  F: __dxlog_file3,
826
- L: 117,
840
+ L: 121,
827
841
  S: this,
828
842
  C: (f, a) => f(...a)
829
843
  });
@@ -840,7 +854,7 @@ var Peer = class {
840
854
  if (!this.connection) {
841
855
  invariant3(message.sessionId, void 0, {
842
856
  F: __dxlog_file3,
843
- L: 137,
857
+ L: 141,
844
858
  S: this,
845
859
  A: [
846
860
  "message.sessionId",
@@ -861,7 +875,7 @@ var Peer = class {
861
875
  err
862
876
  }, {
863
877
  F: __dxlog_file3,
864
- L: 147,
878
+ L: 151,
865
879
  S: this,
866
880
  C: (f, a) => f(...a)
867
881
  });
@@ -883,7 +897,7 @@ var Peer = class {
883
897
  async initiateConnection() {
884
898
  invariant3(!this.initiating, "Initiation in progress.", {
885
899
  F: __dxlog_file3,
886
- L: 164,
900
+ L: 168,
887
901
  S: this,
888
902
  A: [
889
903
  "!this.initiating",
@@ -892,7 +906,7 @@ var Peer = class {
892
906
  });
893
907
  invariant3(!this.connection, "Already connected.", {
894
908
  F: __dxlog_file3,
895
- L: 165,
909
+ L: 169,
896
910
  S: this,
897
911
  A: [
898
912
  "!this.connection",
@@ -907,7 +921,7 @@ var Peer = class {
907
921
  sessionId
908
922
  }, {
909
923
  F: __dxlog_file3,
910
- L: 167,
924
+ L: 171,
911
925
  S: this,
912
926
  C: (f, a) => f(...a)
913
927
  });
@@ -932,14 +946,14 @@ var Peer = class {
932
946
  remoteId: this.id
933
947
  }, {
934
948
  F: __dxlog_file3,
935
- L: 183,
949
+ L: 187,
936
950
  S: this,
937
951
  C: (f, a) => f(...a)
938
952
  });
939
953
  if (connection.state !== ConnectionState.INITIAL) {
940
954
  log3("ignoring response", void 0, {
941
955
  F: __dxlog_file3,
942
- L: 185,
956
+ L: 189,
943
957
  S: this,
944
958
  C: (f, a) => f(...a)
945
959
  });
@@ -959,11 +973,17 @@ var Peer = class {
959
973
  remoteId: this.id
960
974
  }, {
961
975
  F: __dxlog_file3,
962
- L: 196,
976
+ L: 200,
963
977
  S: this,
964
978
  C: (f, a) => f(...a)
965
979
  });
966
980
  if (err instanceof TimeoutError) {
981
+ log3.warn("aborting connection due to signalling failure", void 0, {
982
+ F: __dxlog_file3,
983
+ L: 202,
984
+ S: this,
985
+ C: (f, a) => f(...a)
986
+ });
967
987
  await connection.abort(err);
968
988
  }
969
989
  await this.closeConnection(err);
@@ -985,13 +1005,13 @@ var Peer = class {
985
1005
  sessionId
986
1006
  }, {
987
1007
  F: __dxlog_file3,
988
- L: 213,
1008
+ L: 218,
989
1009
  S: this,
990
1010
  C: (f, a) => f(...a)
991
1011
  });
992
1012
  invariant3(!this.connection, "Already connected.", {
993
1013
  F: __dxlog_file3,
994
- L: 220,
1014
+ L: 225,
995
1015
  S: this,
996
1016
  A: [
997
1017
  "!this.connection",
@@ -1027,7 +1047,7 @@ var Peer = class {
1027
1047
  initiator
1028
1048
  }, {
1029
1049
  F: __dxlog_file3,
1030
- L: 239,
1050
+ L: 244,
1031
1051
  S: this,
1032
1052
  C: (f, a) => f(...a)
1033
1053
  });
@@ -1040,14 +1060,14 @@ var Peer = class {
1040
1060
  initiator
1041
1061
  }, {
1042
1062
  F: __dxlog_file3,
1043
- L: 248,
1063
+ L: 253,
1044
1064
  S: this,
1045
1065
  C: (f, a) => f(...a)
1046
1066
  });
1047
1067
  this._connectionLimiter.doneConnecting(sessionId);
1048
1068
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1049
1069
  F: __dxlog_file3,
1050
- L: 253,
1070
+ L: 258,
1051
1071
  S: this,
1052
1072
  A: [
1053
1073
  "this.connection === connection",
@@ -1062,7 +1082,7 @@ var Peer = class {
1062
1082
  initiator
1063
1083
  }, {
1064
1084
  F: __dxlog_file3,
1065
- L: 255,
1085
+ L: 260,
1066
1086
  S: this,
1067
1087
  C: (f, a) => f(...a)
1068
1088
  });
@@ -1097,7 +1117,7 @@ var Peer = class {
1097
1117
  err
1098
1118
  }, {
1099
1119
  F: __dxlog_file3,
1100
- L: 295,
1120
+ L: 300,
1101
1121
  S: this,
1102
1122
  C: (f, a) => f(...a)
1103
1123
  });
@@ -1110,7 +1130,7 @@ var Peer = class {
1110
1130
  err
1111
1131
  }, {
1112
1132
  F: __dxlog_file3,
1113
- L: 296,
1133
+ L: 301,
1114
1134
  S: this,
1115
1135
  C: (f, a) => f(...a)
1116
1136
  });
@@ -1129,7 +1149,7 @@ var Peer = class {
1129
1149
  sessionId: connection.sessionId
1130
1150
  }, {
1131
1151
  F: __dxlog_file3,
1132
- L: 321,
1152
+ L: 326,
1133
1153
  S: this,
1134
1154
  C: (f, a) => f(...a)
1135
1155
  });
@@ -1139,7 +1159,7 @@ var Peer = class {
1139
1159
  sessionId: connection.sessionId
1140
1160
  }, {
1141
1161
  F: __dxlog_file3,
1142
- L: 327,
1162
+ L: 332,
1143
1163
  S: this,
1144
1164
  C: (f, a) => f(...a)
1145
1165
  });
@@ -1150,7 +1170,7 @@ var Peer = class {
1150
1170
  message
1151
1171
  }, {
1152
1172
  F: __dxlog_file3,
1153
- L: 332,
1173
+ L: 337,
1154
1174
  S: this,
1155
1175
  C: (f, a) => f(...a)
1156
1176
  });
@@ -1165,7 +1185,7 @@ var Peer = class {
1165
1185
  topic: this.topic
1166
1186
  }, {
1167
1187
  F: __dxlog_file3,
1168
- L: 342,
1188
+ L: 347,
1169
1189
  S: this,
1170
1190
  C: (f, a) => f(...a)
1171
1191
  });
@@ -2671,24 +2691,28 @@ var SimplePeerTransport = class {
2671
2691
  switch (err.code) {
2672
2692
  case "ERR_WEBRTC_SUPPORT":
2673
2693
  this.errors.raise(new ProtocolError2("WebRTC not supported", err));
2694
+ break;
2674
2695
  case "ERR_ICE_CONNECTION_FAILURE":
2675
2696
  case "ERR_DATA_CHANNEL":
2676
2697
  case "ERR_CONNECTION_FAILURE":
2677
2698
  case "ERR_SIGNALING":
2678
2699
  this.errors.raise(new ConnectivityError2("unknown communication failure", err));
2700
+ break;
2679
2701
  case "ERR_CREATE_OFFER":
2680
2702
  case "ERR_CREATE_ANSWER":
2681
2703
  case "ERR_SET_LOCAL_DESCRIPTION":
2682
2704
  case "ERR_SET_REMOTE_DESCRIPTION":
2683
2705
  case "ERR_ADD_ICE_CANDIDATE":
2684
2706
  this.errors.raise(new UnknownProtocolError2("unknown simple-peer library failure", err));
2707
+ break;
2685
2708
  default:
2686
2709
  this.errors.raise(new Error("unknown simple-peer error"));
2710
+ break;
2687
2711
  }
2688
2712
  } else {
2689
2713
  log11.info("unknown peer connection error", err, {
2690
2714
  F: __dxlog_file12,
2691
- L: 96,
2715
+ L: 101,
2692
2716
  S: this,
2693
2717
  C: (f, a) => f(...a)
2694
2718
  });
@@ -2702,7 +2726,7 @@ var SimplePeerTransport = class {
2702
2726
  stats
2703
2727
  }, {
2704
2728
  F: __dxlog_file12,
2705
- L: 104,
2729
+ L: 109,
2706
2730
  S: this,
2707
2731
  C: (f, a) => f(...a)
2708
2732
  });
@@ -2711,7 +2735,7 @@ var SimplePeerTransport = class {
2711
2735
  } catch (err2) {
2712
2736
  log11.catch(err2, void 0, {
2713
2737
  F: __dxlog_file12,
2714
- L: 111,
2738
+ L: 116,
2715
2739
  S: this,
2716
2740
  C: (f, a) => f(...a)
2717
2741
  });
@@ -2722,7 +2746,7 @@ var SimplePeerTransport = class {
2722
2746
  id: this._instanceId
2723
2747
  }), {
2724
2748
  F: __dxlog_file12,
2725
- L: 116,
2749
+ L: 121,
2726
2750
  S: this,
2727
2751
  C: (f, a) => f(...a)
2728
2752
  });
@@ -2730,7 +2754,7 @@ var SimplePeerTransport = class {
2730
2754
  async destroy() {
2731
2755
  log11("closing...", void 0, {
2732
2756
  F: __dxlog_file12,
2733
- L: 120,
2757
+ L: 125,
2734
2758
  S: this,
2735
2759
  C: (f, a) => f(...a)
2736
2760
  });
@@ -2740,7 +2764,7 @@ var SimplePeerTransport = class {
2740
2764
  this.closed.emit();
2741
2765
  log11("closed", void 0, {
2742
2766
  F: __dxlog_file12,
2743
- L: 125,
2767
+ L: 130,
2744
2768
  S: this,
2745
2769
  C: (f, a) => f(...a)
2746
2770
  });
@@ -2842,7 +2866,8 @@ var SimplePeerTransportService = class {
2842
2866
  const transportState = {
2843
2867
  transport,
2844
2868
  stream: duplex,
2845
- writeCallbacks: []
2869
+ writeCallbacks: [],
2870
+ state: "OPEN"
2846
2871
  };
2847
2872
  ready();
2848
2873
  this.transports.set(request.proxyId, transportState);
@@ -2852,7 +2877,7 @@ var SimplePeerTransportService = class {
2852
2877
  async sendSignal({ proxyId, signal }) {
2853
2878
  invariant12(this.transports.has(proxyId), void 0, {
2854
2879
  F: __dxlog_file13,
2855
- L: 110,
2880
+ L: 112,
2856
2881
  S: this,
2857
2882
  A: [
2858
2883
  "this.transports.has(proxyId)",
@@ -2862,9 +2887,17 @@ var SimplePeerTransportService = class {
2862
2887
  await this.transports.get(proxyId).transport.signal(signal);
2863
2888
  }
2864
2889
  async sendData({ proxyId, payload }) {
2890
+ if (this.transports.get(proxyId)?.state !== "OPEN") {
2891
+ log12.debug("transport is closed", void 0, {
2892
+ F: __dxlog_file13,
2893
+ L: 118,
2894
+ S: this,
2895
+ C: (f, a) => f(...a)
2896
+ });
2897
+ }
2865
2898
  invariant12(this.transports.has(proxyId), void 0, {
2866
2899
  F: __dxlog_file13,
2867
- L: 115,
2900
+ L: 120,
2868
2901
  S: this,
2869
2902
  A: [
2870
2903
  "this.transports.has(proxyId)",
@@ -2882,10 +2915,12 @@ var SimplePeerTransportService = class {
2882
2915
  async close({ proxyId }) {
2883
2916
  await this.transports.get(proxyId)?.transport.destroy();
2884
2917
  await this.transports.get(proxyId)?.stream.end();
2885
- this.transports.delete(proxyId);
2918
+ if (this.transports.get(proxyId)) {
2919
+ this.transports.get(proxyId).state = "CLOSED";
2920
+ }
2886
2921
  log12("Closed.", void 0, {
2887
2922
  F: __dxlog_file13,
2888
- L: 129,
2923
+ L: 136,
2889
2924
  S: this,
2890
2925
  C: (f, a) => f(...a)
2891
2926
  });
@@ -3404,6 +3439,26 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
3404
3439
  })
3405
3440
  });
3406
3441
 
3442
+ // packages/core/mesh/network-manager/src/transport/tcp-transport.browser.ts
3443
+ import { Event as Event11 } from "@dxos/async";
3444
+ import { ErrorStream as ErrorStream7 } from "@dxos/debug";
3445
+ var TcpTransportFactory = {
3446
+ createTransport: () => new TcpTransport()
3447
+ };
3448
+ var TcpTransport = class {
3449
+ constructor() {
3450
+ this.closed = new Event11();
3451
+ this.connected = new Event11();
3452
+ this.errors = new ErrorStream7();
3453
+ }
3454
+ async destroy() {
3455
+ throw new Error("Method not implemented.");
3456
+ }
3457
+ signal() {
3458
+ throw new Error("Method not implemented.");
3459
+ }
3460
+ };
3461
+
3407
3462
  // packages/core/mesh/network-manager/src/wire-protocol.ts
3408
3463
  import { Teleport } from "@dxos/teleport";
3409
3464
  var createTeleportProtocolFactory = (onConnection) => {
@@ -3449,6 +3504,8 @@ export {
3449
3504
  SimplePeerTransportProxyFactory,
3450
3505
  LibDataChannelTransport,
3451
3506
  createLibDataChannelTransportFactory,
3507
+ TcpTransportFactory,
3508
+ TcpTransport,
3452
3509
  createTeleportProtocolFactory
3453
3510
  };
3454
- //# sourceMappingURL=chunk-HKHUCTRB.mjs.map
3511
+ //# sourceMappingURL=chunk-3KLH55NB.mjs.map