node-datachannel 0.29.0 → 0.31.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 (61) hide show
  1. package/.clang-format +17 -0
  2. package/CMakeLists.txt +16 -2
  3. package/dist/cjs/lib/index.cjs +21 -0
  4. package/dist/cjs/lib/index.cjs.map +1 -1
  5. package/dist/cjs/polyfill/RTCPeerConnection.cjs +6 -1
  6. package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
  7. package/dist/esm/lib/index.mjs +15 -1
  8. package/dist/esm/lib/index.mjs.map +1 -1
  9. package/dist/esm/polyfill/RTCPeerConnection.mjs +6 -1
  10. package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
  11. package/dist/types/lib/index.d.ts +58 -4
  12. package/dist/types/lib/types.d.ts +3 -1
  13. package/package.json +3 -2
  14. package/rollup.config.mjs +1 -1
  15. package/src/cpp/data-channel-wrapper.cpp +432 -411
  16. package/src/cpp/data-channel-wrapper.h +0 -2
  17. package/src/cpp/ice-udp-mux-listener-wrapper.cpp +104 -97
  18. package/src/cpp/main.cpp +25 -11
  19. package/src/cpp/media-audio-wrapper.cpp +291 -294
  20. package/src/cpp/media-audio-wrapper.h +1 -3
  21. package/src/cpp/media-av1packetization.cpp +24 -0
  22. package/src/cpp/media-av1packetization.h +11 -0
  23. package/src/cpp/media-av1rtppacketizer-wrapper.cpp +126 -0
  24. package/src/cpp/media-av1rtppacketizer-wrapper.h +29 -0
  25. package/src/cpp/media-direction.cpp +32 -32
  26. package/src/cpp/media-direction.h +1 -1
  27. package/src/cpp/media-h264rtppacketizer-wrapper.cpp +126 -0
  28. package/src/cpp/media-h264rtppacketizer-wrapper.h +30 -0
  29. package/src/cpp/media-h265rtppacketizer-wrapper.cpp +126 -0
  30. package/src/cpp/media-h265rtppacketizer-wrapper.h +30 -0
  31. package/src/cpp/media-h26xseparator.cpp +32 -0
  32. package/src/cpp/media-h26xseparator.h +11 -0
  33. package/src/cpp/media-mediahandler-helper.cpp +28 -0
  34. package/src/cpp/media-mediahandler-helper.h +11 -0
  35. package/src/cpp/media-rtcpnackresponder-wrapper.cpp +68 -0
  36. package/src/cpp/media-rtcpnackresponder-wrapper.h +28 -0
  37. package/src/cpp/media-rtcpreceivingsession-wrapper.cpp +38 -25
  38. package/src/cpp/media-rtcpreceivingsession-wrapper.h +1 -6
  39. package/src/cpp/media-rtcpsrreporter-wrapper.cpp +93 -0
  40. package/src/cpp/media-rtcpsrreporter-wrapper.h +30 -0
  41. package/src/cpp/media-rtppacketizationconfig-wrapper.cpp +167 -0
  42. package/src/cpp/media-rtppacketizationconfig-wrapper.h +35 -0
  43. package/src/cpp/media-rtppacketizer-wrapper.cpp +95 -0
  44. package/src/cpp/media-rtppacketizer-wrapper.h +30 -0
  45. package/src/cpp/media-track-wrapper.cpp +356 -340
  46. package/src/cpp/media-track-wrapper.h +0 -3
  47. package/src/cpp/media-video-wrapper.cpp +347 -313
  48. package/src/cpp/media-video-wrapper.h +3 -3
  49. package/src/cpp/peer-connection-wrapper.cpp +1094 -1047
  50. package/src/cpp/peer-connection-wrapper.h +0 -2
  51. package/src/cpp/rtc-wrapper.cpp +142 -138
  52. package/src/cpp/rtc-wrapper.h +8 -10
  53. package/src/cpp/thread-safe-callback.cpp +39 -50
  54. package/src/cpp/thread-safe-callback.h +26 -28
  55. package/src/cpp/web-socket-server-wrapper.cpp +205 -199
  56. package/src/cpp/web-socket-server-wrapper.h +0 -4
  57. package/src/cpp/web-socket-wrapper.cpp +625 -598
  58. package/src/cpp/web-socket-wrapper.h +0 -3
  59. package/src/lib/index.ts +69 -2
  60. package/src/lib/types.ts +6 -0
  61. package/src/polyfill/RTCPeerConnection.ts +8 -2
@@ -6,487 +6,521 @@ std::unordered_set<VideoWrapper *> VideoWrapper::instances;
6
6
 
7
7
  Napi::Object VideoWrapper::Init(Napi::Env env, Napi::Object exports)
