@dxos/teleport 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.
@@ -12,7 +12,7 @@ import { Context as Context3 } from "@dxos/context";
12
12
  import { failUndefined as failUndefined2 } from "@dxos/debug";
13
13
  import { invariant as invariant4 } from "@dxos/invariant";
14
14
  import { PublicKey } from "@dxos/keys";
15
- import { log as log5 } from "@dxos/log";
15
+ import { log as log5, logInfo as logInfo2 } from "@dxos/log";
16
16
  import { RpcClosedError as RpcClosedError2, TimeoutError as TimeoutError2 } from "@dxos/protocols";
17
17
 
18
18
  // packages/core/mesh/teleport/src/control-extension.ts
@@ -329,7 +329,7 @@ import { scheduleTaskInterval as scheduleTaskInterval2, Event as Event3, Trigger
329
329
  import { Context as Context2 } from "@dxos/context";
330
330
  import { failUndefined } from "@dxos/debug";
331
331
  import { invariant as invariant3 } from "@dxos/invariant";
332
- import { log as log4 } from "@dxos/log";
332
+ import { log as log4, logInfo } from "@dxos/log";
333
333
  import { schema as schema2, TimeoutError } from "@dxos/protocols";
334
334
 
335
335
  // packages/core/mesh/teleport/src/muxing/balancer.ts
@@ -542,6 +542,16 @@ var decodeChunk = (data, withLength) => {
542
542
  };
543
543
 
544
544
  // packages/core/mesh/teleport/src/muxing/muxer.ts
545
+ function _ts_decorate(decorators, target, key, desc) {
546
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
547
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
548
+ r = Reflect.decorate(decorators, target, key, desc);
549
+ else
550
+ for (var i = decorators.length - 1; i >= 0; i--)
551
+ if (d = decorators[i])
552
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
553
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
554
+ }
545
555
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
546
556
  var Command = schema2.getCodecForType("dxos.mesh.muxer.Command");
547
557
  var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
@@ -569,6 +579,12 @@ var Muxer = class {
569
579
  await this._handleCommand(Command.decode(msg));
570
580
  });
571
581
  }
