@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.
@@ -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
  });
@@ -989,9 +1014,12 @@ var Muxer = class {
989
1014
  this.statsUpdated.emit(this._lastStats);
990
1015
  }
991
1016
  };
1017
+ _ts_decorate([
1018
+ logInfo
1019
+ ], Muxer.prototype, "sessionIdString", null);
992
1020
 
993
1021
  // packages/core/mesh/teleport/src/teleport.ts
994
- function _ts_decorate(decorators, target, key, desc) {
1022
+ function _ts_decorate2(decorators, target, key, desc) {
995
1023
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
996
1024
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
997
1025
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1011,7 +1039,7 @@ var Teleport = class {
1011
1039
  void this.destroy(err).catch(() => {
1012
1040
  log5.error("Error during destroy", err, {
1013
1041
  F: __dxlog_file5,
1014
- L: 38,
1042
+ L: 39,
1015
1043
  S: this,
1016
1044
  C: (f, a) => f(...a)
1017
1045
  });
@@ -1026,7 +1054,7 @@ var Teleport = class {
1026
1054
  this._aborting = false;
1027
1055
  invariant4(typeof initiator === "boolean", void 0, {
1028
1056
  F: __dxlog_file5,
1029
- L: 55,
1057
+ L: 56,
1030
1058
  S: this,
1031
1059
  A: [
1032
1060
  "typeof initiator === 'boolean'",
@@ -1035,7 +1063,7 @@ var Teleport = class {
1035
1063
  });
1036
1064
  invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1037
1065
  F: __dxlog_file5,
1038
- L: 56,
1066
+ L: 57,
1039
1067
  S: this,
1040
1068
  A: [
1041
1069
  "PublicKey.isPublicKey(localPeerId)",
@@ -1044,7 +1072,7 @@ var Teleport = class {
1044
1072
  });
1045
1073
  invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1046
1074
  F: __dxlog_file5,
1047
- L: 57,
1075
+ L: 58,
1048
1076
  S: this,
1049
1077
  A: [
1050
1078
  "PublicKey.isPublicKey(remotePeerId)",
@@ -1063,13 +1091,13 @@ var Teleport = class {
1063
1091
  }
1064
1092
  log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1065
1093
  F: __dxlog_file5,
1066
- L: 70,
1094
+ L: 71,
1067
1095
  S: this,
1068
1096
  C: (f, a) => f(...a)
1069
1097
  });
1070
1098
  this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1071
1099
  F: __dxlog_file5,
1072
- L: 71,
1100
+ L: 72,
1073
1101
  S: this,
1074
1102
  C: (f, a) => f(...a)
1075
1103
  }));
@@ -1080,13 +1108,13 @@ var Teleport = class {
1080
1108
  name
1081
1109
  }, {
1082
1110
  F: __dxlog_file5,
1083
- L: 79,
1111
+ L: 80,
1084
1112
  S: this,
1085
1113
  C: (f, a) => f(...a)
1086
1114
  });
1087
1115
  invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1088
1116
  F: __dxlog_file5,
1089
- L: 80,
1117
+ L: 81,
1090
1118
  S: this,
1091
1119
  A: [
1092
1120
  "!this._remoteExtensions.has(name)",
@@ -1107,7 +1135,7 @@ var Teleport = class {
1107
1135
  if (this._destroying || this._aborting) {
1108
1136
  log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1109
1137
  F: __dxlog_file5,
1110
- L: 96,
1138
+ L: 97,
1111
1139
  S: this,
1112
1140
  C: (f, a) => f(...a)
1113
1141
  });
@@ -1130,12 +1158,15 @@ var Teleport = class {
1130
1158
  channels: stats.channels
1131
1159
  }, {
1132
1160
  F: __dxlog_file5,
1133
- L: 109,
1161
+ L: 110,
1134
1162
  S: this,
1135
1163
  C: (f, a) => f(...a)
1136
1164
  });
1137
1165
  });
1138
1166
  }
1167
+ get sessionIdString() {
1168
+ return this._sessionId ? this._sessionId.truncate() : "none";
1169
+ }
1139
1170
  get stream() {
1140
1171
  return this._muxer.stream;
1141
1172
  }
@@ -1145,10 +1176,18 @@ var Teleport = class {
1145
1176
  /**
1146
1177
  * Blocks until the handshake is complete.
1147
1178
  */
1148
- 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
+ });
1149
1187
  this._setExtension("dxos.mesh.teleport.control", this._control);
1150
1188
  await this._openExtension("dxos.mesh.teleport.control");
1151
1189
  this._open = true;
