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