8
8
  {
9
- Napi::HandleScope scope(env);
10
-
11
- Napi::Function func = Napi::ObjectWrap<VideoWrapper>::DefineClass(
12
- env,
13
- "Video",
14
- {
15
- InstanceValue("media-type-video", Napi::Boolean::New(env, true)),
16
- InstanceMethod("addH264Codec", &VideoWrapper::addH264Codec),
17
- InstanceMethod("addVideoCodec", &VideoWrapper::addVideoCodec),
18
- InstanceMethod("addVP8Codec", &VideoWrapper::addVP8Codec),
19
- InstanceMethod("addVP9Codec", &VideoWrapper::addVP9Codec),
20
- InstanceMethod("direction", &VideoWrapper::direction),
21
- InstanceMethod("generateSdp", &VideoWrapper::generateSdp),
22
- InstanceMethod("mid", &VideoWrapper::mid),
23
- InstanceMethod("setDirection", &VideoWrapper::setDirection),
24
- InstanceMethod("description", &VideoWrapper::description),
25
- InstanceMethod("removeFormat", &VideoWrapper::removeFormat),
26
- InstanceMethod("addSSRC", &VideoWrapper::addSSRC),
27
- InstanceMethod("removeSSRC", &VideoWrapper::removeSSRC),
28
- InstanceMethod("replaceSSRC", &VideoWrapper::replaceSSRC),
29
- InstanceMethod("hasSSRC", &VideoWrapper::hasSSRC),
30
- InstanceMethod("getSSRCs", &VideoWrapper::getSSRCs),
31
- InstanceMethod("getCNameForSsrc", &VideoWrapper::getCNameForSsrc),
32
- InstanceMethod("setBitrate", &VideoWrapper::setBitrate),
33
- InstanceMethod("getBitrate", &VideoWrapper::getBitrate),
34
- InstanceMethod("hasPayloadType", &VideoWrapper::hasPayloadType),
35
- InstanceMethod("addRTXCodec", &VideoWrapper::addRTXCodec),
36
- InstanceMethod("addRTPMap", &VideoWrapper::addRTPMap),
37
- InstanceMethod("parseSdpLine", &VideoWrapper::parseSdpLine),
38
- });
39
-
40
- // If this is not the first call, we don't want to reassign the constructor (hot-reload problem)
41
- if(constructor.IsEmpty())
42
- {
43
- constructor = Napi::Persistent(func);
44
- constructor.SuppressDestruct();
45
- }
46
-
47
- exports.Set("Video", func);
48
- return exports;
9
+ Napi::HandleScope scope(env);
10
+
11
+ Napi::Function func =
12
+ Napi::ObjectWrap<VideoWrapper>::DefineClass(env, "Video",
13
+ {
14
+ InstanceValue("media-type-video", Napi::Boolean::New(env, true)),
15
+ InstanceMethod("addVideoCodec", &VideoWrapper::addVideoCodec),
16
+ InstanceMethod("addH264Codec", &VideoWrapper::addH264Codec),
17
+ InstanceMethod("addH265Codec", &VideoWrapper::addH265Codec),
18
+ InstanceMethod("addVP8Codec", &VideoWrapper::addVP8Codec),
19
+ InstanceMethod("addVP9Codec", &VideoWrapper::addVP9Codec),
20
+ InstanceMethod("addAV1Codec", &VideoWrapper::addAV1Codec),
21
+ InstanceMethod("direction", &VideoWrapper::direction),
22
+ InstanceMethod("generateSdp", &VideoWrapper::generateSdp),
23
+ InstanceMethod("mid", &VideoWrapper::mid),
24
+ InstanceMethod("setDirection", &VideoWrapper::setDirection),
25
+ InstanceMethod("description", &VideoWrapper::description),
26
+ InstanceMethod("removeFormat", &VideoWrapper::removeFormat),
27
+ InstanceMethod("addSSRC", &VideoWrapper::addSSRC),
28
+ InstanceMethod("removeSSRC", &VideoWrapper::removeSSRC),
29
+ InstanceMethod("replaceSSRC", &VideoWrapper::replaceSSRC),
30
+ InstanceMethod("hasSSRC", &VideoWrapper::hasSSRC),
31
+ InstanceMethod("getSSRCs", &VideoWrapper::getSSRCs),
32
+ InstanceMethod("getCNameForSsrc", &VideoWrapper::getCNameForSsrc),
33
+ InstanceMethod("setBitrate", &VideoWrapper::setBitrate),
34
+ InstanceMethod("getBitrate", &VideoWrapper::getBitrate),
35
+ InstanceMethod("hasPayloadType", &VideoWrapper::hasPayloadType),
36
+ InstanceMethod("addRTXCodec", &VideoWrapper::addRTXCodec),
37
+ InstanceMethod("addRTPMap", &VideoWrapper::addRTPMap),
38
+ InstanceMethod("parseSdpLine", &VideoWrapper::parseSdpLine),
39
+ });
40
+
41
+ // If this is not the first call, we don't want to reassign the constructor (hot-reload problem)
42
+ if (constructor.IsEmpty())
43
+ {
44
+ constructor = Napi::Persistent(func);
45
+ constructor.SuppressDestruct();
46
+ }
47
+
48
+ exports.Set("Video", func);
49
+ return exports;
49
50
  }