1190
+ this._muxer.setSessionId(sessionId);
1152
1191
  }
1153
1192
  async close(err) {
1154
1193
  await this.destroy(err);
@@ -1168,7 +1207,7 @@ var Teleport = class {
1168
1207
  } catch (err2) {
1169
1208
  log5.catch(err2, void 0, {
1170
1209
  F: __dxlog_file5,
1171
- L: 162,
1210
+ L: 173,
1172
1211
  S: this,
1173
1212
  C: (f, a) => f(...a)
1174
1213
  });
@@ -1191,7 +1230,7 @@ var Teleport = class {
1191
1230
  } catch (err2) {
1192
1231
  log5.catch(err2, void 0, {
1193
1232
  F: __dxlog_file5,
1194
- L: 186,
1233
+ L: 197,
1195
1234
  S: this,
1196
1235
  C: (f, a) => f(...a)
1197
1236
  });
@@ -1207,7 +1246,7 @@ var Teleport = class {
1207
1246
  name
1208
1247
  }, {
1209
1248
  F: __dxlog_file5,
1210
- L: 198,
1249
+ L: 209,
1211
1250
  S: this,
1212
1251
  C: (f, a) => f(...a)
1213
1252
  });
@@ -1231,7 +1270,7 @@ var Teleport = class {
1231
1270
  _setExtension(extensionName, extension) {
1232
1271
  invariant4(!extensionName.includes("/"), "Invalid extension name", {
1233
1272
  F: __dxlog_file5,
1234
- L: 222,
1273
+ L: 233,
1235
1274
  S: this,
1236
1275
  A: [
1237
1276
  "!extensionName.includes('/')",
@@ -1240,7 +1279,7 @@ var Teleport = class {
1240
1279
  });
1241
1280
  invariant4(!this._extensions.has(extensionName), "Extension already exists", {
1242
1281
  F: __dxlog_file5,
1243
- L: 223,
1282
+ L: 234,
1244
1283
  S: this,
1245
1284
  A: [
1246
1285
  "!this._extensions.has(extensionName)",
@@ -1254,7 +1293,7 @@ var Teleport = class {
1254
1293
  extensionName
1255
1294
  }, {
1256
1295
  F: __dxlog_file5,
1257
- L: 228,
1296
+ L: 239,
1258
1297
  S: this,
1259
1298
  C: (f, a) => f(...a)
1260
1299
  });
@@ -1266,7 +1305,7 @@ var Teleport = class {
1266
1305
  createPort: async (channelName, opts) => {
1267
1306
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1268
1307
  F: __dxlog_file5,
1269
- L: 236,
1308
+ L: 247,
1270
1309
  S: this,
1271
1310
  A: [
1272
1311
  "!channelName.includes('/')",
@@ -1278,7 +1317,7 @@ var Teleport = class {
1278
1317
  createStream: async (channelName, opts) => {
1279
1318
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1280
1319
  F: __dxlog_file5,
1281
- L: 240,
1320
+ L: 251,
1282
1321
  S: this,
1283
1322
  A: [
1284
1323
  "!channelName.includes('/')",
@@ -1298,16 +1337,19 @@ var Teleport = class {
1298
1337
  extensionName
1299
1338
  }, {
1300
1339
  F: __dxlog_file5,
1301
- L: 251,
1340
+ L: 262,
1302
1341
  S: this,
1303
1342
  C: (f, a) => f(...a)
1304
1343
  });
1305
1344
  }
1306
1345
  };
1307
- _ts_decorate([
1346
+ _ts_decorate2([
1347
+ logInfo2
1348
+ ], Teleport.prototype, "sessionIdString", null);
1349
+ _ts_decorate2([
1308
1350
  synchronized
1309
1351
  ], Teleport.prototype, "abort", null);
1310
- _ts_decorate([
1352
+ _ts_decorate2([
1311
1353
  synchronized
1312
1354
  ], Teleport.prototype, "destroy", null);
1313
1355
 
@@ -1454,7 +1496,7 @@ var TestPeer = class {
1454
1496
  ""
1455
1497
  ]
1456
1498
  });
1457
- await connection.teleport.open();
1499
+ await connection.teleport.open(PublicKey2.random());
1458
1500
  await this.onOpen(connection);
1459
1501
  }
1460
1502
  async closeConnection(connection) {
@@ -1890,4 +1932,4 @@ export {
1890
1932
  TestExtension,
1891
1933
  TestExtensionWithStreams
1892
1934
  };
1893
- //# sourceMappingURL=chunk-2FV5BKLH.mjs.map
1935
+ //# sourceMappingURL=chunk-M7U4KJA7.mjs.map