@dxos/teleport 0.8.4-main.5ea62a8 → 0.8.4-main.72ec0f3

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.
@@ -132,23 +132,29 @@ import { RpcClosedError } from "@dxos/protocols";
132
132
  import { schema } from "@dxos/protocols/proto";
133
133
  import { createProtoRpcPeer } from "@dxos/rpc";
134
134
  import { Callback } from "@dxos/util";
135
- function _define_property(obj, key, value) {
136
- if (key in obj) {
137
- Object.defineProperty(obj, key, {
138
- value,
139
- enumerable: true,
140
- configurable: true,
141
- writable: true
142
- });
143
- } else {
144
- obj[key] = value;
145
- }
146
- return obj;
147
- }
148
135
  var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/teleport/src/control-extension.ts";
149
136
  var HEARTBEAT_RTT_WARN_THRESH = 1e4;
150
137
  var DEBUG_PRINT_HEARTBEAT = false;
151
138
  var ControlExtension = class {
139
+ opts;
140
+ localPeerId;
141
+ remotePeerId;
142
+ _ctx = new Context({
143
+ onError: (err) => {
144
+ this._extensionContext.close(err);
145
+ }
146
+ }, {
147
+ F: __dxlog_file,
148
+ L: 31
149
+ });
150
+ onExtensionRegistered = new Callback();
151
+ _extensionContext;
152
+ _rpc;
153
+ constructor(opts, localPeerId, remotePeerId) {
154
+ this.opts = opts;
155
+ this.localPeerId = localPeerId;
156
+ this.remotePeerId = remotePeerId;
157
+ }
152
158
  async registerExtension(name) {
153
159
  await this._rpc.rpc.Control.registerExtension({
154
160
  name
@@ -273,27 +279,6 @@ var ControlExtension = class {
273
279
  await this._ctx.dispose();
274
280
  await this._rpc.abort();
275
281
  }
276
- constructor(opts, localPeerId, remotePeerId) {
277
- _define_property(this, "opts", void 0);
278
- _define_property(this, "localPeerId", void 0);
279
- _define_property(this, "remotePeerId", void 0);
280
- _define_property(this, "_ctx", void 0);
281
- _define_property(this, "onExtensionRegistered", void 0);
282
- _define_property(this, "_extensionContext", void 0);
283
- _define_property(this, "_rpc", void 0);
284
- this.opts = opts;
285
- this.localPeerId = localPeerId;
286
- this.remotePeerId = remotePeerId;
287
- this._ctx = new Context({
288
- onError: (err) => {
289
- this._extensionContext.close(err);
290
- }
291
- }, {
292
- F: __dxlog_file,
293
- L: 31
294
- });
295
- this.onExtensionRegistered = new Callback();
296
- }
297
282
  };
298
283
 
299
284
  // src/muxing/framer.ts
@@ -301,22 +286,85 @@ import { Duplex } from "@dxos/node-std/stream";
301
286
  import { Event } from "@dxos/async";
302
287
  import { invariant } from "@dxos/invariant";
303
288
  import { log as log2 } from "@dxos/log";
304
- function _define_property2(obj, key, value) {
305
- if (key in obj) {
306
- Object.defineProperty(obj, key, {
307
- value,
308
- enumerable: true,
309
- configurable: true,
310
- writable: true
311
- });
312
- } else {
313
- obj[key] = value;
314
- }
315
- return obj;
316
- }
317
289
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/muxing/framer.ts";
318
290
  var FRAME_LENGTH_SIZE = 2;
319
291
  var Framer = class {
292
+ // private readonly _tagBuffer = Buffer.alloc(4)
293
+ _messageCb = void 0;
294
+ _subscribeCb = void 0;
295
+ _buffer = void 0;
296
+ _sendCallbacks = [];
297
+ _bytesSent = 0;
298
+ _bytesReceived = 0;
299
+ _writable = true;
300
+ drain = new Event();
301
+ // TODO(egorgripasov): Consider using a Transform stream if it provides better backpressure handling.
302
+ _stream = new Duplex({
303
+ objectMode: false,
304
+ read: () => {
305
+ this._processResponseQueue();
306
+ },
307
+ write: (chunk, encoding, callback) => {
308
+ invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.", {
309
+ F: __dxlog_file2,
310
+ L: 40,
311
+ S: this,
312
+ A: [
313
+ "!this._subscribeCb",
314
+ "'Internal Framer bug. Concurrent writes detected.'"
315
+ ]
316
+ });
317
+ this._bytesReceived += chunk.length;
318
+ if (this._buffer && this._buffer.length > 0) {
319
+ this._buffer = Buffer.concat([
320
+ this._buffer,
321
+ chunk
322
+ ]);
323
+ } else {
324
+ this._buffer = chunk;
325
+ }
326
+ if (this._messageCb) {
327
+ this._popFrames();
328
+ callback();
329
+ } else {
330
+ this._subscribeCb = () => {
331
+ this._popFrames();
332
+ this._subscribeCb = void 0;
333
+ callback();
334
+ };
335
+ }
336
+ }
337
+ });
338
+ port = {
339
+ send: (message) => {
340
+ return new Promise((resolve) => {
341
+ const frame = encodeFrame(message);
342
+ this._bytesSent += frame.length;
343
+ this._writable = this._stream.push(frame);
344
+ if (!this._writable) {
345
+ this._sendCallbacks.push(resolve);
346
+ } else {
347
+ resolve();
348
+ }
349
+ });
350
+ },
351
+ subscribe: (callback) => {
352
+ invariant(!this._messageCb, "Rpc port already has a message listener.", {
353
+ F: __dxlog_file2,
354
+ L: 79,
355
+ S: this,
356
+ A: [
357
+ "!this._messageCb",
358
+ "'Rpc port already has a message listener.'"
359
+ ]
360
+ });
361
+ this._messageCb = callback;
362
+ this._subscribeCb?.();
363
+ return () => {
364
+ this._messageCb = void 0;
365
+ };
366
+ }
367
+ };
320
368
  get stream() {
321
369
  return this._stream;
322
370
  }
@@ -374,82 +422,6 @@ var Framer = class {
374
422
  }
375
423
  this._stream.destroy();
376
424
  }
377
- constructor() {
378
- _define_property2(this, "_messageCb", void 0);
379
- _define_property2(this, "_subscribeCb", void 0);
380
- _define_property2(this, "_buffer", void 0);
381
- _define_property2(this, "_sendCallbacks", []);
382
- _define_property2(this, "_bytesSent", 0);
383
- _define_property2(this, "_bytesReceived", 0);
384
- _define_property2(this, "_writable", true);
385
- _define_property2(this, "drain", new Event());
386
- _define_property2(this, "_stream", new Duplex({
387
- objectMode: false,
388
- read: () => {
389
- this._processResponseQueue();
390
- },
391
- write: (chunk, encoding, callback) => {
392
- invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.", {
393
- F: __dxlog_file2,
394
- L: 40,
395
- S: this,
396
- A: [
397
- "!this._subscribeCb",
398
- "'Internal Framer bug. Concurrent writes detected.'"
399
- ]
400
- });
401
- this._bytesReceived += chunk.length;
402
- if (this._buffer && this._buffer.length > 0) {
403
- this._buffer = Buffer.concat([
404
- this._buffer,
405
- chunk
406
- ]);
407
- } else {
408
- this._buffer = chunk;
409
- }
410
- if (this._messageCb) {
411
- this._popFrames();
412
- callback();
413
- } else {
414
- this._subscribeCb = () => {
415
- this._popFrames();
416
- this._subscribeCb = void 0;
417
- callback();
418
- };
419
- }
420
- }
421
- }));
422
- _define_property2(this, "port", {
423
- send: (message) => {
424
- return new Promise((resolve) => {
425
- const frame = encodeFrame(message);
426
- this._bytesSent += frame.length;
427
- this._writable = this._stream.push(frame);
428
- if (!this._writable) {
429
- this._sendCallbacks.push(resolve);
430
- } else {
431
- resolve();
432
- }
433
- });
434
- },
435
- subscribe: (callback) => {
436
- invariant(!this._messageCb, "Rpc port already has a message listener.", {
437
- F: __dxlog_file2,
438
- L: 79,
439
- S: this,
440
- A: [
441
- "!this._messageCb",
442
- "'Rpc port already has a message listener.'"
443
- ]
444
- });
445
- this._messageCb = callback;
446
- this._subscribeCb?.();
447
- return () => {
448
- this._messageCb = void 0;
449
- };
450
- }
451
- });
452
- }
453
425
  };