50
51
 
51
52
  VideoWrapper::VideoWrapper(const Napi::CallbackInfo &info) : Napi::ObjectWrap<VideoWrapper>(info)
52
53
  {
53
- Napi::Env env = info.Env();
54
- int length = info.Length();
54
+ Napi::Env env = info.Env();
55
+ int length = info.Length();
55
56
 
56
- std::string mid = "video";
57
- rtc::Description::Direction dir = rtc::Description::Direction::Unknown;
57
+ std::string mid = "video";
58
+ rtc::Description::Direction dir = rtc::Description::Direction::Unknown;
58
59
 
59
- // optional
60
- if (length > 0)
60
+ // optional
61
+ if (length > 0)
62
+ {
63
+ if (!info[0].IsString())
61
64
  {
62
- if (!info[0].IsString())
63
- {
64
- Napi::TypeError::New(env, "mid (String) expected").ThrowAsJavaScriptException();
65
- return;
66
- }
67
- mid = info[0].As<Napi::String>().ToString();
65
+ Napi::TypeError::New(env, "mid (String) expected").ThrowAsJavaScriptException();
66
+ return;
68
67
  }
68
+ mid = info[0].As<Napi::String>().ToString();
69
+ }
69
70
 
70
- // ootional
71
- if (length > 1)
71
+ // ootional
72
+ if (length > 1)
73
+ {
74
+ if (!info[1].IsString())
72
75
  {
73
- if (!info[1].IsString())
74
- {
75
- Napi::TypeError::New(env, "direction (String) expected").ThrowAsJavaScriptException();
76
- return;
77
- }
78
-
79
- std::string dirAsStr = info[1].As<Napi::String>().ToString();
80
- dir = strToDirection(dirAsStr);
76
+ Napi::TypeError::New(env, "direction (String) expected").ThrowAsJavaScriptException();
77
+ return;
81
78
  }
82
79
 
83
- mVideoPtr = std::make_unique<rtc::Description::Video>(mid, dir);
80
+ std::string dirAsStr = info[1].As<Napi::String>().ToString();
81
+ dir = strToDirection(dirAsStr);
82
+ }
83
+
84
+ mVideoPtr = std::make_unique<rtc::Description::Video>(mid, dir);
84
85
 
85
- instances.insert(this);
86
+ instances.insert(this);
86
87
  }
87
88
 
88
89
  VideoWrapper::~VideoWrapper()
89
90
  {
90
- mVideoPtr.reset();
91
- instances.erase(this);
91
+ mVideoPtr.reset();
92
+ instances.erase(this);
92
93
  }
93
94
 
94
- rtc::Description::Video VideoWrapper::getVideoInstance()
95
- {
96
- return *(mVideoPtr.get());
97
- }
95
+ rtc::Description::Video VideoWrapper::getVideoInstance() { return *(mVideoPtr.get()); }
98
96
 
99
97
  void VideoWrapper::addVideoCodec(const Napi::CallbackInfo &info)
100
98
  {
101
- Napi::Env env = info.Env();
102
- int length = info.Length();
103
-
104
- if (length < 2 || !info[0].IsNumber() || !info[1].IsString())
105
- {
106
- Napi::TypeError::New(env, "We expect (Number, String, String[optional]) as param").ThrowAsJavaScriptException();
107
- return;
108
- }
109
-
110
- int payloadType = info[0].As<Napi::Number>().ToNumber();
111
- std::string codec = info[1].As<Napi::String>().ToString();
112
- std::optional<std::string> profile = std::nullopt;
113
-
114
- if (length > 2)
99
+ Napi::Env env = info.Env();
100
+ int length = info.Length();
101
+
102
+ if (length < 2 || !info[0].IsNumber() || !info[1].IsString())
103
+ {
104
+ Napi::TypeError::New(env, "We expect (Number, String, String[optional]) as param").ThrowAsJavaScriptException();
105
+ return;
106
+ }
107
+
108
+ int payloadType = info[0].As<Napi::Number>().ToNumber();
109
+ std::string codec = info[1].As<Napi::String>().ToString();
110
+ std::optional<std::string> profile = std::nullopt;
111
+
112
+ if (length > 2)
113
+ {
114
+ if (!info[2].IsString())
115
115
  {
116
- if (!info[2].IsString())
117
- {
118
- Napi::TypeError::New(env, "profile (String) expected").ThrowAsJavaScriptException();
119
- return;
120
- }
121
- profile = info[2].As<Napi::String>().ToString();
116
+ Napi::TypeError::New(env, "profile (String) expected").ThrowAsJavaScriptException();
117
+ return;
122
118
  }
119
+ profile = info[2].As<Napi::String>().ToString();
120
+ }
123
121
 
124
- mVideoPtr->addVideoCodec(payloadType, codec, profile);
122
+ mVideoPtr->addVideoCodec(payloadType, codec, profile);
125
123
  }