582
+ setSessionId(sessionId) {
583
+ this._sessionId = sessionId;
584
+ }
585
+ get sessionIdString() {
586
+ return this._sessionId ? this._sessionId.truncate() : "none";
587
+ }
572
588
  /**
573
589
  * Creates a duplex Node.js-style stream.
574
590
  * The remote peer is expected to call `createStream` with the same tag.
@@ -582,7 +598,7 @@ var Muxer = class {
582
598
  });
583
599
  invariant3(!channel.push, `Channel already open: ${tag}`, {
584
600
  F: __dxlog_file4,
585
- L: 140,
601
+ L: 151,
586
602
  S: this,
587
603
  A: [
588
604
  "!channel.push",
@@ -601,7 +617,15 @@ var Muxer = class {
601
617
  stream.push(data);
602
618
  };
603
619
  channel.destroy = (err) => {
604
- stream.destroy(err);
620
+ if (err) {
621
+ if (stream.listeners("error").length > 0) {
622
+ stream.destroy(err);
623
+ } else {
624
+ stream.destroy();
625
+ }
626
+ } else {
627
+ stream.destroy();
628
+ }
605
629
  };
606
630
  try {
607
631
  await this._sendCommand({
@@ -630,7 +654,7 @@ var Muxer = class {
630
654
  });
631
655
  invariant3(!channel.push, `Channel already open: ${tag}`, {
632
656
  F: __dxlog_file4,
633
- L: 192,
657
+ L: 211,
634
658
  S: this,
635
659
  A: [
636
660
  "!channel.push",
@@ -654,7 +678,7 @@ var Muxer = class {
654
678
  subscribe: (cb) => {
655
679
  invariant3(!callback, "Only one subscriber is allowed", {
656
680
  F: __dxlog_file4,
657
- L: 214,
681
+ L: 233,
658
682
  S: this,
659
683
  A: [
660
684
  "!callback",
@@ -687,7 +711,7 @@ var Muxer = class {
687
711
  if (this._destroying) {
688
712
  log4("already destroying, ignoring graceful close request", void 0, {
689
713
  F: __dxlog_file4,
690
- L: 247,
714
+ L: 266,
691
715
  S: this,
692
716
  C: (f, a) => f(...a)
693
717
  });
@@ -696,7 +720,7 @@ var Muxer = class {
696
720
  if (this._closing) {
697
721
  log4("already closing, ignoring graceful close request", void 0, {
698
722
  F: __dxlog_file4,
699
- L: 251,
723
+ L: 270,
700
724
  S: this,
701
725
  C: (f, a) => f(...a)
702
726
  });
@@ -712,11 +736,11 @@ var Muxer = class {
712
736
  err: err2
713
737
  }, {
714
738
  F: __dxlog_file4,
715
- L: 266,
739
+ L: 285,
716
740
  S: this,
717
741
  C: (f, a) => f(...a)
718
742
  });
719
- await this.dispose(err2);
743
+ await this._dispose(err2);
720
744
  });
721
745
  await Promise.race([
722
746
  new Promise((_resolve, reject) => {
@@ -725,7 +749,7 @@ var Muxer = class {
725
749
  }, GRACEFUL_CLOSE_TIMEOUT);
726
750
  }),
727
751
  (async () => {
728
- await this.dispose(err);
752
+ await this._dispose(err);
729
753
  })()
730
754
  ]);
731
755
  }
@@ -734,7 +758,7 @@ var Muxer = class {
734
758
  if (this._destroying) {
735
759
  log4("already destroying, ignoring destroy request", void 0, {
736
760
  F: __dxlog_file4,
737
- L: 287,
761
+ L: 307,
738
762
  S: this,
739
763
  C: (f, a) => f(...a)
740
764
  });
@@ -745,7 +769,7 @@ var Muxer = class {
745
769
  if (this._closing) {
746
770
  log4("destroy cancelling graceful close", void 0, {
747
771
  F: __dxlog_file4,
748
- L: 293,
772
+ L: 313,
749
773
  S: this,
750
774
  C: (f, a) => f(...a)
751
775
  });
@@ -760,29 +784,29 @@ var Muxer = class {
760
784
  err: err2
761
785
  }, {
762
786
  F: __dxlog_file4,
763
- L: 306,
787
+ L: 326,
764
788
  S: this,
765
789
  C: (f, a) => f(...a)
766
790
  });
767
791
  });
768
792
  }
769
- this.dispose(err).catch((err2) => {
793
+ this._dispose(err).catch((err2) => {
770
794
  log4("error disposing after destroy", {
771
795
  err: err2
772
796
  }, {
773
797
  F: __dxlog_file4,
774
- L: 311,
798
+ L: 331,
775
799
  S: this,
776
800
  C: (f, a) => f(...a)
777
801
  });
778
802
  });
779
803
  }
780
804
  // complete the termination, graceful or otherwise
781
- async dispose(err) {
805
+ async _dispose(err) {
782
806
  if (this._disposed) {
783
807
  log4("already destroyed, ignoring dispose request", void 0, {
784
808
  F: __dxlog_file4,
785
- L: 319,
809
+ L: 339,
786
810
  S: this,
787
811
  C: (f, a) => f(...a)
788
812
  });
@@ -794,6 +818,7 @@ var Muxer = class {
794
818
  channel.destroy?.(err);
795
819
  }
796
820
  this._disposed = true;
821
+ await this._emitStats();
797
822
  this.afterClosed.emit(err);
798
823
  this._channelsByLocalId.clear();
799
824
  this._channelsByTag.clear();
@@ -804,7 +829,7 @@ var Muxer = class {
804
829
  cmd
805
830
  }, {
806
831
  F: __dxlog_file4,
807
- L: 341,
832
+ L: 362,
808
833
  S: this,
809
834
  C: (f, a) => f(...a)
810
835
  });
@@ -814,15 +839,15 @@ var Muxer = class {
814
839
  if (!this._closing) {
815
840
  log4("received peer close, initiating my own graceful close", void 0, {
816
841
  F: __dxlog_file4,
817
- L: 347,
842
+ L: 368,
818
843
  S: this,
819
844
  C: (f, a) => f(...a)
820
845
  });
821
- await this.close();
846
+ await this.close(new Error("received peer close"));
822
847
  } else {
823
848
  log4("received close from peer, already closing", void 0, {
824
849
  F: __dxlog_file4,
825
- L: 350,
850
+ L: 371,
826
851
  S: this,
827
852
  C: (f, a) => f(...a)
828
853
  });
@@ -851,7 +876,7 @@ var Muxer = class {
851
876
  tag: stream.tag
852
877
  }, {
853
878
  F: __dxlog_file4,
854
- L: 379,
879
+ L: 400,
855
880
  S: this,
856
881
  C: (f, a) => f(...a)
857
882
  });
@@ -866,7 +891,7 @@ var Muxer = class {
866
891
  cmd
867
892
  }, {
868
893
  F: __dxlog_file4,
869
- L: 388,
894
+ L: 409,
870
895
  S: this,
871
896
  C: (f, a) => f(...a)
872
897
  });
@@ -914,7 +939,7 @@ var Muxer = class {
914
939
  threshold: MAX_SAFE_FRAME_SIZE
915
940
  }, {
916
941
  F: __dxlog_file4,
917
- L: 429,
942
+ L: 450,
918
943
  S: this,
919
944
  C: (f, a) => f(...a)
920
945
  });
@@ -940,7 +965,17 @@ var Muxer = class {
940
965
  }
941
966
  async _emitStats() {
942
967
  if (this._disposed || this._destroying) {
968
+ if (!this._lastStats) {
969
+ return;
970
+ }
971
+ const lastStats = this._lastStats;
943
972
  this._lastStats = void 0;
973
+ lastStats.readBufferSize = 0;
974
+ lastStats.writeBufferSize = 0;
975
+ for (const c of lastStats.channels) {
976
+ c.writeBufferSize = 0;
977
+ }
978
+ this.statsUpdated.emit(lastStats);
944
979
  this._lastChannelStats.clear();
945
980
  return;
946
981
  }
@@ -979,9 +1014,12 @@ var Muxer = class {
979
1014
  this.statsUpdated.emit(this._lastStats);
980
1015
  }
981
1016
  };
1017
+ _ts_decorate([
1018
+ logInfo
1019
+ ], Muxer.prototype, "sessionIdString", null);
982
1020
 
983
1021
  // packages/core/mesh/teleport/src/teleport.ts
984
- function _ts_decorate(decorators, target, key, desc) {
1022
+ function _ts_decorate2(decorators, target, key, desc) {
985
1023
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
986
1024
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
987
1025
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1001,7 +1039,7 @@ var Teleport = class {
1001
1039
  void this.destroy(err).catch(() => {
1002
1040
  log5.error("Error during destroy", err, {
1003
1041
  F: __dxlog_file5,
1004
- L: 38,
1042
+ L: 39,
1005
1043
  S: this,
1006
1044
  C: (f, a) => f(...a)
1007
1045
  });
@@ -1016,7 +1054,7 @@ var Teleport = class {
1016
1054
  this._aborting = false;
1017
1055
  invariant4(typeof initiator === "boolean", void 0, {
1018
1056
  F: __dxlog_file5,
1019
- L: 55,
1057
+ L: 56,
1020
1058
  S: this,
1021
1059
  A: [
1022
1060
  "typeof initiator === 'boolean'",
@@ -1025,7 +1063,7 @@ var Teleport = class {
1025
1063
  });
1026
1064
  invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1027
1065
  F: __dxlog_file5,
1028
- L: 56,
1066
+ L: 57,
1029
1067
  S: this,
1030
1068
  A: [
1031
1069
  "PublicKey.isPublicKey(localPeerId)",
@@ -1034,7 +1072,7 @@ var Teleport = class {
1034
1072
  });
1035
1073
  invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1036
1074
  F: __dxlog_file5,
1037
- L: 57,
1075
+ L: 58,
1038
1076
  S: this,
1039
1077
  A: [
1040
1078
  "PublicKey.isPublicKey(remotePeerId)",
@@ -1053,13 +1091,13 @@ var Teleport = class {
1053
1091
  }
1054
1092
  log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1055
1093
  F: __dxlog_file5,
1056
- L: 70,
1094
+ L: 71,
1057
1095
  S: this,
1058
1096
  C: (f, a) => f(...a)
1059
1097
  });
1060
1098
  this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1061
1099
  F: __dxlog_file5,
1062
- L: 71,
1100
+ L: 72,
1063
1101
  S: this,
1064
1102
  C: (f, a) => f(...a)
1065
1103
  }));
@@ -1070,13 +1108,13 @@ var Teleport = class {
1070
1108
  name
1071
1109
  }, {
1072
1110
  F: __dxlog_file5,
1073
- L: 79,
1111
+ L: 80,
1074
1112
  S: this,
1075
1113
  C: (f, a) => f(...a)
1076
1114
  });
1077
1115
  invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1078
1116
  F: __dxlog_file5,
1079
- L: 80,
1117
+ L: 81,
1080
1118
  S: this,
1081
1119
  A: [
1082
1120
  "!this._remoteExtensions.has(name)",
@@ -1097,7 +1135,7 @@ var Teleport = class {
1097
1135
  if (this._destroying || this._aborting) {
1098
1136
  log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1099
1137
  F: __dxlog_file5,
1100
- L: 96,
1138
+ L: 97,
1101
1139
  S: this,
1102
1140
  C: (f, a) => f(...a)
1103
1141
  });
@@ -1120,12 +1158,15 @@ var Teleport = class {
1120
1158
  channels: stats.channels
1121
1159
  }, {
1122
1160
  F: __dxlog_file5,
1123
- L: 109,
1161
+ L: 110,
1124
1162
  S: this,
1125
1163
  C: (f, a) => f(...a)
1126
1164
  });
1127
1165
  });
1128
1166
  }
1167
+ get sessionIdString() {
1168
+ return this._sessionId ? this._sessionId.truncate() : "none";
1169
+ }
1129
1170
  get stream() {
1130
1171
  return this._muxer.stream;
1131
1172
  }
@@ -1135,10 +1176,18 @@ var Teleport = class {
1135
1176
  /**
1136
1177
  * Blocks until the handshake is complete.
1137
1178
  */