454
426
  var decodeFrame = (buffer, offset) => {
455
427
  if (buffer.length < offset + FRAME_LENGTH_SIZE) {
@@ -488,22 +460,24 @@ var import_varint = __toESM(require_varint(), 1);
488
460
  import { Event as Event2 } from "@dxos/async";
489
461
  import { invariant as invariant2 } from "@dxos/invariant";
490
462
  import { log as log3 } from "@dxos/log";
491
- function _define_property3(obj, key, value) {
492
- if (key in obj) {
493
- Object.defineProperty(obj, key, {
494
- value,
495
- enumerable: true,
496
- configurable: true,
497
- writable: true
498
- });
499
- } else {
500
- obj[key] = value;
501
- }
502
- return obj;
503
- }
504
463
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
505
464
  var MAX_CHUNK_SIZE = 8192;
506
465
  var Balancer = class {
466
+ _sysChannelId;
467
+ _lastCallerIndex = 0;
468
+ _channels = [];
469
+ _framer = new Framer();
470
+ // TODO(egorgripasov): Will cause a memory leak if channels do not appreciate the backpressure.
471
+ _sendBuffers = /* @__PURE__ */ new Map();
472
+ _receiveBuffers = /* @__PURE__ */ new Map();
473
+ _sending = false;
474
+ incomingData = new Event2();
475
+ stream = this._framer.stream;
476
+ constructor(_sysChannelId) {
477
+ this._sysChannelId = _sysChannelId;
478
+ this._channels.push(_sysChannelId);
479
+ this._framer.port.subscribe(this._processIncomingMessage.bind(this));
480
+ }
507
481
  get bytesSent() {
508
482
  return this._framer.bytesSent;
509
483
  }
@@ -664,28 +638,6 @@ var Balancer = class {
664
638
  });
665
639
  this._sending = false;
666
640
  }
667
- constructor(_sysChannelId) {
668
- _define_property3(this, "_sysChannelId", void 0);
669
- _define_property3(this, "_lastCallerIndex", void 0);
670
- _define_property3(this, "_channels", void 0);
671
- _define_property3(this, "_framer", void 0);
672
- _define_property3(this, "_sendBuffers", void 0);
673
- _define_property3(this, "_receiveBuffers", void 0);
674
- _define_property3(this, "_sending", void 0);
675
- _define_property3(this, "incomingData", void 0);
676
- _define_property3(this, "stream", void 0);
677
- this._sysChannelId = _sysChannelId;
678
- this._lastCallerIndex = 0;
679
- this._channels = [];
680
- this._framer = new Framer();
681
- this._sendBuffers = /* @__PURE__ */ new Map();
682
- this._receiveBuffers = /* @__PURE__ */ new Map();
683
- this._sending = false;
684
- this.incomingData = new Event2();
685
- this.stream = this._framer.stream;
686
- this._channels.push(_sysChannelId);
687
- this._framer.port.subscribe(this._processIncomingMessage.bind(this));
688
- }
689
641
  };