126
124
 
127
125
  void VideoWrapper::addH264Codec(const Napi::CallbackInfo &info)
128
126
  {
129
- Napi::Env env = info.Env();
130
- int length = info.Length();
127
+ Napi::Env env = info.Env();
128
+ int length = info.Length();
131
129
 
132
- if (length < 1 || !info[0].IsNumber())
133
- {
134
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
135
- return;
136
- }
130
+ if (length < 1 || !info[0].IsNumber())
131
+ {
132
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
133
+ return;
134
+ }
137
135
 
138
- int payloadType = info[0].As<Napi::Number>().ToNumber();
139
- std::string profile = rtc::DEFAULT_H264_VIDEO_PROFILE;
136
+ int payloadType = info[0].As<Napi::Number>().ToNumber();
137
+ std::string profile = rtc::DEFAULT_H264_VIDEO_PROFILE;
140
138
 
141
- if (length > 1)
139
+ if (length > 1)
140
+ {
141
+ if (!info[1].IsString())
142
142
  {
143
- if (!info[1].IsString())
144
- {
145
- Napi::TypeError::New(env, "profile (String) expected").ThrowAsJavaScriptException();
146
- return;
147
- }
148
- profile = info[1].As<Napi::String>().ToString();
143
+ Napi::TypeError::New(env, "profile (String) expected").ThrowAsJavaScriptException();
144
+ return;
149
145
  }
146
+ profile = info[1].As<Napi::String>().ToString();
147
+ }
150
148
 
151
- mVideoPtr->addH264Codec(payloadType, profile);
149
+ mVideoPtr->addH264Codec(payloadType, profile);
150
+ }
151
+
152
+ void VideoWrapper::addH265Codec(const Napi::CallbackInfo &info)
153
+ {
154
+ Napi::Env env = info.Env();
155
+ int length = info.Length();
156
+
157
+ if (length < 1 || !info[0].IsNumber())
158
+ {
159
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
160
+ return;
161
+ }
162
+
163
+ int payloadType = info[0].As<Napi::Number>().ToNumber();
164
+
165
+ mVideoPtr->addH265Codec(payloadType);
152
166
  }
153
167
 
154
168
  void VideoWrapper::addVP8Codec(const Napi::CallbackInfo &info)
155
169
  {
156
- Napi::Env env = info.Env();
157
- int length = info.Length();
170
+ Napi::Env env = info.Env();
171
+ int length = info.Length();
158
172
 
159
- if (length < 1 || !info[0].IsNumber())
160
- {
161
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
162
- return;
163
- }
173
+ if (length < 1 || !info[0].IsNumber())
174
+ {
175
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
176
+ return;
177
+ }
164
178
 
165
- int payloadType = info[0].As<Napi::Number>().ToNumber();
179
+ int payloadType = info[0].As<Napi::Number>().ToNumber();
166
180
 
167
- mVideoPtr->addVP8Codec(payloadType);
181
+ mVideoPtr->addVP8Codec(payloadType);
168
182
  }
169
183
 
170
184
  void VideoWrapper::addVP9Codec(const Napi::CallbackInfo &info)
171
185
  {
172
- Napi::Env env = info.Env();
173
- int length = info.Length();
186
+ Napi::Env env = info.Env();
187
+ int length = info.Length();
174
188
 
175
- if (length < 1 || !info[0].IsNumber())
176
- {
177
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
178
- return;
179
- }
189
+ if (length < 1 || !info[0].IsNumber())
190
+ {
191
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
192
+ return;
193
+ }
180
194
 
181
- int payloadType = info[0].As<Napi::Number>().ToNumber();
195
+ int payloadType = info[0].As<Napi::Number>().ToNumber();
182
196
 
183
- mVideoPtr->addVP9Codec(payloadType);
197
+ mVideoPtr->addVP9Codec(payloadType);
184
198
  }
185
199
 
200
+ void VideoWrapper::addAV1Codec(const Napi::CallbackInfo &info)
201
+ {
202
+ Napi::Env env = info.Env();
203
+ int length = info.Length();
204
+
205
+ if (length < 1 || !info[0].IsNumber())
206
+ {
207
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
208
+ return;
209
+ }
210
+
211
+ int payloadType = info[0].As<Napi::Number>().ToNumber();
212
+
213
+ mVideoPtr->addAV1Codec(payloadType);
214
+ }
215
+
216
+
186
217
  Napi::Value VideoWrapper::direction(const Napi::CallbackInfo &info)
187
218
  {
188
- Napi::Env env = info.Env();
189
- return Napi::String::New(env, directionToStr(mVideoPtr->direction()));
219
+ Napi::Env env = info.Env();
220
+ return Napi::String::New(env, directionToStr(mVideoPtr->direction()));
190
221
  }
191
222
 
