@dxos/network-manager 0.8.4-main.fd6878d → 0.8.4-main.fffef41

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.
@@ -19,7 +19,7 @@ var STARTING_SIGNALLING_DELAY = 10;
19
19
  var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
20
20
  var TRANSPORT_STATS_INTERVAL = 5e3;
21
21
  var MAX_SIGNALLING_DELAY = 300;
22
- var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
22
+ var ConnectionState = /* @__PURE__ */ (function(ConnectionState5) {
23
23
  ConnectionState5["CREATED"] = "CREATED";
24
24
  ConnectionState5["INITIAL"] = "INITIAL";
25
25
  ConnectionState5["CONNECTING"] = "CONNECTING";
@@ -29,7 +29,7 @@ var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
29
29
  ConnectionState5["ABORTING"] = "ABORTING";
30
30
  ConnectionState5["ABORTED"] = "ABORTED";
31
31
  return ConnectionState5;
32
- }({});
32
+ })({});
33
33
  var Connection = class {
34
34
  topic;
35
35
  localInfo;
@@ -40,21 +40,29 @@ var Connection = class {
40
40
  _protocol;
41
41
  _transportFactory;
42
42
  _callbacks;
43
- _ctx;
44
- connectedTimeoutContext;
45
- _protocolClosed;
46
- _transportClosed;
47
- _state;
43
+ _ctx = new Context(void 0, {
44
+ F: __dxlog_file,
45
+ L: 100
46
+ });
47
+ connectedTimeoutContext = new Context(void 0, {
48
+ F: __dxlog_file,
49
+ L: 101
50
+ });
51
+ _protocolClosed = new Trigger();
52
+ _transportClosed = new Trigger();
53
+ _state = "CREATED";
48
54
  _transport;
49
55
  closeReason;
50
- _incomingSignalBuffer;
51
- _outgoingSignalBuffer;
52
- stateChanged;
53
- errors;
54
- _instanceId;
55
- transportStats;
56
- _signalSendTask;
57
- _signallingDelay;
56
+ _incomingSignalBuffer = [];
57
+ _outgoingSignalBuffer = [];
58
+ stateChanged = new Event();
59
+ errors = new ErrorStream();
60
+ _instanceId = PublicKey.random().toHex();
61
+ transportStats = new Event();
62
+ _signalSendTask = new DeferredTask(this._ctx, async () => {
63
+ await this._flushSignalBuffer();
64
+ });
65
+ _signallingDelay = STARTING_SIGNALLING_DELAY;
58
66
  constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
59
67
  this.topic = topic;
60
68
  this.localInfo = localInfo;
@@ -65,27 +73,6 @@ var Connection = class {
65
73
  this._protocol = _protocol;
66
74
  this._transportFactory = _transportFactory;
67
75
  this._callbacks = _callbacks;
68
- this._ctx = new Context(void 0, {
69
- F: __dxlog_file,
70
- L: 100
71
- });
72
- this.connectedTimeoutContext = new Context(void 0, {
73
- F: __dxlog_file,
74
- L: 101
75
- });
76
- this._protocolClosed = new Trigger();
77
- this._transportClosed = new Trigger();
78
- this._state = "CREATED";
79
- this._incomingSignalBuffer = [];
80
- this._outgoingSignalBuffer = [];
81
- this.stateChanged = new Event();
82
- this.errors = new ErrorStream();
83
- this._instanceId = PublicKey.random().toHex();
84
- this.transportStats = new Event();
85
- this._signalSendTask = new DeferredTask(this._ctx, async () => {
86
- await this._flushSignalBuffer();
87
- });
88
- this._signallingDelay = STARTING_SIGNALLING_DELAY;
89
76
  log.trace("dxos.mesh.connection.construct", {
90
77
  sessionId: this.sessionId,
91
78
  topic: this.topic,
@@ -948,18 +935,21 @@ var Peer = class {
948
935
  /**
949
936
  * Will be available to connect after this time.
950
937
  */
951
- _availableAfter;
952
- availableToConnect;
938
+ _availableAfter = 0;
939
+ availableToConnect = true;
953
940
  _lastConnectionTime;
954
- _ctx;
941
+ _ctx = new Context3(void 0, {
942
+ F: __dxlog_file4,
943
+ L: 81
944
+ });
955
945
  _connectionCtx;
956
946
  connection;
957
947
  /**
958
948
  * Whether the peer is currently advertizing itself on the signal-network.
959
949
  */
960
- advertizing;
961
- initiating;
962
- connectionDisplaced;
950
+ advertizing = false;
951
+ initiating = false;
952
+ connectionDisplaced = new Event2();
963
953
  constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
964
954
  this.remoteInfo = remoteInfo;
965
955
  this.topic = topic;
@@ -969,15 +959,6 @@ var Peer = class {
969
959
  this._transportFactory = _transportFactory;
970
960
  this._connectionLimiter = _connectionLimiter;
971
961
  this._callbacks = _callbacks;
972
- this._availableAfter = 0;
973
- this.availableToConnect = true;
974
- this._ctx = new Context3(void 0, {
975
- F: __dxlog_file4,
976
- L: 81
977
- });
978
- this.advertizing = false;
979
- this.initiating = false;
980
- this.connectionDisplaced = new Event2();
981
962
  }
982
963
  /**
983
964
  * Respond to remote offer.
@@ -1453,33 +1434,36 @@ var Swarm = class {
1453
1434
  _connectionLimiter;
1454
1435
  _initiationDelay;
1455
1436
  _swarmMessenger;
1456
- _ctx;
1457
- _listeningHandle;
1437
+ _ctx = new Context4(void 0, {
1438
+ F: __dxlog_file5,
1439
+ L: 39
1440
+ });
1441
+ _listeningHandle = void 0;
1458
1442
  /**
1459
1443
  * PeerInfo -> Peer.
1460
1444
  * @internal
1461
1445
  */
1462
- _peers;
1446
+ _peers = new ComplexMap2(PeerInfoHash);
1463
1447
  /**
1464
1448
  * Unique id of the swarm, local to the current peer, generated when swarm is joined.
1465
1449
  */
1466
- _instanceId;
1450
+ _instanceId = PublicKey4.random().toHex();
1467
1451
  /**
1468
1452
  * New connection to a peer is started.
1469
1453
  * @internal
1470
1454
  */
1471
- connectionAdded;
1455
+ connectionAdded = new Event3();
1472
1456
  /**
1473
1457
  * Connection to a peer is dropped.
1474
1458
  * @internal
1475
1459
  */
1476
- disconnected;
1460
+ disconnected = new Event3();
1477
1461
  /**
1478
1462
  * Connection is established to a new peer.
1479
1463
  * @internal
1480
1464
  */
1481
- connected;
1482
- errors;
1465
+ connected = new Event3();
1466
+ errors = new ErrorStream2();
1483
1467
  // TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
1484
1468
  // TODO(burdon): Pass in object.
1485
1469
  constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
@@ -1492,17 +1476,6 @@ var Swarm = class {
1492
1476
  this._label = _label;
1493
1477
  this._connectionLimiter = _connectionLimiter;
1494
1478
  this._initiationDelay = _initiationDelay;
1495
- this._ctx = new Context4(void 0, {
1496
- F: __dxlog_file5,
1497
- L: 39
1498
- });
1499
- this._listeningHandle = void 0;
1500
- this._peers = new ComplexMap2(PeerInfoHash);
1501
- this._instanceId = PublicKey4.random().toHex();
1502
- this.connectionAdded = new Event3();
1503
- this.disconnected = new Event3();
1504
- this.connected = new Event3();
1505
- this.errors = new ErrorStream2();
1506
1479
  log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
1507
1480
  id: this._instanceId,
1508
1481
  data: {
@@ -2045,19 +2018,15 @@ import { ComplexMap as ComplexMap3 } from "@dxos/util";
2045
2018
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2046
2019
  var SwarmMapper = class {
2047
2020
  _swarm;
2048
- _subscriptions;
2049
- _connectionSubscriptions;
2050
- _peers;
2051
- mapUpdated;
2021
+ _subscriptions = new SubscriptionList();
2022
+ _connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
2023
+ _peers = new ComplexMap3(PeerInfoHash2);
2024
+ mapUpdated = new Event4();
2052
2025
  get peers() {
2053
2026
  return Array.from(this._peers.values());
2054
2027
  }
2055
2028
  constructor(_swarm) {
2056
2029
  this._swarm = _swarm;
2057
- this._subscriptions = new SubscriptionList();
2058
- this._connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
2059
- this._peers = new ComplexMap3(PeerInfoHash2);
2060
- this.mapUpdated = new Event4();
2061
2030
  this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
2062
2031
  this._update();
2063
2032
  this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
@@ -2204,14 +2173,14 @@ import { raise } from "@dxos/debug";
2204
2173
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2205
2174
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
2206
2175
  var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
2207
- var EventType = /* @__PURE__ */ function(EventType2) {
2176
+ var EventType = /* @__PURE__ */ (function(EventType2) {
2208
2177
  EventType2["CONNECTION_STATE_CHANGED"] = "CONNECTION_STATE_CHANGED";
2209
2178
  EventType2["PROTOCOL_ERROR"] = "PROTOCOL_ERROR";
2210
2179
  EventType2["PROTOCOL_EXTENSIONS_INITIALIZED"] = "PROTOCOL_EXTENSIONS_INITIALIZED";
2211
2180
  EventType2["PROTOCOL_EXTENSIONS_HANDSHAKE"] = "PROTOCOL_EXTENSIONS_HANDSHAKE";
2212
2181
  EventType2["PROTOCOL_HANDSHAKE"] = "PROTOCOL_HANDSHAKE";
2213
2182
  return EventType2;
2214
- }({});
2183
+ })({});
2215
2184
  var ConnectionLog = class {
2216
2185
  /**
2217
2186
  * SwarmId => info
@@ -2935,26 +2904,18 @@ var MemoryTransport = class _MemoryTransport {
2935
2904
  _options;
2936
2905
  // TODO(burdon): Remove static properties (inject context into constructor).
2937
2906
  static _connections = new ComplexMap7(PublicKey9.hash);
2938
- _instanceId;
2939
- _remote;
2940
- _outgoingDelay;
2941
- _incomingDelay;
2942
- _closed;
2907
+ _instanceId = PublicKey9.random();
2908
+ _remote = new Trigger2();
2909
+ _outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2910
+ _incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2911
+ _closed = false;
2943
2912
  _remoteInstanceId;
2944
2913
  _remoteConnection;
2945
- closed;
2946
- connected;
2947
- errors;
2914
+ closed = new Event7();
2915
+ connected = new Event7();
2916
+ errors = new ErrorStream3();
2948
2917
  constructor(_options) {
2949
2918
  this._options = _options;
2950
- this._instanceId = PublicKey9.random();
2951
- this._remote = new Trigger2();
2952
- this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2953
- this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2954
- this._closed = false;
2955
- this.closed = new Event7();
2956
- this.connected = new Event7();
2957
- this.errors = new ErrorStream3();
2958
2919
  invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2959
2920
  F: __dxlog_file12,
2960
2921
  L: 64,
@@ -3106,13 +3067,13 @@ _ts_decorate5([
3106
3067
  var toError = (err) => err instanceof Error ? err : new Error(String(err));
3107
3068
 
3108
3069
  // src/transport/transport.ts
3109
- var TransportKind = /* @__PURE__ */ function(TransportKind2) {
3070
+ var TransportKind = /* @__PURE__ */ (function(TransportKind2) {
3110
3071
  TransportKind2["WEB_RTC"] = "WEB-RTC";
3111
3072
  TransportKind2["WEB_RTC_PROXY"] = "WEB-RTC_PROXY";
3112
3073
  TransportKind2["MEMORY"] = "MEMORY";
3113
3074
  TransportKind2["TCP"] = "TCP";
3114
3075
  return TransportKind2;
3115
- }({});
3076
+ })({});
3116
3077
 
3117
3078
  // src/transport/webrtc/rtc-connection-factory.ts
3118
3079
  import { Mutex } from "@dxos/async";
@@ -3229,15 +3190,15 @@ var MAX_BUFFERED_AMOUNT = 64 * 1024;
3229
3190
  var RtcTransportChannel = class extends Resource {
3230
3191
  _connection;
3231
3192
  _options;
3232
- closed;
3233
- connected;
3234
- errors;
3193
+ closed = new AsyncEvent();
3194
+ connected = new AsyncEvent();
3195
+ errors = new ErrorStream4();
3235
3196
  _channel;
3236
3197
  _stream;
3237
- _streamDataFlushedCallback;
3238
- _isChannelCreationInProgress;
3198
+ _streamDataFlushedCallback = null;
3199
+ _isChannelCreationInProgress = false;
3239
3200
  constructor(_connection, _options) {
3240
- super(), this._connection = _connection, this._options = _options, this.closed = new AsyncEvent(), this.connected = new AsyncEvent(), this.errors = new ErrorStream4(), this._streamDataFlushedCallback = null, this._isChannelCreationInProgress = false;
3201
+ super(), this._connection = _connection, this._options = _options;
3241
3202
  }
3242
3203
  get isRtcChannelCreationInProgress() {
3243
3204
  return this._isChannelCreationInProgress;
@@ -3467,13 +3428,13 @@ var RtcPeerConnection = class {
3467
3428
  _factory;
3468
3429
  _options;
3469
3430
  // A peer who is not the initiator waits for another party to open a channel.
3470
- _channelCreatedCallbacks;
3431
+ _channelCreatedCallbacks = /* @__PURE__ */ new Map();
3471
3432
  // Channels indexed by topic.
3472
- _transportChannels;
3473
- _dataChannels;
3433
+ _transportChannels = /* @__PURE__ */ new Map();
3434
+ _dataChannels = /* @__PURE__ */ new Map();
3474
3435
  // A peer is ready to receive ICE candidates when local and remote description were set.
3475
- _readyForCandidates;
3476
- _offerProcessingMutex;
3436
+ _readyForCandidates = new Trigger3();
3437
+ _offerProcessingMutex = new Mutex2();
3477
3438
  /**
3478
3439
  * Can't use peer.connection.initiator, because if two connections to the same peer are created in
3479
3440
  * different swarms, we might be the initiator of the first one, but not of the other one.
@@ -3485,11 +3446,6 @@ var RtcPeerConnection = class {
3485
3446
  constructor(_factory, _options) {
3486
3447
  this._factory = _factory;
3487
3448
  this._options = _options;
3488
- this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
3489
- this._transportChannels = /* @__PURE__ */ new Map();
3490
- this._dataChannels = /* @__PURE__ */ new Map();
3491
- this._readyForCandidates = new Trigger3();
3492
- this._offerProcessingMutex = new Mutex2();
3493
3449
  this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
3494
3450
  }
3495
3451
  get transportChannelCount() {
@@ -4084,13 +4040,13 @@ var CLOSE_RPC_TIMEOUT = 3e3;
4084
4040
  var RESP_MIN_THRESHOLD = 500;
4085
4041
  var RtcTransportProxy = class extends Resource2 {
4086
4042
  _options;
4087
- _proxyId;
4088
- closed;
4089
- connected;
4090
- errors;
4043
+ _proxyId = PublicKey10.random();
4044
+ closed = new Event8();
4045
+ connected = new Event8();
4046
+ errors = new ErrorStream5();
4091
4047
  _serviceStream;
4092
4048
  constructor(_options) {
4093
- super(), this._options = _options, this._proxyId = PublicKey10.random(), this.closed = new Event8(), this.connected = new Event8(), this.errors = new ErrorStream5();
4049
+ super(), this._options = _options;
4094
4050
  }
4095
4051
  async _open() {
4096
4052
  let stream;
@@ -4357,10 +4313,9 @@ import { ComplexMap as ComplexMap8 } from "@dxos/util";
4357
4313
  var __dxlog_file16 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
4358
4314
  var RtcTransportService = class {
4359
4315
  _transportFactory;
4360
- _openTransports;
4316
+ _openTransports = new ComplexMap8(PublicKey11.hash);
4361
4317
  constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
4362
4318
  this._transportFactory = _transportFactory;
4363
- this._openTransports = new ComplexMap8(PublicKey11.hash);
4364
4319
  }
4365
4320
  hasOpenTransports() {
4366
4321
  return this._openTransports.size > 0;
@@ -4610,4 +4565,4 @@ export {
4610
4565
  RtcTransportService,
4611
4566
  createTeleportProtocolFactory
4612
4567
  };
4613
- //# sourceMappingURL=chunk-JUVDHWW4.mjs.map
4568
+ //# sourceMappingURL=chunk-E3P563GT.mjs.map