690
642
  var encodeChunk = ({ channelId, dataLength, chunk }) => {
691
643
  const channelTagLength = import_varint.default.encodingLength(channelId);
@@ -715,19 +667,6 @@ var decodeChunk = (data, withLength) => {
715
667
  };
716
668
 
717
669
  // src/muxing/muxer.ts
718
- function _define_property4(obj, key, value) {
719
- if (key in obj) {
720
- Object.defineProperty(obj, key, {
721
- value,
722
- enumerable: true,
723
- configurable: true,
724
- writable: true
725
- });
726
- } else {
727
- obj[key] = value;
728
- }
729
- return obj;
730
- }
731
670
  function _ts_decorate(decorators, target, key, desc) {
732
671
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
733
672
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -743,6 +682,28 @@ var MAX_SAFE_FRAME_SIZE = 1e6;
743
682
  var SYSTEM_CHANNEL_ID = 0;
744
683
  var GRACEFUL_CLOSE_TIMEOUT = 3e3;
745
684
  var Muxer = class {
685
+ _balancer = new Balancer(SYSTEM_CHANNEL_ID);
686
+ _channelsByLocalId = /* @__PURE__ */ new Map();
687
+ _channelsByTag = /* @__PURE__ */ new Map();
688
+ _ctx = new Context2(void 0, {
689
+ F: __dxlog_file4,
690
+ L: 108
691
+ });
692
+ _sessionId;
693
+ _nextId = 1;
694
+ _closing = false;
695
+ _destroying = false;
696
+ _disposed = false;
697
+ _lastStats = void 0;
698
+ _lastChannelStats = /* @__PURE__ */ new Map();
699
+ afterClosed = new Event3();
700
+ statsUpdated = new Event3();
701
+ stream = this._balancer.stream;
702
+ constructor() {
703
+ this._balancer.incomingData.on(async (msg) => {
704
+ await this._handleCommand(Command.decode(msg));
705
+ });
706
+ }
746
707
  setSessionId(sessionId) {
747
708
  this._sessionId = sessionId;
748
709
  }
@@ -1170,47 +1131,12 @@ var Muxer = class {
1170
1131
  };
1171
1132
  this.statsUpdated.emit(this._lastStats);
1172
1133
  }
1173
- constructor() {
1174
- _define_property4(this, "_balancer", new Balancer(SYSTEM_CHANNEL_ID));
1175
- _define_property4(this, "_channelsByLocalId", /* @__PURE__ */ new Map());
1176
- _define_property4(this, "_channelsByTag", /* @__PURE__ */ new Map());
1177
- _define_property4(this, "_ctx", new Context2(void 0, {
1178
- F: __dxlog_file4,
1179
- L: 108
1180
- }));
1181
- _define_property4(this, "_sessionId", void 0);
1182
- _define_property4(this, "_nextId", 1);
1183
- _define_property4(this, "_closing", false);
1184
- _define_property4(this, "_destroying", false);
1185
- _define_property4(this, "_disposed", false);
1186
- _define_property4(this, "_lastStats", void 0);
1187
- _define_property4(this, "_lastChannelStats", /* @__PURE__ */ new Map());
1188
- _define_property4(this, "afterClosed", new Event3());
1189
- _define_property4(this, "statsUpdated", new Event3());
1190
- _define_property4(this, "stream", this._balancer.stream);
1191
- this._balancer.incomingData.on(async (msg) => {
1192
- await this._handleCommand(Command.decode(msg));
1193
- });
1194
- }
1195
1134
  };
1196
1135
  _ts_decorate([
1197
1136
  logInfo
1198
1137
  ], Muxer.prototype, "sessionIdString", null);
1199
1138
 
1200
1139
  // src/teleport.ts
1201
- function _define_property5(obj, key, value) {
1202
- if (key in obj) {
1203
- Object.defineProperty(obj, key, {
1204
- value,
1205
- enumerable: true,
1206
- configurable: true,
1207
- writable: true
1208
- });
1209
- } else {
1210
- obj[key] = value;
1211
- }
1212
- return obj;
1213
- }
1214
1140
  function _ts_decorate2(decorators, target, key, desc) {
1215
1141
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1216
1142
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1221,9 +1147,156 @@ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts"
1221
1147
  var CONTROL_HEARTBEAT_INTERVAL = 1e4;
1222
1148
  var CONTROL_HEARTBEAT_TIMEOUT = 6e4;
1223
1149
  var Teleport = class {
1150
+ initiator;
1151
+ localPeerId;
1152
+ remotePeerId;
1153
+ _sessionId;
1154
+ _ctx = new Context3({
1155
+ onError: (err) => {
1156
+ log5.info("error in teleport context", {
1157
+ err
1158
+ }, {
1159
+ F: __dxlog_file5,
1160
+ L: 40,
1161
+ S: this,
1162
+ C: (f, a) => f(...a)
1163
+ });
1164
+ void this.destroy(err).catch(() => {
1165
+ log5.error("Error during destroy", err, {
1166
+ F: __dxlog_file5,
1167
+ L: 42,
1168
+ S: this,
1169
+ C: (f, a) => f(...a)
1170
+ });
1171
+ });
1172
+ }
1173
+ }, {
1174
+ F: __dxlog_file5,
1175
+ L: 38
1176
+ });
1177
+ _muxer = new Muxer();
1178
+ _control;
1179
+ _extensions = /* @__PURE__ */ new Map();
1180
+ _remoteExtensions = /* @__PURE__ */ new Set();
1181
+ _open = false;
1182
+ _destroying = false;
1183
+ _aborting = false;
1224
1184
  get isOpen() {
1225
1185
  return this._open;
1226
1186
  }
1187
+ constructor({ initiator, localPeerId, remotePeerId, ...rest }) {
1188
+ invariant4(typeof initiator === "boolean", void 0, {
1189
+ F: __dxlog_file5,
1190
+ L: 63,
1191
+ S: this,
1192
+ A: [
1193
+ "typeof initiator === 'boolean'",
1194
+ ""
1195
+ ]
1196
+ });
1197
+ invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1198
+ F: __dxlog_file5,
1199
+ L: 64,
1200
+ S: this,
1201
+ A: [
1202
+ "PublicKey.isPublicKey(localPeerId)",
1203
+ ""
1204
+ ]
1205
+ });
1206
+ invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1207
+ F: __dxlog_file5,
1208
+ L: 65,
1209
+ S: this,
1210
+ A: [
1211
+ "PublicKey.isPublicKey(remotePeerId)",
1212
+ ""
1213
+ ]
1214
+ });
1215
+ this.initiator = initiator;
1216
+ this.localPeerId = localPeerId;
1217
+ this.remotePeerId = remotePeerId;
1218
+ this._control = new ControlExtension({
1219
+ heartbeatInterval: rest.controlHeartbeatInterval ?? CONTROL_HEARTBEAT_INTERVAL,
1220
+ heartbeatTimeout: rest.controlHeartbeatTimeout ?? CONTROL_HEARTBEAT_TIMEOUT,
1221
+ onTimeout: () => {
1222
+ if (this._destroying || this._aborting) {
1223
+ return;
1224
+ }
1225
+ log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1226
+ F: __dxlog_file5,
1227
+ L: 78,
1228
+ S: this,
1229
+ C: (f, a) => f(...a)
1230
+ });
1231
+ this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1232
+ F: __dxlog_file5,
1233
+ L: 79,
1234
+ S: this,
1235
+ C: (f, a) => f(...a)
1236
+ }));
1237
+ }
1238
+ }, this.localPeerId, this.remotePeerId);
1239
+ this._control.onExtensionRegistered.set(async (name) => {
1240
+ log5("remote extension", {
1241
+ name
1242
+ }, {
1243
+ F: __dxlog_file5,
1244
+ L: 87,
1245
+ S: this,
1246
+ C: (f, a) => f(...a)
1247
+ });
1248
+ invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1249
+ F: __dxlog_file5,
1250
+ L: 88,
1251
+ S: this,
1252
+ A: [
1253
+ "!this._remoteExtensions.has(name)",
1254
+ "'Remote extension already exists'"
1255
+ ]
1256
+ });
1257
+ this._remoteExtensions.add(name);
1258
+ if (this._extensions.has(name)) {
1259
+ try {
1260
+ await this._openExtension(name);
1261
+ } catch (err) {
1262
+ await this.destroy(err);
1263
+ }
1264
+ }
1265
+ });
1266
+ {
1267
+ this._muxer.stream.on("close", async () => {
1268
+ if (this._destroying || this._aborting) {
1269
+ log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1270
+ F: __dxlog_file5,
1271
+ L: 104,
1272
+ S: this,
1273
+ C: (f, a) => f(...a)
1274
+ });
1275
+ return;
1276
+ }
1277
+ await this.destroy();
1278
+ });
1279
+ this._muxer.stream.on("error", async (err) => {
1280
+ await this.destroy(err);
1281
+ });
1282
+ }
1283
+ this._muxer.statsUpdated.on((stats) => {
1284
+ log5.trace("dxos.mesh.teleport.stats", {
1285
+ localPeerId,
1286
+ remotePeerId,
1287
+ bytesSent: stats.bytesSent,
1288
+ bytesSentRate: stats.bytesSentRate,
1289
+ bytesReceived: stats.bytesReceived,
1290
+ bytesReceivedRate: stats.bytesReceivedRate,
1291
+ channels: stats.channels
1292
+ }, {
1293
+ F: __dxlog_file5,
1294
+ L: 117,
1295
+ S: this,
1296
+ C: (f, a) => f(...a)
1297
+ });
1298
+ });
1299
+ }
1227
1300
  get sessionIdString() {
1228
1301
  return this._sessionId ? this._sessionId.truncate() : "none";
1229
1302
  }