192
223
  Napi::Value VideoWrapper::generateSdp(const Napi::CallbackInfo &info)
193
224
  {
194
- Napi::Env env = info.Env();
195
- int length = info.Length();
225
+ Napi::Env env = info.Env();
226
+ int length = info.Length();
196
227
 
197
- if (length < 3 || !info[0].IsString() || !info[1].IsString() || !info[2].IsNumber())
198
- {
199
- Napi::TypeError::New(env, "We expect (String, String, Number) as param").ThrowAsJavaScriptException();
200
- return Napi::String::New(env, "");
201
- }
228
+ if (length < 3 || !info[0].IsString() || !info[1].IsString() || !info[2].IsNumber())
229
+ {
230
+ Napi::TypeError::New(env, "We expect (String, String, Number) as param").ThrowAsJavaScriptException();
231
+ return Napi::String::New(env, "");
232
+ }
202
233
 
203
- std::string eol = info[0].As<Napi::String>().ToString();
204
- std::string addr = info[1].As<Napi::String>().ToString();
205
- uint16_t port = info[2].As<Napi::Number>().Uint32Value();
234
+ std::string eol = info[0].As<Napi::String>().ToString();
235
+ std::string addr = info[1].As<Napi::String>().ToString();
236
+ uint16_t port = info[2].As<Napi::Number>().Uint32Value();
206
237
 
207
- return Napi::String::New(env, mVideoPtr->generateSdp(eol, addr, port));
238
+ return Napi::String::New(env, mVideoPtr->generateSdp(eol, addr, port));
208
239
  }
209
240
 
210
241
  Napi::Value VideoWrapper::mid(const Napi::CallbackInfo &info)
211
242
  {
212
- Napi::Env env = info.Env();
213
- return Napi::String::New(env, mVideoPtr->mid());
243
+ Napi::Env env = info.Env();
244
+ return Napi::String::New(env, mVideoPtr->mid());
214
245
  }
215
246
 
216
247
  void VideoWrapper::setDirection(const Napi::CallbackInfo &info)
217
248
  {
218
- Napi::Env env = info.Env();
219
- int length = info.Length();
220
-
221
- if (length < 1 || !info[0].IsString())
222
- {
223
- Napi::TypeError::New(env, "We expect (String) as param").ThrowAsJavaScriptException();
224
- return;
225
- }
226
-
227
- std::string dirAsStr = info[0].As<Napi::String>().ToString();
228
- rtc::Description::Direction dir = strToDirection(dirAsStr);
229
- mVideoPtr->setDirection(dir);
249
+ Napi::Env env = info.Env();
250
+ int length = info.Length();
251
+
252
+ if (length < 1 || !info[0].IsString())
253
+ {
254
+ Napi::TypeError::New(env, "We expect (String) as param").ThrowAsJavaScriptException();
255
+ return;
256
+ }
257
+
258
+ std::string dirAsStr = info[0].As<Napi::String>().ToString();
259
+ rtc::Description::Direction dir = strToDirection(dirAsStr);
260
+ mVideoPtr->setDirection(dir);
230
261
  }
231
262
 
232
263
  Napi::Value VideoWrapper::description(const Napi::CallbackInfo &info)
233
264
  {
234
- Napi::Env env = info.Env();
235
- return Napi::String::New(env, mVideoPtr->description());
265
+ Napi::Env env = info.Env();
266
+ return Napi::String::New(env, mVideoPtr->description());
236
267
  }
237
268
 
238
269
  void VideoWrapper::removeFormat(const Napi::CallbackInfo &info)
239
270
  {
240
- Napi::Env env = info.Env();
241
- int length = info.Length();
271
+ Napi::Env env = info.Env();
272
+ int length = info.Length();
242
273
 
243
- if (length < 1 || !info[0].IsString())
244
- {
245
- Napi::TypeError::New(env, "We expect (String) as param").ThrowAsJavaScriptException();
246
- return;
247
- }
274
+ if (length < 1 || !info[0].IsString())
275
+ {
276
+ Napi::TypeError::New(env, "We expect (String) as param").ThrowAsJavaScriptException();
277
+ return;
278
+ }
248
279
 
249
- std::string fmt = info[0].As<Napi::String>().ToString();
280
+ std::string fmt = info[0].As<Napi::String>().ToString();
250
281
 
251
- mVideoPtr->removeFormat(fmt);
282
+ mVideoPtr->removeFormat(fmt);
252
283
  }
253
284
 
254
285
  void VideoWrapper::addSSRC(const Napi::CallbackInfo &info)