1138
- async open() {
1179
+ async open(sessionId = PublicKey.random()) {
1180
+ this._sessionId = sessionId;
1181
+ log5("open", void 0, {
1182
+ F: __dxlog_file5,
1183
+ L: 144,
1184
+ S: this,
1185
+ C: (f, a) => f(...a)
1186
+ });
1139
1187
  this._setExtension("dxos.mesh.teleport.control", this._control);
1140
1188
  await this._openExtension("dxos.mesh.teleport.control");
1141
1189
  this._open = true;
1190
+ this._muxer.setSessionId(sessionId);
1142
1191
  }
1143
1192
  async close(err) {
1144
1193
  await this.destroy(err);
@@ -1158,7 +1207,7 @@ var Teleport = class {
1158
1207
  } catch (err2) {
1159
1208
  log5.catch(err2, void 0, {
1160
1209
  F: __dxlog_file5,
1161
- L: 162,
1210
+ L: 173,
1162
1211
  S: this,
1163
1212
  C: (f, a) => f(...a)
1164
1213
  });
@@ -1181,7 +1230,7 @@ var Teleport = class {
1181
1230
  } catch (err2) {
1182
1231
  log5.catch(err2, void 0, {
1183
1232
  F: __dxlog_file5,
1184
- L: 186,
1233
+ L: 197,
1185
1234
  S: this,
1186
1235
  C: (f, a) => f(...a)
1187
1236
  });
@@ -1197,7 +1246,7 @@ var Teleport = class {
1197
1246
  name
1198
1247
  }, {
1199
1248
  F: __dxlog_file5,
1200
- L: 198,
1249
+ L: 209,
1201
1250
  S: this,
1202
1251
  C: (f, a) => f(...a)
1203
1252
  });
@@ -1221,7 +1270,7 @@ var Teleport = class {
1221
1270
  _setExtension(extensionName, extension) {
1222
1271
  invariant4(!extensionName.includes("/"), "Invalid extension name", {
1223
1272
  F: __dxlog_file5,
1224
- L: 222,
1273
+ L: 233,
1225
1274
  S: this,
1226
1275
  A: [
1227
1276
  "!extensionName.includes('/')",
@@ -1230,7 +1279,7 @@ var Teleport = class {
1230
1279
  });
1231
1280
  invariant4(!this._extensions.has(extensionName), "Extension already exists", {
1232
1281
  F: __dxlog_file5,
1233
- L: 223,
1282
+ L: 234,
1234
1283
  S: this,
1235
1284
  A: [
1236
1285
  "!this._extensions.has(extensionName)",
@@ -1244,7 +1293,7 @@ var Teleport = class {
1244
1293
  extensionName
1245
1294
  }, {
1246
1295
  F: __dxlog_file5,
1247
- L: 228,
1296
+ L: 239,
1248
1297
  S: this,
1249
1298
  C: (f, a) => f(...a)
1250
1299
  });
@@ -1256,7 +1305,7 @@ var Teleport = class {
1256
1305
  createPort: async (channelName, opts) => {
1257
1306
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1258
1307
  F: __dxlog_file5,
1259
- L: 236,
1308
+ L: 247,
1260
1309
  S: this,
1261
1310
  A: [
1262
1311
  "!channelName.includes('/')",
@@ -1268,7 +1317,7 @@ var Teleport = class {
1268
1317
  createStream: async (channelName, opts) => {
1269
1318
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1270
1319
  F: __dxlog_file5,
1271
- L: 240,
1320
+ L: 251,
1272
1321
  S: this,
1273
1322
  A: [
1274
1323
  "!channelName.includes('/')",
@@ -1288,16 +1337,19 @@ var Teleport = class {
1288
1337
  extensionName
1289
1338
  }, {
1290
1339
  F: __dxlog_file5,
1291
- L: 251,
1340
+ L: 262,
1292
1341
  S: this,
1293
1342
  C: (f, a) => f(...a)
1294
1343
  });
1295
1344
  }
1296
1345
  };
1297
- _ts_decorate([
1346
+ _ts_decorate2([
1347
+ logInfo2
1348
+ ], Teleport.prototype, "sessionIdString", null);
1349
+ _ts_decorate2([
1298
1350
  synchronized
1299
1351
  ], Teleport.prototype, "abort", null);
1300
- _ts_decorate([
1352
+ _ts_decorate2([
1301
1353
  synchronized
1302
1354
  ], Teleport.prototype, "destroy", null);
1303
1355
 
@@ -1444,7 +1496,7 @@ var TestPeer = class {
1444
1496
  ""
1445
1497
  ]
1446
1498
  });
1447
- await connection.teleport.open();
1499
+ await connection.teleport.open(PublicKey2.random());
1448
1500
  await this.onOpen(connection);
1449
1501
  }
1450
1502
  async closeConnection(connection) {
@@ -1880,4 +1932,4 @@ export {
1880
1932
  TestExtension,
1881
1933
  TestExtensionWithStreams
1882
1934
  };
1883
- //# sourceMappingURL=chunk-C7IP5EHF.mjs.map
1935
+ //# sourceMappingURL=chunk-M7U4KJA7.mjs.map