@@ -1434,153 +1507,6 @@ var Teleport = class {
1434
1507
  C: (f, a) => f(...a)
1435
1508
  });
1436
1509
  }
1437
- constructor({ initiator, localPeerId, remotePeerId, ...rest }) {
1438
- _define_property5(this, "initiator", void 0);
1439
- _define_property5(this, "localPeerId", void 0);
1440
- _define_property5(this, "remotePeerId", void 0);
1441
- _define_property5(this, "_sessionId", void 0);
1442
- _define_property5(this, "_ctx", new Context3({
1443
- onError: (err) => {
1444
- log5.info("error in teleport context", {
1445
- err
1446
- }, {
1447
- F: __dxlog_file5,
1448
- L: 40,
1449
- S: this,
1450
- C: (f, a) => f(...a)
1451
- });
1452
- void this.destroy(err).catch(() => {
1453
- log5.error("Error during destroy", err, {
1454
- F: __dxlog_file5,
1455
- L: 42,
1456
- S: this,
1457
- C: (f, a) => f(...a)
1458
- });
1459
- });
1460
- }
1461
- }, {
1462
- F: __dxlog_file5,
1463
- L: 38
1464
- }));
1465
- _define_property5(this, "_muxer", new Muxer());
1466
- _define_property5(this, "_control", void 0);
1467
- _define_property5(this, "_extensions", /* @__PURE__ */ new Map());
1468
- _define_property5(this, "_remoteExtensions", /* @__PURE__ */ new Set());
1469
- _define_property5(this, "_open", false);
1470
- _define_property5(this, "_destroying", false);
1471
- _define_property5(this, "_aborting", false);
1472
- invariant4(typeof initiator === "boolean", void 0, {
1473
- F: __dxlog_file5,
1474
- L: 63,
1475
- S: this,
1476
- A: [
1477
- "typeof initiator === 'boolean'",
1478
- ""
1479
- ]
1480
- });
1481
- invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1482
- F: __dxlog_file5,
1483
- L: 64,
1484
- S: this,
1485
- A: [
1486
- "PublicKey.isPublicKey(localPeerId)",
1487
- ""
1488
- ]
1489
- });
1490
- invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1491
- F: __dxlog_file5,
1492
- L: 65,
1493
- S: this,
1494
- A: [
1495
- "PublicKey.isPublicKey(remotePeerId)",
1496
- ""
1497
- ]
1498
- });
1499
- this.initiator = initiator;
1500
- this.localPeerId = localPeerId;
1501
- this.remotePeerId = remotePeerId;
1502
- this._control = new ControlExtension({
1503
- heartbeatInterval: rest.controlHeartbeatInterval ?? CONTROL_HEARTBEAT_INTERVAL,
1504
- heartbeatTimeout: rest.controlHeartbeatTimeout ?? CONTROL_HEARTBEAT_TIMEOUT,
1505
- onTimeout: () => {
1506
- if (this._destroying || this._aborting) {
1507
- return;
1508
- }
1509
- log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1510
- F: __dxlog_file5,
1511
- L: 78,
1512
- S: this,
1513
- C: (f, a) => f(...a)
1514
- });
1515
- this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1516
- F: __dxlog_file5,
1517
- L: 79,
1518
- S: this,
1519
- C: (f, a) => f(...a)
1520
- }));
1521
- }
1522
- }, this.localPeerId, this.remotePeerId);
1523
- this._control.onExtensionRegistered.set(async (name) => {
1524
- log5("remote extension", {
1525
- name
1526
- }, {
1527
- F: __dxlog_file5,
1528
- L: 87,
1529
- S: this,
1530
- C: (f, a) => f(...a)
1531
- });
1532
- invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1533
- F: __dxlog_file5,
1534
- L: 88,
1535
- S: this,
1536
- A: [
1537
- "!this._remoteExtensions.has(name)",
1538
- "'Remote extension already exists'"
1539
- ]
1540
- });
1541
- this._remoteExtensions.add(name);
1542
- if (this._extensions.has(name)) {
1543
- try {
1544
- await this._openExtension(name);
1545
- } catch (err) {
1546
- await this.destroy(err);
1547
- }
1548
- }
1549
- });
1550
- {
1551
- this._muxer.stream.on("close", async () => {
1552
- if (this._destroying || this._aborting) {
1553
- log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1554
- F: __dxlog_file5,
1555
- L: 104,
1556
- S: this,
1557
- C: (f, a) => f(...a)
1558
- });
1559
- return;
1560
- }
1561
- await this.destroy();
1562
- });
1563
- this._muxer.stream.on("error", async (err) => {
1564
- await this.destroy(err);
1565
- });
1566
- }
1567
- this._muxer.statsUpdated.on((stats) => {
1568
- log5.trace("dxos.mesh.teleport.stats", {
1569
- localPeerId,
1570
- remotePeerId,
1571
- bytesSent: stats.bytesSent,
1572
- bytesSentRate: stats.bytesSentRate,
1573
- bytesReceived: stats.bytesReceived,
1574
- bytesReceivedRate: stats.bytesReceivedRate,
1575
- channels: stats.channels
1576
- }, {
1577
- F: __dxlog_file5,
1578
- L: 117,
1579
- S: this,
1580
- C: (f, a) => f(...a)
1581
- });
1582
- });
1583
- }
1584
1510
  };