255
286
  {
256
- Napi::Env env = info.Env();
257
- int length = info.Length();
258
-
259
- if (length < 1 || !info[0].IsNumber())
287
+ Napi::Env env = info.Env();
288
+ int length = info.Length();
289
+
290
+ if (length < 1 || !info[0].IsNumber())
291
+ {
292
+ Napi::TypeError::New(env, "We expect (Number, String[optional], String[optional], String[optional]) as param")
293
+ .ThrowAsJavaScriptException();
294
+ return;
295
+ }
296
+
297
+ uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
298
+ std::optional<std::string> name;
299
+ std::optional<std::string> msid = std::nullopt;
300
+ std::optional<std::string> trackID = std::nullopt;
301
+
302
+ if (length > 1)
303
+ {
304
+ if (!info[1].IsString())
260
305
  {
261
- Napi::TypeError::New(env, "We expect (Number, String[optional], String[optional], String[optional]) as param").ThrowAsJavaScriptException();
262
- return;
306
+ Napi::TypeError::New(env, "name as String expected").ThrowAsJavaScriptException();
307
+ return;
263
308
  }
309
+ name = info[1].As<Napi::String>().ToString();
310
+ }
264
311
 
265
- uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
266
- std::optional<std::string> name;
267
- std::optional<std::string> msid = std::nullopt;
268
- std::optional<std::string> trackID = std::nullopt;
269
-
270
- if (length > 1)
271
- {
272
- if (!info[1].IsString())
273
- {
274
- Napi::TypeError::New(env, "name as String expected").ThrowAsJavaScriptException();
275
- return;
276
- }
277
- name = info[1].As<Napi::String>().ToString();
278
- }
279
-
280
- if (length > 2)
312
+ if (length > 2)
313
+ {
314
+ if (!info[2].IsString())
281
315
  {
282
- if (!info[2].IsString())
283
- {
284
- Napi::TypeError::New(env, "msid as String expected").ThrowAsJavaScriptException();
285
- return;
286
- }
287
- msid = info[2].As<Napi::String>().ToString();
316
+ Napi::TypeError::New(env, "msid as String expected").ThrowAsJavaScriptException();
317
+ return;
288
318
  }
319
+ msid = info[2].As<Napi::String>().ToString();
320
+ }
289
321
 
290
- if (length > 3)
322
+ if (length > 3)
323
+ {
324
+ if (!info[3].IsString())
291
325
  {
292
- if (!info[3].IsString())
293
- {
294
- Napi::TypeError::New(env, "trackID as String expected").ThrowAsJavaScriptException();
295
- return;
296
- }
297
- trackID = info[3].As<Napi::String>().ToString();
326
+ Napi::TypeError::New(env, "trackID as String expected").ThrowAsJavaScriptException();
327
+ return;
298
328
  }
329
+ trackID = info[3].As<Napi::String>().ToString();
330
+ }
299
331
 
300
- mVideoPtr->addSSRC(ssrc, name, msid, trackID);
332
+ mVideoPtr->addSSRC(ssrc, name, msid, trackID);
301
333
  }
302
334
 
303
335
  void VideoWrapper::removeSSRC(const Napi::CallbackInfo &info)
304
336
  {
305
- Napi::Env env = info.Env();
306
- int length = info.Length();
337
+ Napi::Env env = info.Env();
338
+ int length = info.Length();
307
339
 
308
- if (length < 1 || !info[0].IsNumber())
309
- {
310
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
311
- return;
312
- }
340
+ if (length < 1 || !info[0].IsNumber())
341
+ {
342
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
343
+ return;
344
+ }
313
345
 
314
- uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
346
+ uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
315
347
 
316
- mVideoPtr->removeSSRC(ssrc);
348
+ mVideoPtr->removeSSRC(ssrc);
317
349
  }
318
350
 
319
351
  void VideoWrapper::replaceSSRC(const Napi::CallbackInfo &info)
