@dxos/teleport 0.3.9-main.b7e6a67 → 0.3.9-main.c2ac8a5

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.
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_GK3YA6TG_exports = {};
30
- __export(chunk_GK3YA6TG_exports, {
29
+ var chunk_GVV33WCQ_exports = {};
30
+ __export(chunk_GVV33WCQ_exports, {
31
31
  Framer: () => Framer,
32
32
  Muxer: () => Muxer,
33
33
  Teleport: () => Teleport,
@@ -39,7 +39,7 @@ __export(chunk_GK3YA6TG_exports, {
39
39
  decodeFrame: () => decodeFrame,
40
40
  encodeFrame: () => encodeFrame
41
41
  });
42
- module.exports = __toCommonJS(chunk_GK3YA6TG_exports);
42
+ module.exports = __toCommonJS(chunk_GVV33WCQ_exports);
43
43
  var import_node_stream = require("node:stream");
44
44
  var import_invariant = require("@dxos/invariant");
45
45
  var import_keys = require("@dxos/keys");
@@ -578,6 +578,16 @@ var decodeChunk = (data, withLength) => {
578
578
  chunk
579
579
  };
580
580
  };
581
+ function _ts_decorate(decorators, target, key, desc) {
582
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
583
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
584
+ r = Reflect.decorate(decorators, target, key, desc);
585
+ else
586
+ for (var i = decorators.length - 1; i >= 0; i--)
587
+ if (d = decorators[i])
588
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
589
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
590
+ }
581
591
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
582
592
  var Command = import_protocols3.schema.getCodecForType("dxos.mesh.muxer.Command");
583
593
  var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
@@ -605,6 +615,12 @@ var Muxer = class {
605
615
  await this._handleCommand(Command.decode(msg));
606
616
  });
607
617
  }
618
+ setSessionId(sessionId) {
619
+ this._sessionId = sessionId;
620
+ }
621
+ get sessionIdString() {
622
+ return this._sessionId ? this._sessionId.truncate() : "none";
623
+ }
608
624
  /**
609
625
  * Creates a duplex Node.js-style stream.
610
626
  * The remote peer is expected to call `createStream` with the same tag.
@@ -618,7 +634,7 @@ var Muxer = class {
618
634
  });
619
635
  (0, import_invariant4.invariant)(!channel.push, `Channel already open: ${tag}`, {
620
636
  F: __dxlog_file4,
621
- L: 140,
637
+ L: 151,
622
638
  S: this,
623
639
  A: [
624
640
  "!channel.push",
@@ -637,7 +653,15 @@ var Muxer = class {
637
653
  stream.push(data);
638
654
  };
639
655
  channel.destroy = (err) => {
640
- stream.destroy(err);
656
+ if (err) {
657
+ if (stream.listeners("error").length > 0) {
658
+ stream.destroy(err);
659
+ } else {
660
+ stream.destroy();
661
+ }
662
+ } else {
663
+ stream.destroy();
664
+ }
641
665
  };
642
666
  try {
643
667
  await this._sendCommand({
@@ -666,7 +690,7 @@ var Muxer = class {
666
690
  });
667
691
  (0, import_invariant4.invariant)(!channel.push, `Channel already open: ${tag}`, {
668
692
  F: __dxlog_file4,
669
- L: 192,
693
+ L: 211,
670
694
  S: this,
671
695
  A: [
672
696
  "!channel.push",
@@ -690,7 +714,7 @@ var Muxer = class {
690
714
  subscribe: (cb) => {
691
715
  (0, import_invariant4.invariant)(!callback, "Only one subscriber is allowed", {
692
716
  F: __dxlog_file4,
693
- L: 214,
717
+ L: 233,
694
718
  S: this,
695
719
  A: [
696
720
  "!callback",
@@ -723,7 +747,7 @@ var Muxer = class {
723
747
  if (this._destroying) {
724
748
  (0, import_log5.log)("already destroying, ignoring graceful close request", void 0, {
725
749
  F: __dxlog_file4,
726
- L: 247,
750
+ L: 266,
727
751
  S: this,
728
752
  C: (f, a) => f(...a)
729
753
  });
@@ -732,7 +756,7 @@ var Muxer = class {
732
756
  if (this._closing) {
733
757
  (0, import_log5.log)("already closing, ignoring graceful close request", void 0, {
734
758
  F: __dxlog_file4,
735
- L: 251,
759
+ L: 270,
736
760
  S: this,
737
761
  C: (f, a) => f(...a)
738
762
  });
@@ -748,11 +772,11 @@ var Muxer = class {
748
772
  err: err2
749
773
  }, {
750
774
  F: __dxlog_file4,
751
- L: 266,
775
+ L: 285,
752
776
  S: this,
753
777
  C: (f, a) => f(...a)
754
778
  });
755
- await this.dispose(err2);
779
+ await this._dispose(err2);
756
780
  });
757
781
  await Promise.race([
758
782
  new Promise((_resolve, reject) => {
@@ -761,7 +785,7 @@ var Muxer = class {
761
785
  }, GRACEFUL_CLOSE_TIMEOUT);
762
786
  }),
763
787
  (async () => {
764
- await this.dispose(err);
788
+ await this._dispose(err);
765
789
  })()
766
790
  ]);
767
791
  }
@@ -770,7 +794,7 @@ var Muxer = class {
770
794
  if (this._destroying) {
771
795
  (0, import_log5.log)("already destroying, ignoring destroy request", void 0, {
772
796
  F: __dxlog_file4,
773
- L: 287,
797
+ L: 307,
774
798
  S: this,
775
799
  C: (f, a) => f(...a)
776
800
  });
@@ -781,7 +805,7 @@ var Muxer = class {
781
805
  if (this._closing) {
782
806
  (0, import_log5.log)("destroy cancelling graceful close", void 0, {
783
807
  F: __dxlog_file4,
784
- L: 293,
808
+ L: 313,
785
809
  S: this,
786
810
  C: (f, a) => f(...a)
787
811
  });
@@ -796,29 +820,29 @@ var Muxer = class {
796
820
  err: err2
797
821
  }, {
798
822
  F: __dxlog_file4,
799
- L: 306,
823
+ L: 326,
800
824
  S: this,
801
825
  C: (f, a) => f(...a)
802
826
  });
803
827
  });
804
828
  }
805
- this.dispose(err).catch((err2) => {
829
+ this._dispose(err).catch((err2) => {
806
830
  (0, import_log5.log)("error disposing after destroy", {
807
831
  err: err2
808
832
  }, {
809
833
  F: __dxlog_file4,
810
- L: 311,
834
+ L: 331,
811
835
  S: this,
812
836
  C: (f, a) => f(...a)
813
837
  });
814
838
  });
815
839
  }
816
840
  // complete the termination, graceful or otherwise
817
- async dispose(err) {
841
+ async _dispose(err) {
818
842
  if (this._disposed) {
819
843
  (0, import_log5.log)("already destroyed, ignoring dispose request", void 0, {
820
844
  F: __dxlog_file4,
821
- L: 319,
845
+ L: 339,
822
846
  S: this,
823
847
  C: (f, a) => f(...a)
824
848
  });
@@ -830,6 +854,7 @@ var Muxer = class {
830
854
  channel.destroy?.(err);
831
855
  }
832
856
  this._disposed = true;
857
+ await this._emitStats();
833
858
  this.afterClosed.emit(err);
834
859
  this._channelsByLocalId.clear();
835
860
  this._channelsByTag.clear();
@@ -840,7 +865,7 @@ var Muxer = class {
840
865
  cmd
841
866
  }, {
842
867
  F: __dxlog_file4,
843
- L: 341,
868
+ L: 362,
844
869
  S: this,
845
870
  C: (f, a) => f(...a)
846
871
  });
@@ -850,15 +875,15 @@ var Muxer = class {
850
875
  if (!this._closing) {
851
876
  (0, import_log5.log)("received peer close, initiating my own graceful close", void 0, {
852
877
  F: __dxlog_file4,
853
- L: 347,
878
+ L: 368,
854
879
  S: this,
855
880
  C: (f, a) => f(...a)
856
881
  });
857
- await this.close();
882
+ await this.close(new Error("received peer close"));
858
883
  } else {
859
884
  (0, import_log5.log)("received close from peer, already closing", void 0, {
860
885
  F: __dxlog_file4,
861
- L: 350,
886
+ L: 371,
862
887
  S: this,
863
888
  C: (f, a) => f(...a)
864
889
  });
@@ -887,7 +912,7 @@ var Muxer = class {
887
912
  tag: stream.tag
888
913
  }, {
889
914
  F: __dxlog_file4,
890
- L: 379,
915
+ L: 400,
891
916
  S: this,
892
917
  C: (f, a) => f(...a)
893
918
  });
@@ -902,7 +927,7 @@ var Muxer = class {
902
927
  cmd
903
928
  }, {
904
929
  F: __dxlog_file4,
905
- L: 388,
930
+ L: 409,
906
931
  S: this,
907
932
  C: (f, a) => f(...a)
908
933
  });
@@ -950,7 +975,7 @@ var Muxer = class {
950
975
  threshold: MAX_SAFE_FRAME_SIZE
951
976
  }, {
952
977
  F: __dxlog_file4,
953
- L: 429,
978
+ L: 450,
954
979
  S: this,
955
980
  C: (f, a) => f(...a)
956
981
  });
@@ -1025,7 +1050,10 @@ var Muxer = class {
1025
1050
  this.statsUpdated.emit(this._lastStats);
1026
1051
  }
1027
1052
  };
1028
- function _ts_decorate(decorators, target, key, desc) {
1053
+ _ts_decorate([
1054
+ import_log5.logInfo
1055
+ ], Muxer.prototype, "sessionIdString", null);
1056
+ function _ts_decorate2(decorators, target, key, desc) {
1029
1057
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1030
1058
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1031
1059
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1045,7 +1073,7 @@ var Teleport = class {
1045
1073
  void this.destroy(err).catch(() => {
1046
1074
  import_log2.log.error("Error during destroy", err, {
1047
1075
  F: __dxlog_file5,
1048
- L: 38,
1076
+ L: 39,
1049
1077
  S: this,
1050
1078
  C: (f, a) => f(...a)
1051
1079
  });
@@ -1060,7 +1088,7 @@ var Teleport = class {
1060
1088
  this._aborting = false;
1061
1089
  (0, import_invariant2.invariant)(typeof initiator === "boolean", void 0, {
1062
1090
  F: __dxlog_file5,
1063
- L: 55,
1091
+ L: 56,
1064
1092
  S: this,
1065
1093
  A: [
1066
1094
  "typeof initiator === 'boolean'",
@@ -1069,7 +1097,7 @@ var Teleport = class {
1069
1097
  });
1070
1098
  (0, import_invariant2.invariant)(import_keys2.PublicKey.isPublicKey(localPeerId), void 0, {
1071
1099
  F: __dxlog_file5,
1072
- L: 56,
1100
+ L: 57,
1073
1101
  S: this,
1074
1102
  A: [
1075
1103
  "PublicKey.isPublicKey(localPeerId)",
@@ -1078,7 +1106,7 @@ var Teleport = class {
1078
1106
  });
1079
1107
  (0, import_invariant2.invariant)(import_keys2.PublicKey.isPublicKey(remotePeerId), void 0, {
1080
1108
  F: __dxlog_file5,
1081
- L: 57,
1109
+ L: 58,
1082
1110
  S: this,
1083
1111
  A: [
1084
1112
  "PublicKey.isPublicKey(remotePeerId)",
@@ -1097,13 +1125,13 @@ var Teleport = class {
1097
1125
  }
1098
1126
  import_log2.log.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1099
1127
  F: __dxlog_file5,
1100
- L: 70,
1128
+ L: 71,
1101
1129
  S: this,
1102
1130
  C: (f, a) => f(...a)
1103
1131
  });
1104
1132
  this.abort(new import_protocols.TimeoutError("control extension")).catch((err) => import_log2.log.catch(err, void 0, {
1105
1133
  F: __dxlog_file5,
1106
- L: 71,
1134
+ L: 72,
1107
1135
  S: this,
1108
1136
  C: (f, a) => f(...a)
1109
1137
  }));
@@ -1114,13 +1142,13 @@ var Teleport = class {
1114
1142
  name
1115
1143
  }, {
1116
1144
  F: __dxlog_file5,
1117
- L: 79,
1145
+ L: 80,
1118
1146
  S: this,
1119
1147
  C: (f, a) => f(...a)
1120
1148
  });
1121
1149
  (0, import_invariant2.invariant)(!this._remoteExtensions.has(name), "Remote extension already exists", {
1122
1150
  F: __dxlog_file5,
1123
- L: 80,
1151
+ L: 81,
1124
1152
  S: this,
1125
1153
  A: [
1126
1154
  "!this._remoteExtensions.has(name)",
@@ -1141,7 +1169,7 @@ var Teleport = class {
1141
1169
  if (this._destroying || this._aborting) {
1142
1170
  (0, import_log2.log)("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1143
1171
  F: __dxlog_file5,
1144
- L: 96,
1172
+ L: 97,
1145
1173
  S: this,
1146
1174
  C: (f, a) => f(...a)
1147
1175
  });
@@ -1164,12 +1192,15 @@ var Teleport = class {
1164
1192
  channels: stats.channels
1165
1193
  }, {
1166
1194
  F: __dxlog_file5,
1167
- L: 109,
1195
+ L: 110,
1168
1196
  S: this,
1169
1197
  C: (f, a) => f(...a)
1170
1198
  });
1171
1199
  });
1172
1200
  }
1201
+ get sessionIdString() {
1202
+ return this._sessionId ? this._sessionId.truncate() : "none";
1203
+ }
1173
1204
  get stream() {
1174
1205
  return this._muxer.stream;
1175
1206
  }
@@ -1179,10 +1210,18 @@ var Teleport = class {
1179
1210
  /**
1180
1211
  * Blocks until the handshake is complete.
1181
1212
  */
1182
- async open() {
1213
+ async open(sessionId = import_keys2.PublicKey.random()) {
1214
+ this._sessionId = sessionId;
1215
+ (0, import_log2.log)("open", void 0, {
1216
+ F: __dxlog_file5,
1217
+ L: 144,
1218
+ S: this,
1219
+ C: (f, a) => f(...a)
1220
+ });
1183
1221
  this._setExtension("dxos.mesh.teleport.control", this._control);
1184
1222
  await this._openExtension("dxos.mesh.teleport.control");
1185
1223
  this._open = true;
1224
+ this._muxer.setSessionId(sessionId);
1186
1225
  }
1187
1226
  async close(err) {
1188
1227
  await this.destroy(err);
@@ -1202,7 +1241,7 @@ var Teleport = class {
1202
1241
  } catch (err2) {
1203
1242
  import_log2.log.catch(err2, void 0, {
1204
1243
  F: __dxlog_file5,
1205
- L: 162,
1244
+ L: 173,
1206
1245
  S: this,
1207
1246
  C: (f, a) => f(...a)
1208
1247
  });
@@ -1225,7 +1264,7 @@ var Teleport = class {
1225
1264
  } catch (err2) {
1226
1265
  import_log2.log.catch(err2, void 0, {
1227
1266
  F: __dxlog_file5,
1228
- L: 186,
1267
+ L: 197,
1229
1268
  S: this,
1230
1269
  C: (f, a) => f(...a)
1231
1270
  });
@@ -1241,7 +1280,7 @@ var Teleport = class {
1241
1280
  name
1242
1281
  }, {
1243
1282
  F: __dxlog_file5,
1244
- L: 198,
1283
+ L: 209,
1245
1284
  S: this,
1246
1285
  C: (f, a) => f(...a)
1247
1286
  });
@@ -1265,7 +1304,7 @@ var Teleport = class {
1265
1304
  _setExtension(extensionName, extension) {
1266
1305
  (0, import_invariant2.invariant)(!extensionName.includes("/"), "Invalid extension name", {
1267
1306
  F: __dxlog_file5,
1268
- L: 222,
1307
+ L: 233,
1269
1308
  S: this,
1270
1309
  A: [
1271
1310
  "!extensionName.includes('/')",
@@ -1274,7 +1313,7 @@ var Teleport = class {
1274
1313
  });
1275
1314
  (0, import_invariant2.invariant)(!this._extensions.has(extensionName), "Extension already exists", {
1276
1315
  F: __dxlog_file5,
1277
- L: 223,
1316
+ L: 234,
1278
1317
  S: this,
1279
1318
  A: [
1280
1319
  "!this._extensions.has(extensionName)",
@@ -1288,7 +1327,7 @@ var Teleport = class {
1288
1327
  extensionName
1289
1328
  }, {
1290
1329
  F: __dxlog_file5,
1291
- L: 228,
1330
+ L: 239,
1292
1331
  S: this,
1293
1332
  C: (f, a) => f(...a)
1294
1333
  });
@@ -1300,7 +1339,7 @@ var Teleport = class {
1300
1339
  createPort: async (channelName, opts) => {
1301
1340
  (0, import_invariant2.invariant)(!channelName.includes("/"), "Invalid channel name", {
1302
1341
  F: __dxlog_file5,
1303
- L: 236,
1342
+ L: 247,
1304
1343
  S: this,
1305
1344
  A: [
1306
1345
  "!channelName.includes('/')",
@@ -1312,7 +1351,7 @@ var Teleport = class {
1312
1351
  createStream: async (channelName, opts) => {
1313
1352
  (0, import_invariant2.invariant)(!channelName.includes("/"), "Invalid channel name", {
1314
1353
  F: __dxlog_file5,
1315
- L: 240,
1354
+ L: 251,
1316
1355
  S: this,
1317
1356
  A: [
1318
1357
  "!channelName.includes('/')",
@@ -1332,16 +1371,19 @@ var Teleport = class {
1332
1371
  extensionName
1333
1372
  }, {
1334
1373
  F: __dxlog_file5,
1335
- L: 251,
1374
+ L: 262,
1336
1375
  S: this,
1337
1376
  C: (f, a) => f(...a)
1338
1377
  });
1339
1378
  }
1340
1379
  };
1341
- _ts_decorate([
1380
+ _ts_decorate2([
1381
+ import_log2.logInfo
1382
+ ], Teleport.prototype, "sessionIdString", null);
1383
+ _ts_decorate2([
1342
1384
  import_async.synchronized
1343
1385
  ], Teleport.prototype, "abort", null);
1344
- _ts_decorate([
1386
+ _ts_decorate2([
1345
1387
  import_async.synchronized
1346
1388
  ], Teleport.prototype, "destroy", null);
1347
1389
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
@@ -1486,7 +1528,7 @@ var TestPeer = class {
1486
1528
  ""
1487
1529
  ]
1488
1530
  });
1489
- await connection.teleport.open();
1531
+ await connection.teleport.open(import_keys.PublicKey.random());
1490
1532
  await this.onOpen(connection);
1491
1533
  }
1492
1534
  async closeConnection(connection) {
@@ -1907,4 +1949,4 @@ var TestExtensionWithStreams = class {
1907
1949
  decodeFrame,
1908
1950
  encodeFrame
1909
1951
  });
1910
- //# sourceMappingURL=chunk-GK3YA6TG.cjs.map
1952
+ //# sourceMappingURL=chunk-GVV33WCQ.cjs.map