@dxos/network-manager 0.3.9-main.b7e6a67 → 0.3.9-main.c7cd0ec

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 (87) hide show
  1. package/dist/lib/browser/{chunk-LA2ACGLR.mjs → chunk-XF474R3E.mjs} +434 -116
  2. package/dist/lib/browser/chunk-XF474R3E.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -11
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +3 -3
  6. package/dist/lib/node/{chunk-QWUG7JSH.cjs → chunk-Y2B5BDRH.cjs} +426 -104
  7. package/dist/lib/node/chunk-Y2B5BDRH.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +27 -36
  9. package/dist/lib/node/index.cjs.map +2 -2
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +18 -19
  12. package/dist/lib/node/testing/index.cjs.map +1 -1
  13. package/dist/types/src/connection-log.d.ts.map +1 -1
  14. package/dist/types/src/swarm/connection.d.ts +4 -1
  15. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  16. package/dist/types/src/topology/mmst-topology.d.ts +1 -0
  17. package/dist/types/src/topology/mmst-topology.d.ts.map +1 -1
  18. package/dist/types/src/transport/index.d.ts +0 -1
  19. package/dist/types/src/transport/index.d.ts.map +1 -1
  20. package/dist/types/src/transport/libdatachannel-transport.d.ts +4 -1
  21. package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
  22. package/dist/types/src/transport/memory-transport.d.ts +3 -1
  23. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  24. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts +3 -1
  25. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  26. package/dist/types/src/transport/simplepeer-transport-service.d.ts +3 -1
  27. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
  28. package/dist/types/src/transport/simplepeer-transport.d.ts +7 -1
  29. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  30. package/dist/types/src/transport/tcp-transport.browser.d.ts +3 -1
  31. package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -1
  32. package/dist/types/src/transport/tcp-transport.d.ts +3 -1
  33. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -1
  34. package/dist/types/src/transport/transport.d.ts +17 -0
  35. package/dist/types/src/transport/transport.d.ts.map +1 -1
  36. package/dist/types/src/wire-protocol.d.ts +1 -1
  37. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  38. package/package.json +18 -18
  39. package/src/connection-log.ts +14 -1
  40. package/src/swarm/connection.ts +40 -6
  41. package/src/topology/mmst-topology.ts +34 -6
  42. package/src/transport/index.ts +0 -1
  43. package/src/transport/libdatachannel-transport.test.ts +0 -4
  44. package/src/transport/libdatachannel-transport.ts +90 -8
  45. package/src/transport/memory-transport.ts +14 -1
  46. package/src/transport/simplepeer-transport-proxy.ts +9 -1
  47. package/src/transport/simplepeer-transport-service.ts +14 -0
  48. package/src/transport/simplepeer-transport.ts +70 -4
  49. package/src/transport/tcp-transport.browser.ts +9 -1
  50. package/src/transport/tcp-transport.ts +19 -1
  51. package/src/transport/transport.ts +19 -0
  52. package/src/wire-protocol.ts +3 -3
  53. package/dist/lib/browser/chunk-LA2ACGLR.mjs.map +0 -7
  54. package/dist/lib/browser/chunk-YERMWDRB.mjs +0 -24
  55. package/dist/lib/browser/chunk-YERMWDRB.mjs.map +0 -7
  56. package/dist/lib/browser/index.browser-O53CPVK3.mjs +0 -14
  57. package/dist/lib/browser/index.browser-O53CPVK3.mjs.map +0 -7
  58. package/dist/lib/node/chunk-QWUG7JSH.cjs.map +0 -7
  59. package/dist/lib/node/chunk-XE5JOIGD.cjs +0 -462
  60. package/dist/lib/node/chunk-XE5JOIGD.cjs.map +0 -7
  61. package/dist/lib/node/datachannel-53JZPGFA.cjs +0 -35
  62. package/dist/lib/node/datachannel-53JZPGFA.cjs.map +0 -7
  63. package/dist/types/src/transport/datachannel/index.browser.d.ts +0 -15
  64. package/dist/types/src/transport/datachannel/index.browser.d.ts.map +0 -1
  65. package/dist/types/src/transport/datachannel/index.d.ts +0 -8
  66. package/dist/types/src/transport/datachannel/index.d.ts.map +0 -1
  67. package/dist/types/src/transport/datachannel/rtc-data-channel.d.ts +0 -29
  68. package/dist/types/src/transport/datachannel/rtc-data-channel.d.ts.map +0 -1
  69. package/dist/types/src/transport/datachannel/rtc-events.d.ts +0 -9
  70. package/dist/types/src/transport/datachannel/rtc-events.d.ts.map +0 -1
  71. package/dist/types/src/transport/datachannel/rtc-ice-candidate.d.ts +0 -22
  72. package/dist/types/src/transport/datachannel/rtc-ice-candidate.d.ts.map +0 -1
  73. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts +0 -47
  74. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +0 -1
  75. package/dist/types/src/transport/datachannel/rtc-peer-connection.test.d.ts +0 -2
  76. package/dist/types/src/transport/datachannel/rtc-peer-connection.test.d.ts.map +0 -1
  77. package/dist/types/src/transport/datachannel/rtc-session-description.d.ts +0 -10
  78. package/dist/types/src/transport/datachannel/rtc-session-description.d.ts.map +0 -1
  79. package/src/transport/datachannel/README.md +0 -2
  80. package/src/transport/datachannel/index.browser.ts +0 -8
  81. package/src/transport/datachannel/index.ts +0 -17
  82. package/src/transport/datachannel/rtc-data-channel.ts +0 -148
  83. package/src/transport/datachannel/rtc-events.ts +0 -23
  84. package/src/transport/datachannel/rtc-ice-candidate.ts +0 -54
  85. package/src/transport/datachannel/rtc-peer-connection.test.ts +0 -112
  86. package/src/transport/datachannel/rtc-peer-connection.ts +0 -347
  87. package/src/transport/datachannel/rtc-session-description.ts +0 -23
