node-datachannel 0.9.1 → 0.10.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.
package/lib/index.d.cts CHANGED
@@ -63,7 +63,7 @@ export interface RtcConfig {
63
63
  }
64
64
 
65
65
  // Lowercase to match the description type string from libdatachannel
66
- export const enum DescriptionType {
66
+ export enum DescriptionType {
67
67
  Unspec = 'unspec',
68
68
  Offer = 'offer',
69
69
  Answer = 'answer',
@@ -71,26 +71,13 @@ export const enum DescriptionType {
71
71
  Rollback = 'rollback',
72
72
  }
73
73
 
74
- export const enum ReliabilityType {
75
- Reliable = 0,
76
- Rexmit = 1,
77
- Timed = 2,
78
- }
79
-
80
74
  export interface DataChannelInitConfig {
81
75
  protocol?: string;
82
76
  negotiated?: boolean;
83
77
  id?: number;
84
- ordered?: boolean;
85
- maxPacketLifeTime?: number;
86
- maxRetransmits?: number;
87
-
88
- // Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
89
- reliability?: {
90
- type?: ReliabilityType;
91
- unordered?: boolean;
92
- rexmit?: number;
93
- };
78
+ unordered?: boolean; // Reliability
79
+ maxPacketLifeTime?: number; // Reliability
80
+ maxRetransmits?: number; // Reliability
94
81
  }
95
82
 
96
83
  export interface SelectedCandidateInfo {
@@ -113,8 +100,7 @@ export const enum Direction {
113
100
  }
114
101
 
115
102
  export class RtcpReceivingSession {
116
- requestBitrate(bitRate: number): void;
117
- requestKeyframe(): boolean;
103
+ //
118
104
  }
119
105
 
120
106
  export class Audio {
package/lib/index.d.ts CHANGED
@@ -63,7 +63,7 @@ export interface RtcConfig {
63
63
  }
64
64
 
65
65
  // Lowercase to match the description type string from libdatachannel
66
- export const enum DescriptionType {
66
+ export enum DescriptionType {
67
67
  Unspec = 'unspec',
68
68
  Offer = 'offer',
69
69
  Answer = 'answer',
@@ -71,26 +71,13 @@ export const enum DescriptionType {
71
71
  Rollback = 'rollback',
72
72
  }
73
73
 
74
- export const enum ReliabilityType {
75
- Reliable = 0,
76
- Rexmit = 1,
77
- Timed = 2,
78
- }
79
-
80
74
  export interface DataChannelInitConfig {
81
75
  protocol?: string;
82
76
  negotiated?: boolean;
83
77
  id?: number;
84
- ordered?: boolean;
85
- maxPacketLifeTime?: number;
86
- maxRetransmits?: number;
87
-
88
- // Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
89
- reliability?: {
90
- type?: ReliabilityType;
91
- unordered?: boolean;
92
- rexmit?: number;
93
- };
78
+ unordered?: boolean; // Reliability
79
+ maxPacketLifeTime?: number; // Reliability
80
+ maxRetransmits?: number; // Reliability
94
81
  }
95
82
 
96
83
  export interface SelectedCandidateInfo {
@@ -113,8 +100,7 @@ export const enum Direction {
113
100
  }
114
101
 
115
102
  export class RtcpReceivingSession {
116
- requestBitrate(bitRate: number): void;
117
- requestKeyframe(): boolean;
103
+ //
118
104
  }
119
105
 
120
106
  export class Audio {
package/lib/index.js CHANGED
@@ -41,3 +41,11 @@ export default {
41
41
  ...nodeDataChannel,
42
42
  DataChannelStream,
43
43
  };
44
+
45
+ export const DescriptionType = {
46
+ Unspec: 'unspec',
47
+ Offer: 'offer',
48
+ Answer: 'answer',
49
+ Pranswer: 'pranswer',
50
+ Rollback: 'rollback',
51
+ };
package/package.json CHANGED
@@ -1,27 +1,28 @@
1
1
  {
2
2
  "name": "node-datachannel",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "libdatachannel node bindings",
5
5
  "type": "module",
6
+ "types": "./lib/index.d.ts",
6
7
  "exports": {
7
8
  ".": {
8
9
  "import": {
9
- "default": "./lib/index.js",
10
- "types": "./lib/index.d.ts"
10
+ "types": "./lib/index.d.ts",
11
+ "default": "./lib/index.js"
11
12
  },
12
13
  "require": {
13
- "default": "./lib/index.cjs",
14
- "types": "./lib/index.d.cts"
14
+ "types": "./lib/index.d.cts",
15
+ "default": "./lib/index.cjs"
15
16
  }
16
17
  },
17
18
  "./polyfill": {
18
19
  "import": {
19
- "default": "./polyfill/index.js",
20
- "types": "./polyfill/index.d.ts"
20
+ "types": "./polyfill/index.d.ts",
21
+ "default": "./polyfill/index.js"
21
22
  },
22
23
  "require": {
23
- "default": "./polyfill/index.cjs",
24
- "types": "./polyfill/index.d.cts"
24
+ "types": "./polyfill/index.d.cts",
25
+ "default": "./polyfill/index.cjs"
25
26
  }
26
27
  }
27
28
  },
@@ -4,11 +4,11 @@ import RTCDataChannel from './RTCDataChannel.js';
4
4
  import RTCIceCandidate from './RTCIceCandidate.js';
5
5
  import { RTCDataChannelEvent, RTCPeerConnectionIceEvent } from './Events.js';
6
6
  import RTCSctpTransport from './RTCSctpTransport.js';
7
- import DOMException from 'node-domexception';
7
+ import 'node-domexception';
8
8
 
9
9
  export default class _RTCPeerConnection extends EventTarget {
10
10
  static async generateCertificate() {
11
- throw new Error('Not implemented');
11
+ throw new DOMException('Not implemented');
12
12
  }
13
13
 
14
14
  #peerConnection;
@@ -192,10 +192,6 @@ export default class _RTCPeerConnection extends EventTarget {
192
192
  return this.#peerConnection.signalingState();
193
193
  }
194
194
 
195
- static generateCertificate(keygenAlgorithm) {
196
- throw new DOMException('Not implemented');
197
- }
198
-
199
195
  async addIceCandidate(candidate) {
200
196
  if (candidate == null || candidate.candidate == null) {
201
197
  throw new DOMException('Candidate invalid');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var DOMException = require('node-domexception');
5
+ var DOMException$1 = require('node-domexception');
6
6
  var module$1 = require('module');
7
7
  var stream = require('stream');
8
8
 
@@ -113,7 +113,7 @@ class _RTCDataChannel extends EventTarget {
113
113
 
114
114
  set binaryType(type) {
115
115
  if (type !== 'blob' && type !== 'arraybuffer') {
116
- throw new DOMException(
116
+ throw new DOMException$1(
117
117
  "Failed to set the 'binaryType' property on 'RTCDataChannel': Unknown binary type : " + type,
118
118
  'TypeMismatchError',
119
119
  );
@@ -173,7 +173,7 @@ class _RTCDataChannel extends EventTarget {
173
173
 
174
174
  send(data) {
175
175
  if (this.#readyState !== 'open') {
176
- throw new DOMException(
176
+ throw new DOMException$1(
177
177
  "Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open'",
178
178
  'InvalidStateError',
179
179
  );
@@ -223,7 +223,7 @@ class _RTCIceCandidate {
223
223
 
224
224
  constructor({ candidate, sdpMLineIndex, sdpMid, usernameFragment }) {
225
225
  if (candidate == null) {
226
- throw new DOMException('candidate must be specified');
226
+ throw new DOMException$1('candidate must be specified');
227
227
  }
228
228
 
229
229
  this.#candidate = candidate;
@@ -676,7 +676,7 @@ class _RTCSctpTransport extends EventTarget {
676
676
 
677
677
  class _RTCPeerConnection extends EventTarget {
678
678
  static async generateCertificate() {
679
- throw new Error('Not implemented');
679
+ throw new DOMException('Not implemented');
680
680
  }
681
681
 
682
682
  #peerConnection;
@@ -860,10 +860,6 @@ class _RTCPeerConnection extends EventTarget {
860
860
  return this.#peerConnection.signalingState();
861
861
  }
862
862
 
863
- static generateCertificate(keygenAlgorithm) {
864
- throw new DOMException('Not implemented');
865
- }
866
-
867
863
  async addIceCandidate(candidate) {
868
864
  if (candidate == null || candidate.candidate == null) {
869
865
  throw new DOMException('Candidate invalid');
@@ -11,8 +11,7 @@ Napi::Object RtcpReceivingSessionWrapper::Init(Napi::Env env, Napi::Object expor
11
11
  env,
12
12
  "RtcpReceivingSession",
13
13
  {
14
- Napi::ObjectWrap<RtcpReceivingSessionWrapper>::InstanceMethod("requestBitrate", &RtcpReceivingSessionWrapper::requestBitrate),
15
- Napi::ObjectWrap<RtcpReceivingSessionWrapper>::InstanceMethod("requestKeyframe", &RtcpReceivingSessionWrapper::requestKeyframe),
14
+ // Instance Methods
16
15
  });
17
16
 
18
17
  constructor = Napi::Persistent(func);
@@ -39,24 +38,3 @@ std::shared_ptr<rtc::RtcpReceivingSession> RtcpReceivingSessionWrapper::getSessi
39
38
  {
40
39
  return mSessionPtr;
41
40
  }
42
-
43
- void RtcpReceivingSessionWrapper::requestBitrate(const Napi::CallbackInfo &info)
44
- {
45
- Napi::Env env = info.Env();
46
- int length = info.Length();
47
-
48
- if (length < 1 || !info[0].IsNumber())
49
- {
50
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
51
- return;
52
- }
53
-
54
- unsigned int bitrate = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
55
- mSessionPtr->requestBitrate(bitrate);
56
- }
57
-
58
- Napi::Value RtcpReceivingSessionWrapper::requestKeyframe(const Napi::CallbackInfo &info)
59
- {
60
- Napi::Env env = info.Env();
61
- return Napi::Boolean::New(env, mSessionPtr->requestKeyframe());
62
- }
@@ -22,15 +22,12 @@ public:
22
22
  std::shared_ptr<rtc::RtcpReceivingSession> getSessionInstance();
23
23
 
24
24
  // Functions
25
- void requestBitrate(const Napi::CallbackInfo &info);
26
- Napi::Value requestKeyframe(const Napi::CallbackInfo &info);
27
25
 
28
26
  // Callbacks
29
-
30
27
 
31
28
  private:
32
- static std::unordered_set<RtcpReceivingSessionWrapper*> instances;
29
+ static std::unordered_set<RtcpReceivingSessionWrapper *> instances;
33
30
  std::shared_ptr<rtc::RtcpReceivingSession> mSessionPtr = nullptr;
34
31
  };
35
32
 
36
- #endif // MEDIA_RTCPRECEIVINGSESSION_WRAPPER_H
33
+ #endif // MEDIA_RTCPRECEIVINGSESSION_WRAPPER_H
@@ -249,7 +249,7 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
249
249
  PLOG_DEBUG << "Peer Connection created";
250
250
 
251
251
  // State change callback must be set to trigger cleanup on close
252
- mOnStateChangeCallback = std::make_unique<ThreadSafeCallback>(Napi::Function::New(info.Env(), [](const Napi::CallbackInfo&){}));
252
+ mOnStateChangeCallback = std::make_unique<ThreadSafeCallback>(Napi::Function::New(info.Env(), [](const Napi::CallbackInfo &) {}));
253
253
 
254
254
  instances.insert(this);
255
255
  }
@@ -503,81 +503,17 @@ Napi::Value PeerConnectionWrapper::createDataChannel(const Napi::CallbackInfo &i
503
503
  init.id = uint16_t(initConfig.Get("id").As<Napi::Number>().Uint32Value());
504
504
  }
505
505
 
506
- // Deprecated reliability object, kept for retro-compatibility
507
- if (!initConfig.Get("reliability").IsUndefined())
506
+ // Reliability.unordered parameter
507
+ if (!initConfig.Get("unordered").IsUndefined())
508
508
  {
509
- if (!initConfig.Get("reliability").IsObject())
509
+ if (!initConfig.Get("unordered").IsBoolean())
510
510
  {
511
- Napi::TypeError::New(env, "Wrong DataChannel Init Config (reliability)").ThrowAsJavaScriptException();
511
+ Napi::TypeError::New(env, "Wrong DataChannel Init Config (unordered)").ThrowAsJavaScriptException();
512
512
  return info.Env().Null();
513
513
  }
514
-
515
- Napi::Object reliability = initConfig.Get("reliability").As<Napi::Object>();
516
- if (!reliability.Get("type").IsUndefined())
517
- {
518
- if (!reliability.Get("type").IsNumber())
519
- {
520
- Napi::TypeError::New(env, "Wrong Reliability Config (type)").ThrowAsJavaScriptException();
521
- return info.Env().Null();
522
- }
523
- switch (reliability.Get("type").As<Napi::Number>().Uint32Value())
524
- {
525
- case 0:
526
- init.reliability.type = rtc::Reliability::Type::Reliable;
527
- break;
528
- case 1:
529
- init.reliability.type = rtc::Reliability::Type::Rexmit;
530
- break;
531
- case 2:
532
- init.reliability.type = rtc::Reliability::Type::Timed;
533
- break;
534
- default:
535
- Napi::TypeError::New(env, "Unknown DataChannel Reliability Type").ThrowAsJavaScriptException();
536
- return info.Env().Null();
537
- }
538
- }
539
-
540
- if (!reliability.Get("unordered").IsUndefined())
541
- {
542
- if (!reliability.Get("unordered").IsBoolean())
543
- {
544
- Napi::TypeError::New(env, "Wrong reliability Config (unordered)").ThrowAsJavaScriptException();
545
- return info.Env().Null();
546
- }
547
- init.reliability.unordered = reliability.Get("unordered").As<Napi::Boolean>();
548
- }
549
-
550
- if (!reliability.Get("rexmit").IsUndefined())
551
- {
552
- if (!reliability.Get("rexmit").IsNumber())
553
- {
554
- Napi::TypeError::New(env, "Wrong Reliability Config (rexmit)").ThrowAsJavaScriptException();
555
- return info.Env().Null();
556
- }
557
- switch (reliability.Get("type").As<Napi::Number>().Uint32Value())
558
- {
559
- case 1:
560
- init.reliability.rexmit = int(reliability.Get("rexmit").As<Napi::Number>().ToNumber().Uint32Value());
561
- break;
562
- case 2:
563
- init.reliability.rexmit = std::chrono::milliseconds(reliability.Get("rexmit").As<Napi::Number>().Int32Value());
564
- break;
565
- }
566
- }
514
+ init.reliability.unordered = !initConfig.Get("unordered").As<Napi::Boolean>();
567
515
  }
568
516
 
569
- // Reliability parameters
570
- if (!initConfig.Get("ordered").IsUndefined())
571
- {
572
- if (!initConfig.Get("ordered").IsBoolean())
573
- {
574
- Napi::TypeError::New(env, "Wrong DataChannel Init Config (ordered)").ThrowAsJavaScriptException();
575
- return info.Env().Null();
576
- }
577
- init.reliability.unordered = !initConfig.Get("ordered").As<Napi::Boolean>();
578
- }
579
-
580
-
581
517
  if (!initConfig.Get("maxPacketLifeTime").IsUndefined() && !initConfig.Get("maxPacketLifeTime").IsNull() &&
582
518
  !initConfig.Get("maxRetransmits").IsUndefined() && !initConfig.Get("maxRetransmits").IsNull())
583
519
  {
@@ -0,0 +1,10 @@
1
+ import { expect } from '@jest/globals';
2
+ import polyfill from '../../polyfill/index.js';
3
+
4
+ describe('polyfill', () => {
5
+ test('generateCertificate should throw', () => {
6
+ expect(async () => {
7
+ await polyfill.RTCPeerConnection.generateCertificate({});
8
+ }).rejects.toEqual(new DOMException('Not implemented'));
9
+ });
10
+ });
@@ -1,17 +0,0 @@
1
- set(CMAKE_SYSTEM_NAME Linux)
2
- set(TOOLCHAIN_PREFIX aarch64-linux-gnu)
3
-
4
- # cross compilers to use for C and C++
5
- set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
6
- set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
7
-
8
- # Needed sysroot
9
- # https://github.com/webrtc-uwp/chromium-build/blob/master/linux/sysroot_scripts/sysroots.json
10
- set(CMAKE_SYSROOT "$ENV{ARM64_SYSROOT}")
11
-
12
- set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
13
- set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
14
- set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
15
-
16
- set(CMAKE_C_FLAGS "-march=armv8-a -fPIC -Wno-error=format-truncation" CACHE STRING "Compiler Flags")
17
- set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Compiler Flags")
@@ -1,17 +0,0 @@
1
- set(CMAKE_SYSTEM_NAME Linux)
2
- set(TOOLCHAIN_PREFIX arm-linux-gnueabihf)
3
-
4
- # cross compilers to use for C and C++
5
- set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
6
- set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
7
-
8
- # Needed sysroot
9
- # https://github.com/webrtc-uwp/chromium-build/blob/master/linux/sysroot_scripts/sysroots.json
10
- set(CMAKE_SYSROOT "$ENV{ARM_SYSROOT}")
11
-
12
- set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
13
- set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
14
- set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
15
-
16
- set(CMAKE_C_FLAGS "-march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -fPIC -Wno-error=format-truncation" CACHE STRING "Compiler Flags")
17
- set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Compiler Flags")