320
352
  {
321
- Napi::Env env = info.Env();
322
- int length = info.Length();
323
-
324
- if (length < 2 || !info[0].IsNumber() || !info[1].IsNumber())
353
+ Napi::Env env = info.Env();
354
+ int length = info.Length();
355
+
356
+ if (length < 2 || !info[0].IsNumber() || !info[1].IsNumber())
357
+ {
358
+ Napi::TypeError::New(env,
359
+ "We expect (Number, Number, String[optional], String[optional], String[optional]) as param")
360
+ .ThrowAsJavaScriptException();
361
+ return;
362
+ }
363
+
364
+ uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
365
+ uint32_t oldSsrc = static_cast<uint32_t>(info[1].As<Napi::Number>().ToNumber());
366
+ std::optional<std::string> name;
367
+ std::optional<std::string> msid = std::nullopt;
368
+ std::optional<std::string> trackID = std::nullopt;
369
+
370
+ if (length > 2)
371
+ {
372
+ if (!info[2].IsString())
325
373
  {
326
- Napi::TypeError::New(env, "We expect (Number, Number, String[optional], String[optional], String[optional]) as param").ThrowAsJavaScriptException();
327
- return;
374
+ Napi::TypeError::New(env, "name as String expected").ThrowAsJavaScriptException();
375
+ return;
328
376
  }
377
+ name = info[2].As<Napi::String>().ToString();
378
+ }
329
379
 
330
- uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
331
- uint32_t oldSsrc = static_cast<uint32_t>(info[1].As<Napi::Number>().ToNumber());
332
- std::optional<std::string> name;
333
- std::optional<std::string> msid = std::nullopt;
334
- std::optional<std::string> trackID = std::nullopt;
335
-
336
- if (length > 2)
380
+ if (length > 3)
381
+ {
382
+ if (!info[3].IsString())
337
383
  {
338
- if (!info[2].IsString())
339
- {
340
- Napi::TypeError::New(env, "name as String expected").ThrowAsJavaScriptException();
341
- return;
342
- }
343
- name = info[2].As<Napi::String>().ToString();
384
+ Napi::TypeError::New(env, "msid as String expected").ThrowAsJavaScriptException();
385
+ return;
344
386
  }
387
+ msid = info[3].As<Napi::String>().ToString();
388
+ }
345
389
 
346
- if (length > 3)
390
+ if (length > 4)
391
+ {
392
+ if (!info[4].IsString())
347
393
  {
348
- if (!info[3].IsString())
349
- {
350
- Napi::TypeError::New(env, "msid as String expected").ThrowAsJavaScriptException();
351
- return;
352
- }
353
- msid = info[3].As<Napi::String>().ToString();
394
+ Napi::TypeError::New(env, "trackID as String expected").ThrowAsJavaScriptException();
395
+ return;
354
396
  }
397
+ trackID = info[4].As<Napi::String>().ToString();
398
+ }
355
399
 
356
- if (length > 4)
357
- {
358
- if (!info[4].IsString())
359
- {
360
- Napi::TypeError::New(env, "trackID as String expected").ThrowAsJavaScriptException();
361
- return;
362
- }
363
- trackID = info[4].As<Napi::String>().ToString();
364
- }
365
-
366
- mVideoPtr->replaceSSRC(oldSsrc, ssrc, name, msid, trackID);
400
+ mVideoPtr->replaceSSRC(oldSsrc, ssrc, name, msid, trackID);
367
401
  }
368
402
 
369
403
  Napi::Value VideoWrapper::hasSSRC(const Napi::CallbackInfo &info)
370
404
  {
371
- Napi::Env env = info.Env();
372
- int length = info.Length();
405
+ Napi::Env env = info.Env();
406
+ int length = info.Length();
373
407
 
374
- if (length < 1 || !info[0].IsNumber())
375
- {
376
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
377
- return env.Null();
378
- }
408
+ if (length < 1 || !info[0].IsNumber())
409
+ {
410
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
411
+ return env.Null();
412
+ }
379
413
 
380
- uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
414
+ uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
381
415
 
382
- return Napi::Boolean::New(env, mVideoPtr->hasSSRC(ssrc));
416
+ return Napi::Boolean::New(env, mVideoPtr->hasSSRC(ssrc));
383
417
  }
384
418
 
385
419
  Napi::Value VideoWrapper::getSSRCs(const Napi::CallbackInfo &info)
386
420
  {
387
- Napi::Env env = info.Env();
421
+ Napi::Env env = info.Env();
388
422
 
389
- auto list = mVideoPtr->getSSRCs();
423
+ auto list = mVideoPtr->getSSRCs();
390
424
 
391
- Napi::Uint32Array napiArr = Napi::Uint32Array::New(env, list.size());
392
- for (size_t i = 0; i < list.size(); i++)
393
- napiArr[i] = list[i];
425
+ Napi::Uint32Array napiArr = Napi::Uint32Array::New(env, list.size());
426
+ for (size_t i = 0; i < list.size(); i++)
427
+ napiArr[i] = list[i];
394
428
 
395
- return napiArr;
429
+ return napiArr;
396
430
  }
397
431
 
398
432
  Napi::Value VideoWrapper::getCNameForSsrc(const Napi::CallbackInfo &info)
399
433
  {
400
- Napi::Env env = info.Env();
401
- int length = info.Length();
434
+ Napi::Env env = info.Env();
435
+ int length = info.Length();
402
436
 
403
- if (length < 1 || !info[0].IsNumber())
404
- {
405
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
406
- return env.Null();
407
- }
437
+ if (length < 1 || !info[0].IsNumber())
438
+ {
439
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
440
+ return env.Null();
441
+ }
408
442
 
409
- uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
443
+ uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
410
444
 
411
- std::optional<std::string> name = mVideoPtr->getCNameForSsrc(ssrc);
445
+ std::optional<std::string> name = mVideoPtr->getCNameForSsrc(ssrc);
412
446
 
413
- if (!name.has_value())
414
- return env.Null();
447
+ if (!name.has_value())
448
+ return env.Null();
415
449
 
416
- return Napi::String::New(env, name.value());
450
+ return Napi::String::New(env, name.value());
417
451
  }
418
452
 
419
453
  void VideoWrapper::setBitrate(const Napi::CallbackInfo &info)
