@dxos/network-manager 0.8.1 → 0.8.2-main.10c050d

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.
Files changed (76) hide show
  1. package/dist/lib/browser/{chunk-BHB7ZFZF.mjs → chunk-LFKR6BAF.mjs} +20 -32
  2. package/dist/lib/browser/chunk-LFKR6BAF.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +1 -1
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/browser/transport/tcp/index.mjs.map +2 -2
  8. package/dist/lib/node/{chunk-D2HGDGMO.cjs → chunk-2G6RZMS5.cjs} +23 -35
  9. package/dist/lib/node/chunk-2G6RZMS5.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +23 -23
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +14 -14
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/lib/node/transport/tcp/index.cjs.map +3 -3
  16. package/dist/lib/node-esm/{chunk-NHFGO4HB.mjs → chunk-QQY4BF6O.mjs} +20 -32
  17. package/dist/lib/node-esm/chunk-QQY4BF6O.mjs.map +7 -0
  18. package/dist/lib/node-esm/index.mjs +1 -1
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.mjs +1 -1
  21. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  22. package/dist/lib/node-esm/transport/tcp/index.mjs.map +3 -3
  23. package/dist/types/src/connection-log.d.ts.map +1 -1
  24. package/dist/types/src/network-manager.d.ts.map +1 -1
  25. package/dist/types/src/signal/ice.d.ts.map +1 -1
  26. package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
  27. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  28. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  29. package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
  30. package/dist/types/src/swarm/swarm.d.ts +1 -1
  31. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  32. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  33. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
  34. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  35. package/dist/types/src/tests/utils.d.ts.map +1 -1
  36. package/dist/types/src/topology/fully-connected-topology.d.ts.map +1 -1
  37. package/dist/types/src/topology/mmst-topology.d.ts.map +1 -1
  38. package/dist/types/src/topology/star-topology.d.ts.map +1 -1
  39. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  40. package/dist/types/src/transport/tcp/tcp-transport.browser.d.ts.map +1 -1
  41. package/dist/types/src/transport/tcp/tcp-transport.d.ts.map +1 -1
  42. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
  43. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
  44. package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
  45. package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
  46. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
  47. package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts.map +1 -1
  48. package/dist/types/src/transport/webrtc/test-utils.d.ts.map +1 -1
  49. package/dist/types/src/transport/webrtc/utils.d.ts.map +1 -1
  50. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  51. package/dist/types/tsconfig.tsbuildinfo +1 -1
  52. package/package.json +18 -18
  53. package/src/connection-log.ts +3 -3
  54. package/src/network-manager.ts +5 -5
  55. package/src/swarm/connection-limiter.ts +1 -1
  56. package/src/swarm/connection.ts +10 -10
  57. package/src/swarm/peer.ts +5 -5
  58. package/src/swarm/swarm-mapper.ts +2 -2
  59. package/src/swarm/swarm.test.ts +2 -2
  60. package/src/swarm/swarm.ts +11 -11
  61. package/src/testing/test-builder.ts +9 -9
  62. package/src/testing/test-wire-protocol.ts +2 -2
  63. package/src/topology/fully-connected-topology.ts +1 -1
  64. package/src/topology/mmst-topology.ts +3 -3
  65. package/src/topology/star-topology.ts +1 -1
  66. package/src/transport/memory-transport.ts +10 -5
  67. package/src/transport/tcp/tcp-transport.browser.ts +3 -3
  68. package/src/transport/tcp/tcp-transport.ts +4 -4
  69. package/src/transport/webrtc/rtc-connection-factory.ts +5 -5
  70. package/src/transport/webrtc/rtc-peer-connection.ts +15 -15
  71. package/src/transport/webrtc/rtc-transport-channel.ts +6 -6
  72. package/src/transport/webrtc/rtc-transport-proxy.ts +7 -7
  73. package/src/transport/webrtc/rtc-transport-service.ts +3 -3
  74. package/dist/lib/browser/chunk-BHB7ZFZF.mjs.map +0 -7
  75. package/dist/lib/node/chunk-D2HGDGMO.cjs.map +0 -7
  76. package/dist/lib/node-esm/chunk-NHFGO4HB.mjs.map +0 -7
@@ -70,7 +70,7 @@ export class MemoryTransport implements Transport {
70
70
  return !this._closed;
71
71
  }
72
72
 