1585
1511
  _ts_decorate2([
1586
1512
  logInfo2
@@ -1593,21 +1519,9 @@ _ts_decorate2([
1593
1519
  ], Teleport.prototype, "destroy", null);
1594
1520
 
1595
1521
  // src/testing/test-builder.ts
1596
- function _define_property6(obj, key, value) {
1597
- if (key in obj) {
1598
- Object.defineProperty(obj, key, {
1599
- value,
1600
- enumerable: true,
1601
- configurable: true,
1602
- writable: true
1603
- });
1604
- } else {
1605
- obj[key] = value;
1606
- }
1607
- return obj;
1608
- }
1609
1522
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
1610
1523
  var TestBuilder = class {
1524
+ _peers = /* @__PURE__ */ new Set();
1611
1525
  createPeer(opts) {
1612
1526
  const peer = opts.factory();
1613
1527
  this._peers.add(peer);
@@ -1720,11 +1634,13 @@ var TestBuilder = class {
1720
1634
  peer2.closeConnection(connection2)
1721
1635
  ]);
1722
1636
  }
1723
- constructor() {
1724
- _define_property6(this, "_peers", /* @__PURE__ */ new Set());
1725
- }
1726
1637
  };
1727
1638
  var TestPeer = class {
1639
+ peerId;
1640
+ connections = /* @__PURE__ */ new Set();
1641
+ constructor(peerId = PublicKey2.random()) {
1642
+ this.peerId = peerId;
1643
+ }
1728
1644
  async onOpen(connection) {
1729
1645
  }
1730
1646
  async onClose(connection) {
@@ -1766,12 +1682,6 @@ var TestPeer = class {
1766
1682
  await this.closeConnection(teleport);
1767
1683
  }
1768
1684
  }
1769
- constructor(peerId = PublicKey2.random()) {
1770
- _define_property6(this, "peerId", void 0);
1771
- _define_property6(this, "connections", void 0);
1772
- this.peerId = peerId;
1773
- this.connections = /* @__PURE__ */ new Set();
1774
- }
1775
1685
  };
1776
1686
  var pipeStreams = (stream1, stream2) => {
1777
1687
  pipeline(stream1, stream2, (err) => {
@@ -1796,16 +1706,11 @@ var pipeStreams = (stream1, stream2) => {
1796
1706
  });
1797
1707
  };
1798
1708
  var TestConnection = class {
1799
- whenOpen(open) {
1800
- return waitForCondition({
1801
- condition: () => this.teleport.isOpen === open
1802
- });
1803
- }
1709
+ localPeerId;
1710
+ remotePeerId;
1711
+ initiator;
1712
+ teleport;
1804
1713
  constructor(localPeerId, remotePeerId, initiator) {
1805
- _define_property6(this, "localPeerId", void 0);
1806
- _define_property6(this, "remotePeerId", void 0);
1807
- _define_property6(this, "initiator", void 0);
1808
- _define_property6(this, "teleport", void 0);
1809
1714
  this.localPeerId = localPeerId;
1810
1715
  this.remotePeerId = remotePeerId;
1811
1716
  this.initiator = initiator;
@@ -1815,6 +1720,11 @@ var TestConnection = class {
1815
1720
  remotePeerId
1816
1721
  });
1817
1722
  }
1723
+ whenOpen(open) {
1724
+ return waitForCondition({
1725
+ condition: () => this.teleport.isOpen === open
1726
+ });
1727
+ }
1818
1728
  };
1819
1729
 
1820
1730
  // src/testing/test-extension.ts
@@ -1823,21 +1733,17 @@ import { invariant as invariant6 } from "@dxos/invariant";
1823
1733
  import { log as log7 } from "@dxos/log";
1824
1734
  import { schema as schema3 } from "@dxos/protocols/proto";
1825
1735
  import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
1826
- function _define_property7(obj, key, value) {
1827
- if (key in obj) {
1828
- Object.defineProperty(obj, key, {
1829
- value,
1830
- enumerable: true,
1831
- configurable: true,
1832
- writable: true
1833
- });
1834
- } else {
1835
- obj[key] = value;
1836
- }
1837
- return obj;
1838
- }
1839
1736
  var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
1840
1737
  var TestExtension = class {
1738
+ callbacks;
1739
+ open = new Trigger2();
1740
+ closed = new Trigger2();
1741
+ aborted = new Trigger2();
1742
+ extensionContext;
1743
+ _rpc;
1744
+ constructor(callbacks = {}) {
1745
+ this.callbacks = callbacks;
1746
+ }
1841
1747
  get remotePeerId() {
1842
1748
  return this.extensionContext?.remotePeerId;
1843
1749
  }
@@ -1928,18 +1834,6 @@ var TestExtension = class {
1928
1834
  async closeConnection(err) {
1929
1835
  this.extensionContext?.close(err);
1930
1836
  }
1931
- constructor(callbacks = {}) {
1932
- _define_property7(this, "callbacks", void 0);
1933
- _define_property7(this, "open", void 0);
1934
- _define_property7(this, "closed", void 0);
1935
- _define_property7(this, "aborted", void 0);
1936
- _define_property7(this, "extensionContext", void 0);
1937
- _define_property7(this, "_rpc", void 0);
1938
- this.callbacks = callbacks;
1939
- this.open = new Trigger2();
1940
- this.closed = new Trigger2();
1941
- this.aborted = new Trigger2();
1942
- }
1943
1837
  };
1944
1838
 
1945
1839
  // src/testing/test-extension-with-streams.ts
@@ -1949,21 +1843,18 @@ import { invariant as invariant7 } from "@dxos/invariant";
1949
1843
  import { log as log8 } from "@dxos/log";
1950
1844
  import { schema as schema4 } from "@dxos/protocols/proto";
1951
1845
  import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
1952
- function _define_property8(obj, key, value) {
1953
- if (key in obj) {
1954
- Object.defineProperty(obj, key, {
1955
- value,
1956
- enumerable: true,
1957
- configurable: true,
1958
- writable: true
1959
- });
1960
- } else {
1961
- obj[key] = value;
1962
- }
1963
- return obj;
1964
- }
1965
1846
  var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
1966
1847
  var TestExtensionWithStreams = class {
1848
+ callbacks;
1849
+ open = new Trigger3();
1850
+ closed = new Trigger3();
1851
+ aborted = new Trigger3();
1852
+ _streams = /* @__PURE__ */ new Map();
1853
+ extensionContext;
1854
+ _rpc;
1855
+ constructor(callbacks = {}) {
1856
+ this.callbacks = callbacks;
1857
+ }
1967
1858
  get remotePeerId() {
1968
1859
  return this.extensionContext?.remotePeerId;
1969
1860
  }
@@ -2206,20 +2097,6 @@ var TestExtensionWithStreams = class {
2206
2097
  async closeConnection(err) {
2207
2098
  this.extensionContext?.close(err);
2208
2099
  }
2209
- constructor(callbacks = {}) {
2210
- _define_property8(this, "callbacks", void 0);
2211
- _define_property8(this, "open", void 0);
2212
- _define_property8(this, "closed", void 0);
2213
- _define_property8(this, "aborted", void 0);
2214
- _define_property8(this, "_streams", void 0);
2215
- _define_property8(this, "extensionContext", void 0);
2216
- _define_property8(this, "_rpc", void 0);
2217
- this.callbacks = callbacks;
2218
- this.open = new Trigger3();
2219
- this.closed = new Trigger3();
2220
- this.aborted = new Trigger3();
2221
- this._streams = /* @__PURE__ */ new Map();
2222
- }
2223
2100
  };
2224
2101
 
2225
2102
  export {
@@ -2234,4 +2111,4 @@ export {
2234
2111
  TestExtension,
2235
2112
  TestExtensionWithStreams
2236
2113
  };
2237
- //# sourceMappingURL=chunk-32P6LS2F.mjs.map
2114
+ //# sourceMappingURL=chunk-WQHET3HS.mjs.map