node-datachannel 0.25.0 → 0.27.0

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 (43) hide show
  1. package/CMakeLists.txt +29 -10
  2. package/dist/cjs/lib/index.cjs +1 -3
  3. package/dist/cjs/lib/index.cjs.map +1 -1
  4. package/dist/cjs/polyfill/Events.cjs.map +1 -1
  5. package/dist/cjs/polyfill/RTCDataChannel.cjs +2 -0
  6. package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -1
  7. package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -1
  8. package/dist/cjs/polyfill/RTCError.cjs.map +1 -1
  9. package/dist/cjs/polyfill/RTCIceTransport.cjs.map +1 -1
  10. package/dist/cjs/polyfill/RTCPeerConnection.cjs +1 -1
  11. package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
  12. package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -1
  13. package/dist/esm/lib/index.mjs +1 -3
  14. package/dist/esm/lib/index.mjs.map +1 -1
  15. package/dist/esm/polyfill/Events.mjs.map +1 -1
  16. package/dist/esm/polyfill/RTCDataChannel.mjs +2 -0
  17. package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -1
  18. package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -1
  19. package/dist/esm/polyfill/RTCError.mjs.map +1 -1
  20. package/dist/esm/polyfill/RTCIceTransport.mjs.map +1 -1
  21. package/dist/esm/polyfill/RTCPeerConnection.mjs +1 -1
  22. package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
  23. package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -1
  24. package/dist/types/lib/index.d.ts +5 -2
  25. package/dist/types/polyfill/Events.d.ts +3 -6
  26. package/dist/types/polyfill/RTCDataChannel.d.ts +6 -6
  27. package/dist/types/polyfill/RTCDtlsTransport.d.ts +5 -8
  28. package/dist/types/polyfill/RTCIceTransport.d.ts +6 -9
  29. package/dist/types/polyfill/RTCPeerConnection.d.ts +20 -22
  30. package/dist/types/polyfill/RTCSctpTransport.d.ts +3 -6
  31. package/package.json +112 -102
  32. package/src/cpp/main.cpp +14 -0
  33. package/src/cpp/peer-connection-wrapper.cpp +9 -1
  34. package/src/cpp/peer-connection-wrapper.h +5 -1
  35. package/src/cpp/rtc-wrapper.cpp +18 -0
  36. package/src/lib/index.ts +5 -2
  37. package/src/polyfill/Events.ts +6 -10
  38. package/src/polyfill/RTCDataChannel.ts +9 -7
  39. package/src/polyfill/RTCDtlsTransport.ts +6 -7
  40. package/src/polyfill/RTCError.ts +1 -1
  41. package/src/polyfill/RTCIceTransport.ts +7 -8
  42. package/src/polyfill/RTCPeerConnection.ts +31 -30
  43. package/src/polyfill/RTCSctpTransport.ts +5 -6
@@ -12,6 +12,7 @@ import RTCCertificate from './RTCCertificate';
12
12
  // extend RTCConfiguration with peerIdentity
13
13
  interface RTCConfiguration extends globalThis.RTCConfiguration {
14
14
  peerIdentity?: string;
15
+ peerConnection?: PeerConnection;
15
16
  }
16
17
 