@@ -1,347 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import node from 'node-datachannel';
6
- import defer, { type DeferredPromise } from 'p-defer';
7
-
8
- import { DataChannel } from './rtc-data-channel';
9
- import { DataChannelEvent, PeerConnectionIceEvent } from './rtc-events';
10
- import { IceCandidate } from './rtc-ice-candidate';
11
- import { SessionDescription } from './rtc-session-description';
12
-
13
- export class PeerConnection extends EventTarget implements RTCPeerConnection {
14
- static async generateCertificate(keygenAlgorithm: AlgorithmIdentifier): Promise<RTCCertificate> {
15
- throw new Error('Not implemented');
16
- }
17
-
18
- canTrickleIceCandidates: boolean | null;
19
- sctp: RTCSctpTransport | null;
20
-
21
- onconnectionstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
22
- ondatachannel: ((this: RTCPeerConnection, ev: RTCDataChannelEvent) => any) | null;
23
- onicecandidate: ((this: RTCPeerConnection, ev: RTCPeerConnectionIceEvent) => any) | null;
24
- onicecandidateerror: ((this: RTCPeerConnection, ev: Event) => any) | null;
25
- oniceconnectionstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
26
- onicegatheringstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
27
- onnegotiationneeded: ((this: RTCPeerConnection, ev: Event) => any) | null;
28
- onsignalingstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
29
- ontrack: ((this: RTCPeerConnection, ev: RTCTrackEvent) => any) | null;
30
-
31
- #peerConnection: node.PeerConnection;
32
- #config: RTCConfiguration;
33
- #localOffer: DeferredPromise<RTCSessionDescriptionInit>;
34
- #localAnswer: DeferredPromise<RTCSessionDescriptionInit>;
35
- #dataChannels: Set<DataChannel>;
36
-
37
- constructor(init: RTCConfiguration = {}) {
38
- super();
39
-
40
- this.#config = init;
41
- this.#localOffer = defer();
42
- this.#localAnswer = defer();
43
- this.#dataChannels = new Set();
44
-
45
- const iceServers = init.iceServers ?? [];
46
-
47
- this.#peerConnection = new node.PeerConnection(`peer-${Math.random()}`, {
48
- iceServers: iceServers
49
- .map((server) => {
50
- const urls = (Array.isArray(server.urls) ? server.urls : [server.urls]).map((str) => new URL(str));
51
-
52
- return urls.map((url) => {
53
- /** @type {import('../lib/index.js').IceServer} */
54
- const iceServer = {
55
- hostname: url.hostname,
56
- port: parseInt(url.port, 10),
57
- username: server.username,
58
- password: server.credential,
59
- // relayType - how to specify?
60
- };
61
-
62
- return iceServer;
63
- });
64
- })
65
- .flat(),
66
- iceTransportPolicy: init?.iceTransportPolicy,
67
- });
68
-
69
- this.#peerConnection.onStateChange(() => {
70
- this.dispatchEvent(new Event('connectionstatechange'));
71
- });
72
- // https://github.com/murat-dogan/node-datachannel/pull/171
73
- // this.#peerConnection.onSignalingStateChange(() => {
74
- // this.dispatchEvent(new Event('signalingstatechange'))
75
- // })
76
- this.#peerConnection.onGatheringStateChange(() => {
77
- this.dispatchEvent(new Event('icegatheringstatechange'));
78
- });
79
- this.#peerConnection.onDataChannel((channel) => {
80
- this.dispatchEvent(new DataChannelEvent(new DataChannel(channel)));
81
- });
82
-
83
- // forward events to properties
84
- this.addEventListener('connectionstatechange', (event) => {
85
- this.onconnectionstatechange?.(event);
86
- });
87
- this.addEventListener('signalingstatechange', (event) => {
88
- this.onsignalingstatechange?.(event);
89
- });
90
- this.addEventListener('icegatheringstatechange', (event) => {
91
- this.onicegatheringstatechange?.(event);
92
- });
93
- this.addEventListener('datachannel', (event) => {
94
- this.ondatachannel?.(event as RTCDataChannelEvent);
95
- });
96
-
97
- this.#peerConnection.onLocalDescription((sdp, type) => {
98
- if (type === 'offer') {
99
- this.#localOffer.resolve({
100
- sdp,
101
- type,
102
- });
103
- }
104
-
105
- if (type === 'answer') {
106
- this.#localAnswer.resolve({
107
- sdp,
108
- type,
109
- });
110
- }
111
- });
112
-
113
- this.#peerConnection.onLocalCandidate((candidate, mid) => {
114
- if (mid === 'unspec') {
115
- this.#localAnswer.reject(new Error(`Invalid description type ${mid}`));
116
- return;
117
- }
118
-
119
- const event = new PeerConnectionIceEvent(new IceCandidate({ candidate }));
120
-
121
- this.onicecandidate?.(event);
122
- });
123
-
124
- this.canTrickleIceCandidates = null;
125
- this.sctp = null;
126
- this.onconnectionstatechange = null;
127
- this.ondatachannel = null;
128
- this.onicecandidate = null;
129
- this.onicecandidateerror = null;
130
- this.oniceconnectionstatechange = null;
131
- this.onicegatheringstatechange = null;
132
- this.onnegotiationneeded = null;
133
- this.onsignalingstatechange = null;
134
- this.ontrack = null;
135
- }
136
-
137
- get connectionState(): RTCPeerConnectionState {
138
- return assertState(this.#peerConnection.state(), RTCPeerConnectionStates);
139
- }
140
-
141
- get iceConnectionState(): RTCIceConnectionState {
142
- return assertState(this.#peerConnection.state(), RTCIceConnectionStates);
143
- }
144
-
145
- get iceGatheringState(): RTCIceGatheringState {
146
- return assertState(this.#peerConnection.gatheringState(), RTCIceGatheringStates);
147
- }
148
-
149
- get signalingState(): RTCSignalingState {
150
- return assertState(this.#peerConnection.signalingState(), RTCSignalingStates);
151
- }
152
-
153
- get currentLocalDescription(): RTCSessionDescription | null {
154
- return toSessionDescription(this.#peerConnection.localDescription());
155
- }
156
-
157
- get localDescription(): RTCSessionDescription | null {
158
- return toSessionDescription(this.#peerConnection.localDescription());
159
- }
160
-
161
- get pendingLocalDescription(): RTCSessionDescription | null {
162
- return toSessionDescription(this.#peerConnection.localDescription());
163
- }
164
-
165
- get currentRemoteDescription(): RTCSessionDescription | null {
166
- // not exposed by node-datachannel
167
- console.log("node-datachannel doesn't expose currentRemoteDescription");
168
- return toSessionDescription(null);
169
- }
170
-
171
- get pendingRemoteDescription(): RTCSessionDescription | null {
172
- // not exposed by node-datachannel
173
- console.log("node-datachannel doesn't expose pendingRemoteDescription");
174
- return toSessionDescription(null);
175
- }
176
-
177
- get remoteDescription(): RTCSessionDescription | null {
178
- // not exposed by node-datachannel
179
- console.log("node-datachannel doesn't expose remoteDescription");
180
- return toSessionDescription(null);
181
- }
182
-
183
- async addIceCandidate(candidate?: RTCIceCandidateInit): Promise<void> {
184
- if (candidate == null || candidate.candidate == null) {
185
- throw new Error('Candidate invalid');
186
- }
187
-
188
- this.#peerConnection.addRemoteCandidate(candidate.candidate, candidate.sdpMid ?? '0');
189
- }
190
-
191
- addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender {
192
- throw new Error('addTrack Not implemented');
193
- }
194
-
195
- addTransceiver(trackOrKind: MediaStreamTrack | string, init?: RTCRtpTransceiverInit): RTCRtpTransceiver {
196
- throw new Error('addTransciever Not implemented');
197
- }
198
-
199
- close(): void {
200
- // close all channels before shutting down
201
- this.#dataChannels.forEach((channel) => {
202
- channel.close();
203
- });
204
-
205
- this.#peerConnection.close();
206
- this.#peerConnection.destroy();
207
- }
208
-
209
- createDataChannel(label: string, dataChannelDict: RTCDataChannelInit = {}): RTCDataChannel {
210
- const channel = this.#peerConnection.createDataChannel(label, dataChannelDict);
211
- const dataChannel = new DataChannel(channel, dataChannelDict);
212
-
213
- // ensure we can close all channels when shutting down
214
- this.#dataChannels.add(dataChannel);
215
- dataChannel.addEventListener('close', () => {
216
- this.#dataChannels.delete(dataChannel);
217
- });
218
-
219
- return dataChannel;
220
- }
221
-
222
- async createOffer(options?: RTCOfferOptions): Promise<RTCSessionDescriptionInit>;
223
- async createOffer(
224
- successCallback: RTCSessionDescriptionCallback,
225
- failureCallback: RTCPeerConnectionErrorCallback,
226
- options?: RTCOfferOptions,
227
- ): Promise<void>;
228
-
229
- async createOffer(...args: any[]): Promise<any> {
230
- return this.#localOffer.promise;
231
- }
232
-
233
- async createAnswer(options?: RTCAnswerOptions): Promise<RTCSessionDescriptionInit>;
234
- async createAnswer(
235
- successCallback: RTCSessionDescriptionCallback,
236
- failureCallback: RTCPeerConnectionErrorCallback,
237
- ): Promise<void>;
238
-
239
- async createAnswer(...args: any[]): Promise<any> {
240
- return this.#localAnswer.promise;
241
- }
242
-
243
- getConfiguration(): RTCConfiguration {
244
- return this.#config;
245
- }
246
-
247
- getReceivers(): RTCRtpReceiver[] {
248
- throw new Error('getReceivers Not implemented');
249
- }
250
-
251
- getSenders(): RTCRtpSender[] {
252
- throw new Error('getSenders Not implemented');
253
- }
254
-
255
- async getStats(selector?: MediaStreamTrack | null): Promise<RTCStatsReport> {
256
- throw new Error('getStats Not implemented');
257
- }
258
-
259
- getTransceivers(): RTCRtpTransceiver[] {
260
- throw new Error('getTranscievers Not implemented');
261
- }
262
-
263
- removeTrack(sender: RTCRtpSender): void {
264
- throw new Error('removeTrack Not implemented');
265
- }
266
-
267
- restartIce(): void {
268
- throw new Error('restartIce Not implemented');
269
- }
270
-
271
- setConfiguration(configuration: RTCConfiguration = {}): void {
272
- this.#config = configuration;
273
- }
274
-
275
- async setLocalDescription(description?: RTCLocalSessionDescriptionInit): Promise<void> {
276
- if (description == null || description.type == null) {
277
- throw new Error('Local description type must be set');
278
- }
279
-
280
- if (description.type !== 'offer') {
281
- console.log(`node-datachannel: setLocalDescription: only offer is supported, not ${description.type}`);
282
- // any other type causes libdatachannel to throw
283
- return;
284
- }
285
-
286
- // @ts-expect-error types are wrong
287
- this.#peerConnection.setLocalDescription(description.type);
288
- }
289
-
290
- async setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void> {
291
- if (description.sdp == null) {
292
- throw new Error('Remote SDP must be set');
293
- }
294
-
295
- // @ts-expect-error types are wrong
296
- this.#peerConnection.setRemoteDescription(description.sdp, description.type);
297
- }
298
- }
299
-
300
- export { PeerConnection as RTCPeerConnection };
301
-
302
- const assertState = <T>(state: any, states: T[]): T => {
303
- if (state != null && !states.includes(state)) {
304
- throw new Error(`Invalid value encountered - "${state}" must be one of ${states}`);
305
- }
306
-
307
- return state as T;
308
- };
309
-
310
- const toSessionDescription = (description: { sdp?: string; type: string } | null): RTCSessionDescription | null => {
311
- if (description == null) {
312
- return null;
313
- }
314
-
315
- return new SessionDescription({
316
- sdp: description.sdp,
317
- type: assertState(description.type, RTCSdpTypes),
318
- });
319
- };
320
-
321
- const RTCPeerConnectionStates: RTCPeerConnectionState[] = [
322
- 'closed',
323
- 'connected',
324
- 'connecting',
325
- 'disconnected',
326
- 'failed',
327
- 'new',
328
- ];
329
- const RTCSdpTypes: RTCSdpType[] = ['answer', 'offer', 'pranswer', 'rollback'];
330
- const RTCIceConnectionStates: RTCIceConnectionState[] = [
331
- 'checking',
332
- 'closed',
333
- 'completed',
334
- 'connected',
335
- 'disconnected',
336
- 'failed',
337
- 'new',
338
- ];
339
- const RTCIceGatheringStates: RTCIceGatheringState[] = ['complete', 'gathering', 'new'];
340
- const RTCSignalingStates: RTCSignalingState[] = [
341
- 'closed',
342
- 'have-local-offer',
343
- 'have-local-pranswer',
344
- 'have-remote-offer',
345
- 'have-remote-pranswer',
346
- 'stable',
347
- ];
@@ -1,23 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- /**
6
- * @see https://developer.mozilla.org/docs/Web/API/RTCSessionDescription
7
- */
8
- export class SessionDescription implements RTCSessionDescription {
9
- readonly sdp: string;
10
- readonly type: RTCSdpType;
11
-
12
- constructor(init: RTCSessionDescriptionInit) {
13
- this.sdp = init.sdp ?? '';
14
- this.type = init.type;
15
- }
16
-
17
- toJSON(): RTCSessionDescriptionInit {
18
- return {
19
- sdp: this.sdp,
20
- type: this.type,
21
- };
22
- }
23
- }