73
- async open() {
73
+ async open(): Promise<this> {
74
74
  log('opening...');
75
75
 
76
76
  // Initiator will send a signal, the receiver will receive the unique ID and connect the streams.
@@ -126,7 +126,7 @@ export class MemoryTransport implements Transport {
126
126
  return this;
127
127
  }
128
128
 
129
- async close() {
129
+ async close(): Promise<this> {
130
130
  log('closing...');
131
131
  this._closed = true;
132
132
 
@@ -159,7 +159,7 @@ export class MemoryTransport implements Transport {
159
159
  return this;
160
160
  }
161
161
 
162
- async onSignal({ payload }: Signal) {
162
+ async onSignal({ payload }: Signal): Promise<void> {
163
163
  log('received signal', { payload });
164
164
  if (!payload?.transportId) {
165
165
  return;
@@ -173,11 +173,16 @@ export class MemoryTransport implements Transport {
173
173
  }
174
174
  }
175
175
 
176
- async getDetails() {
176
+ async getDetails(): Promise<string> {
177
177
  return this._instanceId.toHex();
178
178
  }
179
179
 
180
- async getStats() {
180
+ async getStats(): Promise<{
181
+ bytesSent: number;
182
+ bytesReceived: number;
183
+ packetsSent: number;
184
+ packetsReceived: number;
185
+ }> {
181
186
  return {
182
187
  bytesSent: 0,
183
188
  bytesReceived: 0,
@@ -23,15 +23,15 @@ export class TcpTransport implements Transport {
23
23
  return true;
24
24
  }
25
25
 
26
- async open() {
26
+ async open(): Promise<this> {
27
27
  return this;
28
28
  }
29
29
 
30
- async close() {
30
+ async close(): Promise<this> {
31
31
  return this;
32
32
  }
33
33
 
34
- async onSignal() {
34
+ async onSignal(): Promise<void> {
35
35
  throw new Error('Method not implemented.');
36
36
  }
37
37
 
@@ -35,7 +35,7 @@ export class TcpTransport implements Transport {
35
35
  return this._connected && !this._closed;
36
36
  }
37
37
 
38
- async open() {
38
+ async open(): Promise<this> {
39
39
  log('opening');
40
40
 
41
41
  // Initiator will send a signal, the receiver will receive the unique ID and connect the streams.
@@ -75,7 +75,7 @@ export class TcpTransport implements Transport {
75
75
  return this;
76
76
  }
77
77
 
78
- async close() {
78
+ async close(): Promise<this> {
79
79
  log('closing');
80
80
  this._socket?.destroy();
81
81
  this._server?.close();
@@ -83,7 +83,7 @@ export class TcpTransport implements Transport {
83
83
  return this;
84
84
  }
85
85
 
86
- async onSignal({ payload }: Signal) {
86
+ async onSignal({ payload }: Signal): Promise<void> {
87
87
  log('received signal', { payload });
88
88
  if (this.options.initiator || this._connected) {
89
89
  return;
@@ -113,7 +113,7 @@ export class TcpTransport implements Transport {
113
113
  };
114
114
  }
115
115
 
116
- private _handleSocket(socket: Socket) {
116
+ private _handleSocket(socket: Socket): void {
117
117
  log('handling socket', { remotePort: socket.remotePort, localPort: socket.localPort });
118
118
  this._socket = socket;
119
119
 
@@ -19,10 +19,10 @@ export interface RtcConnectionFactory {
19
19
  * Use built-in browser RTCPeerConnection.
20
20
  */
21
21
  class BrowserRtcConnectionFactory implements RtcConnectionFactory {
22
- async initialize() {}
23
- async onConnectionDestroyed() {}
22
+ async initialize(): Promise<void> {}
23
+ async onConnectionDestroyed(): Promise<void> {}
24
24
 
25
- async createConnection(config: RTCConfiguration) {
25
+ async createConnection(config: RTCConfiguration): Promise<RTCPeerConnection> {
26
26
  return new RTCPeerConnection(config);
27
27
  }
28
28
 
@@ -41,8 +41,8 @@ class NodeRtcConnectionFactory implements RtcConnectionFactory {
41
41
  // eslint-disable-next-line no-new-func
42
42
 
43
43
  // TODO(burdon): Do imports here?
44
- async initialize() {}
45
- async onConnectionDestroyed() {
44
+ async initialize(): Promise<void> {}
45
+ async onConnectionDestroyed(): Promise<void> {
46
46
  return NodeRtcConnectionFactory._cleanupMutex.executeSynchronized(async () => {
47
47
  if (--NodeRtcConnectionFactory._createdConnections === 0) {
48
48
  (await import('#node-datachannel')).cleanup();
@@ -79,7 +79,7 @@ export class RtcPeerConnection {
79
79
  const connection = await this._openConnection();
80
80
  if (!this._transportChannels.has(topic)) {
81
81
  if (!this._transportChannels.size) {
82
- this._lockAndCloseConnection();
82
+ void this._lockAndCloseConnection();
83
83
  }
84
84
  throw new Error('Transport closed while connection was being open');
85
85
  }
@@ -105,7 +105,7 @@ export class RtcPeerConnection {
105
105
  channel.closed.on(() => {
106
106
  this._transportChannels.delete(options.topic);
107
107
  if (this._transportChannels.size === 0) {
108
- this._lockAndCloseConnection();
108
+ void this._lockAndCloseConnection();
109
109
  }
110
110
  });
111
111
  return channel;
@@ -145,7 +145,7 @@ export class RtcPeerConnection {
145
145
  await connection.setLocalDescription(offer);
146
146
  await this._sendDescription(connection, offer);
147
147
  } catch (err: any) {
148
- this._lockAndAbort(connection, err);
148
+ void this._lockAndAbort(connection, err);
149
149
  }
150
150
  },
151
151
 
@@ -183,7 +183,7 @@ export class RtcPeerConnection {
183
183
 
184
184
  log('oniceconnectionstatechange', { state: connection.iceConnectionState });
185
185
  if (connection.iceConnectionState === 'failed') {
186
- this._lockAndAbort(connection, createIceFailureError(iceCandidateErrors));
186
+ void this._lockAndAbort(connection, createIceFailureError(iceCandidateErrors));
187
187
  }
188
188
  },
189
189
 
@@ -200,7 +200,7 @@ export class RtcPeerConnection {
200
200
 
201
201
  log('onconnectionstatechange', { state: connection.connectionState });
202
202
  if (connection.connectionState === 'failed') {
203
- this._lockAndAbort(connection, new Error('Connection failed.'));
203
+ void this._lockAndAbort(connection, new Error('Connection failed.'));
204
204
  }
205
205
  },
206
206
 
@@ -237,11 +237,11 @@ export class RtcPeerConnection {
237
237
  }
238
238
 
239
239
  @synchronized
240
- private _lockAndAbort(connection: RTCPeerConnection, error: Error) {
240
+ private async _lockAndAbort(connection: RTCPeerConnection, error: Error): Promise<void> {
241
241
  this._abortConnection(connection, error);
242
242
  }
243
243
 
244
- private _abortConnection(connection: RTCPeerConnection, error: Error) {
244
+ private _abortConnection(connection: RTCPeerConnection, error: Error): void {
245
245
  if (connection !== this._connection) {
246
246
  log.error('attempted to abort an inactive connection', { error });
247
247
  this._safeCloseConnection(connection);
@@ -261,7 +261,7 @@ export class RtcPeerConnection {
261
261
  }
262
262
 
263
263
  @synchronized
264
- private _lockAndCloseConnection() {
264
+ private async _lockAndCloseConnection(): Promise<void> {
265
265
  invariant(this._transportChannels.size === 0);
266
266
  if (this._connection) {
267
267
  this._safeCloseConnection();
@@ -270,7 +270,7 @@ export class RtcPeerConnection {
270
270
  }
271
271
 
272
272
  @synchronized
273
- public async onSignal(signal: Signal) {
273
+ public async onSignal(signal: Signal): Promise<void> {
274
274
  const connection = this._connection;
275
275
  if (!connection) {
276
276
  log.warn('a signal ignored because the connection was closed', { type: signal.payload.data.type });
@@ -335,7 +335,7 @@ export class RtcPeerConnection {
335
335
  log('signal processed', { type: data.type });
336
336
  }
337
337
 
338
- private async _processIceCandidate(connection: RTCPeerConnection, candidate: RTCIceCandidate) {
338
+ private async _processIceCandidate(connection: RTCPeerConnection, candidate: RTCIceCandidate): Promise<void> {
339
339
  try {
340
340
  // ICE candidates are associated with a session, so we need to wait for the remote description to be set.
341
341
  await this._readyForCandidates.wait();
@@ -348,7 +348,7 @@ export class RtcPeerConnection {
348
348
  }
349
349
  }
350
350
 
351
- private _onSessionNegotiated(connection: RTCPeerConnection) {
351
+ private _onSessionNegotiated(connection: RTCPeerConnection): void {
352
352
  if (connection === this._connection) {
353
353
  log('ready to process ice candidates');
354
354
  this._readyForCandidates.wake();
@@ -357,7 +357,7 @@ export class RtcPeerConnection {
357
357
  }
358
358
  }
359
359
 
360
- private _onConnectionCallbackAfterClose(callback: string, connection: RTCPeerConnection) {
360
+ private _onConnectionCallbackAfterClose(callback: string, connection: RTCPeerConnection): void {
361
361
  log.warn('callback invoked after a connection was destroyed, this is probably a bug', {
362
362
  callback,
363
363
  state: connection.connectionState,
@@ -365,7 +365,7 @@ export class RtcPeerConnection {
365
365
  this._safeCloseConnection(connection);
366
366
  }
367
367
 
368
- private _safeCloseConnection(connection: RTCPeerConnection | undefined = this._connection) {
368
+ private _safeCloseConnection(connection: RTCPeerConnection | undefined = this._connection): void {
369
369
  const resetFields = this._connection && connection === this._connection;
370
370
  try {
371
371
  connection?.close();
@@ -397,7 +397,7 @@ export class RtcPeerConnection {
397
397
  return config;
398
398
  }
399
399
 
400
- private async _sendIceCandidate(candidate: RTCIceCandidate) {
400
+ private async _sendIceCandidate(candidate: RTCIceCandidate): Promise<void> {
401
401
  try {
402
402
  await this._options.sendSignal({
403
403
  payload: {
@@ -417,7 +417,7 @@ export class RtcPeerConnection {
417
417
  }
418
418
  }
419
419
 
420
- private async _sendDescription(connection: RTCPeerConnection, description: RTCSessionDescriptionInit) {
420
+ private async _sendDescription(connection: RTCPeerConnection, description: RTCSessionDescriptionInit): Promise<void> {
421
421
  if (connection !== this._connection) {
422
422
  // Connection was closed while description was being created.
423
423
  return;
@@ -46,13 +46,13 @@ export class RtcTransportChannel extends Resource implements Transport {
46
46
  return this._isChannelCreationInProgress;
47
47
  }
48
48
 
49
- public onConnectionError(error: Error) {
49
+ public onConnectionError(error: Error): void {
50
50
  if (this.isOpen) {
51
51
  this.errors.raise(error);
52
52
  }
53
53
  }
54
54
 
55
- protected override async _open() {
55
+ protected override async _open(): Promise<void> {
56
56
  invariant(!this._isChannelCreationInProgress);
57
57
  this._isChannelCreationInProgress = true;
58
58
  this._connection
@@ -81,7 +81,7 @@ export class RtcTransportChannel extends Resource implements Transport {
81
81
  });
82
82
  }
83
83
 
84
- protected override async _close() {
84
+ protected override async _close(): Promise<void> {
85
85
  if (this._channel) {
86
86
  this._safeCloseChannel(this._channel);
87
87
  this._channel = undefined;
@@ -92,7 +92,7 @@ export class RtcTransportChannel extends Resource implements Transport {
92
92
  log('closed');
93
93
  }
94
94
 
95
- private _initChannel(channel: RTCDataChannel) {
95
+ private _initChannel(channel: RTCDataChannel): void {
96
96
  Object.assign<RTCDataChannel, Partial<RTCDataChannel>>(channel, {
97
97
  onopen: () => {
98
98
  if (!this.isOpen) {
@@ -148,7 +148,7 @@ export class RtcTransportChannel extends Resource implements Transport {
148
148
  });
149
149
  }
150
150
 
151
- private async _handleChannelWrite(chunk: any, callback: PendingStreamFlushedCallback) {
151
+ private async _handleChannelWrite(chunk: any, callback: PendingStreamFlushedCallback): Promise<void> {
152
152
  if (!this._channel) {
153
153
  log.warn('writing to a channel after a connection was closed');
154
154
  return;
@@ -179,7 +179,7 @@ export class RtcTransportChannel extends Resource implements Transport {
179
179
  }
180
180
  }
181
181
 
182
- private _safeCloseChannel(channel: RTCDataChannel) {
182
+ private _safeCloseChannel(channel: RTCDataChannel): void {
183
183
  try {
184
184
  channel.close();
185
185
  } catch (error: any) {
@@ -39,7 +39,7 @@ export class RtcTransportProxy extends Resource implements Transport {
39
39
  super();
40
40
  }
41
41
 
42
- protected override async _open() {
42
+ protected override async _open(): Promise<void> {
43
43
  let stream: Stream<BridgeEvent>;
44
44
  try {
45
45
  stream = this._options.bridgeService.open(
@@ -120,7 +120,7 @@ export class RtcTransportProxy extends Resource implements Transport {
120
120
  );
121
121
  }
122
122
 
123
- protected override async _close() {
123
+ protected override async _close(): Promise<void> {
124
124
  try {
125
125
  await this._serviceStream?.close();
126
126
  this._serviceStream = undefined;
@@ -137,7 +137,7 @@ export class RtcTransportProxy extends Resource implements Transport {
137
137
  this.closed.emit();
138
138
  }
139
139
 
140
- async onSignal(signal: Signal) {
140
+ async onSignal(signal: Signal): Promise<void> {
141
141
  this._options.bridgeService
142
142
  .sendSignal({ proxyId: this._proxyId, signal }, { timeout: RPC_TIMEOUT })
143
143
  .catch((err) => this._raiseIfOpen(decodeError(err)));
@@ -161,7 +161,7 @@ export class RtcTransportProxy extends Resource implements Transport {
161
161
  }
162
162
  }
163
163
 
164
- private _handleData(dataEvent: BridgeEvent.DataEvent) {
164
+ private _handleData(dataEvent: BridgeEvent.DataEvent): void {
165
165
  try {
166
166
  // NOTE: This must be a Buffer otherwise hypercore-protocol breaks.
167
167
  this._options.stream.write(arrayToBuffer(dataEvent.payload));
@@ -170,7 +170,7 @@ export class RtcTransportProxy extends Resource implements Transport {
170
170
  }
171
171
  }
172
172
 
173
- private async _handleSignal(signalEvent: BridgeEvent.SignalEvent) {
173
+ private async _handleSignal(signalEvent: BridgeEvent.SignalEvent): Promise<void> {
174
174
  try {
175
175
  await this._options.sendSignal(signalEvent.payload);
176
176
  } catch (error) {
@@ -208,7 +208,7 @@ export class RtcTransportProxy extends Resource implements Transport {
208
208
  }
209
209
  }
210
210
 
211
- private _raiseIfOpen(error: any) {
211
+ private _raiseIfOpen(error: any): void {
212
212
  if (this.isOpen) {
213
213
  this.errors.raise(error);
214
214
  } else {
@@ -219,7 +219,7 @@ export class RtcTransportProxy extends Resource implements Transport {
219
219
  /**
220
220
  * Called when underlying proxy service becomes unavailable.
221
221
  */
222
- forceClose() {
222
+ forceClose(): void {
223
223
  void this._serviceStream?.close();
224
224
  this.closed.emit();
225
225
  }
@@ -43,7 +43,7 @@ export class RtcTransportService implements BridgeService {
43
43
  private readonly _transportFactory: TransportFactory = createRtcTransportFactory(webrtcConfig, iceProvider),
44
44
  ) {}
45
45
 
46
- public hasOpenTransports() {
46
+ public hasOpenTransports(): boolean {
47
47
  return this._openTransports.size > 0;
48
48
  }
49
49
 
@@ -151,7 +151,7 @@ export class RtcTransportService implements BridgeService {
151
151
  }
152
152
  }
153
153
 
154
- async close({ proxyId }: CloseRequest) {
154
+ async close({ proxyId }: CloseRequest): Promise<void> {
155
155
  const transport = this._openTransports.get(proxyId);
156
156
  if (!transport) {
157
157
  return;
@@ -161,7 +161,7 @@ export class RtcTransportService implements BridgeService {
161
161
  await this._safeCloseTransport(transport);
162
162
  }
163
163
 
164
- private async _safeCloseTransport(transport: TransportState) {
164
+ private async _safeCloseTransport(transport: TransportState): Promise<void> {
165
165
  if (this._openTransports.get(transport.proxyId) === transport) {
166
166
  this._openTransports.delete(transport.proxyId);
167
167
  }