17
18
  export default class RTCPeerConnection extends EventTarget implements globalThis.RTCPeerConnection {
@@ -22,27 +23,27 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
22
23
  #peerConnection: PeerConnection;
23
24
  #localOffer: any;
24
25
  #localAnswer: any;
25
- #dataChannels: Set<RTCDataChannel>;
26
+ #dataChannels: Set<globalThis.RTCDataChannel>;
26
27
  #dataChannelsClosed = 0;
27
- #config: RTCConfiguration;
28
+ #config: globalThis.RTCConfiguration;
28
29
  #canTrickleIceCandidates: boolean | null;
29
- #sctp: RTCSctpTransport;
30
+ #sctp: globalThis.RTCSctpTransport;
30
31
 
31
- #localCandidates: RTCIceCandidate[] = [];
32
- #remoteCandidates: RTCIceCandidate[] = [];
32
+ #localCandidates: globalThis.RTCIceCandidate[] = [];
33
+ #remoteCandidates: globalThis.RTCIceCandidate[] = [];
33
34
 
34
35
  // events
35
- onconnectionstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
36
- ondatachannel: ((this: RTCPeerConnection, ev: RTCDataChannelEvent) => any) | null;
37
- onicecandidate: ((this: RTCPeerConnection, ev: RTCPeerConnectionIceEvent) => any) | null;
38
- onicecandidateerror: ((this: RTCPeerConnection, ev: Event) => any) | null;
39
- oniceconnectionstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
40
- onicegatheringstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
41
- onnegotiationneeded: ((this: RTCPeerConnection, ev: Event) => any) | null;
42
- onsignalingstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
43
- ontrack: ((this: RTCPeerConnection, ev: globalThis.RTCTrackEvent) => any) | null;
44
-
45
- private _checkConfiguration(config: RTCConfiguration): void {
36
+ onconnectionstatechange: ((this: globalThis.RTCPeerConnection, ev: Event) => any) | null;
37
+ ondatachannel: ((this: globalThis.RTCPeerConnection, ev: globalThis.RTCDataChannelEvent) => any) | null;
38
+ onicecandidate: ((this: globalThis.RTCPeerConnection, ev: globalThis.RTCPeerConnectionIceEvent) => any) | null;
39
+ onicecandidateerror: ((this: globalThis.RTCPeerConnection, ev: Event) => any) | null;
40
+ oniceconnectionstatechange: ((this: globalThis.RTCPeerConnection, ev: Event) => any) | null;
41
+ onicegatheringstatechange: ((this: globalThis.RTCPeerConnection, ev: Event) => any) | null;
42
+ onnegotiationneeded: ((this: globalThis.RTCPeerConnection, ev: Event) => any) | null;
43
+ onsignalingstatechange: ((this: globalThis.RTCPeerConnection, ev: Event) => any) | null;
44
+ ontrack: ((this: globalThis.RTCPeerConnection, ev: globalThis.RTCTrackEvent) => any) | null;
45
+
46
+ private _checkConfiguration(config: globalThis.RTCConfiguration): void {
46
47
  if (config && config.iceServers === undefined) config.iceServers = [];
47
48
  if (config && config.iceTransportPolicy === undefined) config.iceTransportPolicy = 'all';
48
49
 
@@ -102,7 +103,7 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
102
103
  throw new TypeError('IceTransportPolicy must be either "all" or "relay"');
103
104
  }
104
105
 
105
- setConfiguration(config: RTCConfiguration): void {
106
+ setConfiguration(config: globalThis.RTCConfiguration): void {
106
107
  this._checkConfiguration(config);
107
108
  this.#config = config;
108
109
  }
@@ -121,7 +122,7 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
121
122
 
122
123
  try {
123
124
  const peerIdentity = (config as any)?.peerIdentity ?? `peer-${getRandomString(7)}`;
124
- this.#peerConnection = new PeerConnection(peerIdentity,
125
+ this.#peerConnection = config?.peerConnection ?? new PeerConnection(peerIdentity,
125
126
  {
126
127
  ...config,
127
128
  iceServers:
@@ -202,10 +203,10 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
202
203
  if (this.onicegatheringstatechange) this.onicegatheringstatechange(e);
203
204
  });
204
205
  this.addEventListener('datachannel', (e) => {
205
- if (this.ondatachannel) this.ondatachannel(e as RTCDataChannelEvent);
206
+ if (this.ondatachannel) this.ondatachannel(e as globalThis.RTCDataChannelEvent);
206
207
  });
207
208
  this.addEventListener('icecandidate', (e) => {
208
- if (this.onicecandidate) this.onicecandidate(e as RTCPeerConnectionIceEvent);
209
+ if (this.onicecandidate) this.onicecandidate(e as globalThis.RTCPeerConnectionIceEvent);
209
210
  });
210
211
 
211
212
  this.#sctp = new RTCSctpTransport({
@@ -217,10 +218,10 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
217
218
  maxMessageSize: (): number => {
218
219
  return this.#peerConnection.maxMessageSize();
219
220
  },
220
- localCandidates: (): RTCIceCandidate[] => {
221
+ localCandidates: (): globalThis.RTCIceCandidate[] => {
221
222
  return this.#localCandidates;
222
223
  },
223
- remoteCandidates: (): RTCIceCandidate[] => {
224
+ remoteCandidates: (): globalThis.RTCIceCandidate[] => {
224
225
  return this.#remoteCandidates;
225
226
  },
226
227
  selectedCandidatePair: (): { local: SelectedCandidateInfo; remote: SelectedCandidateInfo } | null => {
@@ -250,31 +251,31 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
250
251
  return this.#peerConnection.gatheringState();
251
252
  }
252
253
 
253
- get currentLocalDescription(): RTCSessionDescription {
254
+ get currentLocalDescription(): globalThis.RTCSessionDescription {
254
255
  return new RTCSessionDescription(this.#peerConnection.localDescription() as any);
255
256
  }
256
257
 
257
- get currentRemoteDescription(): RTCSessionDescription {
258
+ get currentRemoteDescription(): globalThis.RTCSessionDescription {
258
259
  return new RTCSessionDescription(this.#peerConnection.remoteDescription() as any);
259
260
  }
260
261
 
261
- get localDescription(): RTCSessionDescription {
262
+ get localDescription(): globalThis.RTCSessionDescription {
262
263
  return new RTCSessionDescription(this.#peerConnection.localDescription() as any);
263
264
  }
264
265
 
265
- get pendingLocalDescription(): RTCSessionDescription {
266
+ get pendingLocalDescription(): globalThis.RTCSessionDescription {
266
267
  return new RTCSessionDescription(this.#peerConnection.localDescription() as any);
267
268
  }
268
269
 
269
- get pendingRemoteDescription(): RTCSessionDescription {
270
+ get pendingRemoteDescription():globalThis.RTCSessionDescription {
270
271
  return new RTCSessionDescription(this.#peerConnection.remoteDescription() as any);
271
272
  }
272
273
 
273
- get remoteDescription(): RTCSessionDescription {
274
+ get remoteDescription(): globalThis.RTCSessionDescription {
274
275
  return new RTCSessionDescription(this.#peerConnection.remoteDescription() as any);
275
276
  }
276
277
 
277
- get sctp(): RTCSctpTransport {
278
+ get sctp(): globalThis.RTCSctpTransport {
278
279
  return this.#sctp;
279
280
  }
280
281
 
@@ -349,7 +350,7 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
349
350
  }
350
351
 
351
352
 
352
- createDataChannel(label, opts = {}): RTCDataChannel {
353
+ createDataChannel(label, opts = {}): globalThis.RTCDataChannel {
353
354
  const channel = this.#peerConnection.createDataChannel(label, opts);
354
355
  const dataChannel = new RTCDataChannel(channel, opts);
355
356
 
@@ -1,15 +1,14 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import RTCDtlsTransport from './RTCDtlsTransport';
3
- import RTCPeerConnection from './RTCPeerConnection';
4
3
 
5
4
  export default class RTCSctpTransport extends EventTarget implements globalThis.RTCSctpTransport {
6
- #pc: RTCPeerConnection = null;
5
+ #pc: globalThis.RTCPeerConnection = null;
7
6
  #extraFunctions = null;
8
- #transport: RTCDtlsTransport = null;
7
+ #transport: globalThis.RTCDtlsTransport = null;
9
8
 
10
- onstatechange: ((this: RTCSctpTransport, ev: Event) => any) | null = null;
9
+ onstatechange: ((this: globalThis.RTCSctpTransport, ev: Event) => any) | null = null;
11
10
 
12
- constructor(initial: { pc: RTCPeerConnection, extraFunctions }) {
11
+ constructor(initial: { pc: globalThis.RTCPeerConnection, extraFunctions }) {
13
12
  super();
14
13
  this.#pc = initial.pc;
15
14
  this.#extraFunctions = initial.extraFunctions;
@@ -49,7 +48,7 @@ export default class RTCSctpTransport extends EventTarget implements globalThis.
49
48
  return state;
50
49
  }
51
50
 
52
- get transport(): RTCDtlsTransport {
51
+ get transport(): globalThis.RTCDtlsTransport {
53
52
  return this.#transport;
54
53
  }
55
54
  }