420
454
  {
421
- Napi::Env env = info.Env();
422
- int length = info.Length();
455
+ Napi::Env env = info.Env();
456
+ int length = info.Length();
423
457
 
424
- if (length < 1 || !info[0].IsNumber())
425
- {
426
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
427
- return;
428
- }
458
+ if (length < 1 || !info[0].IsNumber())
459
+ {
460
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
461
+ return;
462
+ }
429
463
 
430
- unsigned int bitrate = info[0].As<Napi::Number>().ToNumber().Uint32Value();
431
- mVideoPtr->setBitrate(bitrate);
464
+ unsigned int bitrate = info[0].As<Napi::Number>().ToNumber().Uint32Value();
465
+ mVideoPtr->setBitrate(bitrate);
432
466
  }
433
467
 
434
468
  Napi::Value VideoWrapper::getBitrate(const Napi::CallbackInfo &info)
435
469
  {
436
- return Napi::Number::New(info.Env(), mVideoPtr->bitrate());
470
+ return Napi::Number::New(info.Env(), mVideoPtr->bitrate());
437
471
  }
438
472
 
439
473
  Napi::Value VideoWrapper::hasPayloadType(const Napi::CallbackInfo &info)
440
474
  {
441
- Napi::Env env = info.Env();
442
- int length = info.Length();
475
+ Napi::Env env = info.Env();
476
+ int length = info.Length();
443
477
 
444
- if (length < 1 || !info[0].IsNumber())
445
- {
446
- Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
447
- return env.Null();
448
- }
478
+ if (length < 1 || !info[0].IsNumber())
479
+ {
480
+ Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
481
+ return env.Null();
482
+ }
449
483
 
450
- int payloadType = static_cast<int32_t>(info[0].As<Napi::Number>().ToNumber());
484
+ int payloadType = static_cast<int32_t>(info[0].As<Napi::Number>().ToNumber());
451
485
 
452
- return Napi::Boolean::New(env, mVideoPtr->hasPayloadType(payloadType));
486
+ return Napi::Boolean::New(env, mVideoPtr->hasPayloadType(payloadType));
453
487
  }
454
488
 
455
489
  void VideoWrapper::addRTXCodec(const Napi::CallbackInfo &info)
456
490
  {
457
- Napi::Env env = info.Env();
458
- int length = info.Length();
491
+ Napi::Env env = info.Env();
492
+ int length = info.Length();
459
493
 
460
- if (length < 3 || !info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
461
- {
462
- Napi::TypeError::New(env, "We expect (Number,Number,Number) as param").ThrowAsJavaScriptException();
463
- return;
464
- }
494
+ if (length < 3 || !info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
495
+ {
496
+ Napi::TypeError::New(env, "We expect (Number,Number,Number) as param").ThrowAsJavaScriptException();
497
+ return;
498
+ }
465
499
 
466
- int payloadType = static_cast<int32_t>(info[0].As<Napi::Number>().ToNumber());
467
- int originalPayloadType = static_cast<int32_t>(info[1].As<Napi::Number>().ToNumber());
468
- unsigned int clockRate = static_cast<uint32_t>(info[2].As<Napi::Number>().ToNumber());
500
+ int payloadType = static_cast<int32_t>(info[0].As<Napi::Number>().ToNumber());
501
+ int originalPayloadType = static_cast<int32_t>(info[1].As<Napi::Number>().ToNumber());
502
+ unsigned int clockRate = static_cast<uint32_t>(info[2].As<Napi::Number>().ToNumber());
469
503
 
470
- mVideoPtr->addRtxCodec(payloadType, originalPayloadType, clockRate);
504
+ mVideoPtr->addRtxCodec(payloadType, originalPayloadType, clockRate);
471
505
  }
472
506
 
473
507
  void VideoWrapper::addRTPMap(const Napi::CallbackInfo &info)
474
508
  {
475
- // mVideoPtr->addRTPMap()
509
+ // mVideoPtr->addRTPMap()
476
510
  }
477
511
 
478
512
  void VideoWrapper::parseSdpLine(const Napi::CallbackInfo &info)
479
513
  {
480
- Napi::Env env = info.Env();
481
- int length = info.Length();
514
+ Napi::Env env = info.Env();
515
+ int length = info.Length();
482
516
 
483
- if (length < 1 || !info[0].IsString())
484
- {
485
- Napi::TypeError::New(env, "We expect (String) as param").ThrowAsJavaScriptException();
486
- return;
487
- }
517
+ if (length < 1 || !info[0].IsString())
518
+ {
519
+ Napi::TypeError::New(env, "We expect (String) as param").ThrowAsJavaScriptException();
520
+ return;
521
+ }
488
522
 
489
- std::string line = info[0].As<Napi::String>().ToString();
523
+ std::string line = info[0].As<Napi::String>().ToString();
490
524
 
491
- mVideoPtr->parseSdpLine(line);
525
+ mVideoPtr->parseSdpLine(line);
492
526
  }