node-datachannel 0.28.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.
- package/.clang-format +17 -0
- package/.prettierignore +3 -0
- package/API.md +30 -0
- package/BULDING.md +2 -1
- package/CMakeLists.txt +7 -2
- package/dist/cjs/lib/index.cjs +4 -1
- package/dist/cjs/lib/index.cjs.map +1 -1
- package/dist/cjs/polyfill/Events.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCDataChannel.cjs +18 -5
- package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCPeerConnection.cjs +6 -1
- package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -1
- package/dist/esm/lib/index.mjs +4 -2
- package/dist/esm/lib/index.mjs.map +1 -1
- package/dist/esm/polyfill/Events.mjs.map +1 -1
- package/dist/esm/polyfill/RTCDataChannel.mjs +18 -5
- package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -1
- package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -1
- package/dist/esm/polyfill/RTCPeerConnection.mjs +6 -1
- package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
- package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -1
- package/dist/types/lib/index.d.ts +14 -3
- package/dist/types/lib/types.d.ts +24 -1
- package/dist/types/polyfill/RTCPeerConnection.d.ts +1 -2
- package/package.json +4 -2
- package/src/cpp/data-channel-wrapper.cpp +432 -411
- package/src/cpp/data-channel-wrapper.h +0 -2
- package/src/cpp/ice-udp-mux-listener-wrapper.cpp +157 -0
- package/src/cpp/ice-udp-mux-listener-wrapper.h +43 -0
- package/src/cpp/main.cpp +12 -10
- package/src/cpp/media-audio-wrapper.cpp +291 -294
- package/src/cpp/media-audio-wrapper.h +1 -3
- package/src/cpp/media-direction.cpp +32 -32
- package/src/cpp/media-direction.h +1 -1
- package/src/cpp/media-rtcpreceivingsession-wrapper.cpp +24 -28
- package/src/cpp/media-rtcpreceivingsession-wrapper.h +0 -5
- package/src/cpp/media-track-wrapper.cpp +350 -339
- package/src/cpp/media-track-wrapper.h +0 -3
- package/src/cpp/media-video-wrapper.cpp +312 -313
- package/src/cpp/media-video-wrapper.h +1 -3
- package/src/cpp/peer-connection-wrapper.cpp +1097 -984
- package/src/cpp/peer-connection-wrapper.h +1 -2
- package/src/cpp/rtc-wrapper.cpp +142 -138
- package/src/cpp/rtc-wrapper.h +8 -10
- package/src/cpp/thread-safe-callback.cpp +39 -50
- package/src/cpp/thread-safe-callback.h +26 -28
- package/src/cpp/web-socket-server-wrapper.cpp +205 -199
- package/src/cpp/web-socket-server-wrapper.h +0 -4
- package/src/cpp/web-socket-wrapper.cpp +625 -598
- package/src/cpp/web-socket-wrapper.h +0 -3
- package/src/lib/index.ts +14 -1
- package/src/lib/types.ts +26 -0
- package/src/polyfill/Events.ts +4 -1
- package/src/polyfill/RTCDataChannel.ts +24 -5
- package/src/polyfill/RTCDtlsTransport.ts +1 -1
- package/src/polyfill/RTCPeerConnection.ts +9 -3
- package/src/polyfill/RTCSctpTransport.ts +2 -2
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
54
|
-
|
|
52
|
+
Napi::Env env = info.Env();
|
|
53
|
+
int length = info.Length();
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
std::string mid = "video";
|
|
56
|
+
rtc::Description::Direction dir = rtc::Description::Direction::Unknown;
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
// optional
|
|
59
|
+
if (length > 0)
|
|
60
|
+
{
|
|
61
|
+
if (!info[0].IsString())
|
|
61
62
|
{
|
|
62
|
-
|
|
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
|
-
|
|
71
|
-
|
|
69
|
+
// ootional
|
|
70
|
+
if (length > 1)
|
|
71
|
+
{
|
|
72
|
+
if (!info[1].IsString())
|
|
72
73
|
{
|
|
73
|
-
|
|
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
|
-
|
|
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
|
-
|
|
84
|
+
instances.insert(this);
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
VideoWrapper::~VideoWrapper()
|
|
89
88
|
{
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
107
|
-
|
|
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
|
-
|
|
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
|
-
|
|
130
|
-
|
|
125
|
+
Napi::Env env = info.Env();
|
|
126
|
+
int length = info.Length();
|
|
131
127
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
134
|
+
int payloadType = info[0].As<Napi::Number>().ToNumber();
|
|
135
|
+
std::string profile = rtc::DEFAULT_H264_VIDEO_PROFILE;
|
|
140
136
|
|
|
141
|
-
|
|
137
|
+
if (length > 1)
|
|
138
|
+
{
|
|
139
|
+
if (!info[1].IsString())
|
|
142
140
|
{
|
|
143
|
-
|
|
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
|
-
|
|
147
|
+
mVideoPtr->addH264Codec(payloadType, profile);
|
|
152
148
|
}
|
|
153
149
|
|
|
154
150
|
void VideoWrapper::addVP8Codec(const Napi::CallbackInfo &info)
|
|
155
151
|
{
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
Napi::Env env = info.Env();
|
|
153
|
+
int length = info.Length();
|
|
158
154
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
161
|
+
int payloadType = info[0].As<Napi::Number>().ToNumber();
|
|
166
162
|
|
|
167
|
-
|
|
163
|
+
mVideoPtr->addVP8Codec(payloadType);
|
|
168
164
|
}
|
|
169
165
|
|
|
170
166
|
void VideoWrapper::addVP9Codec(const Napi::CallbackInfo &info)
|
|
171
167
|
{
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
Napi::Env env = info.Env();
|
|
169
|
+
int length = info.Length();
|
|
174
170
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
177
|
+
int payloadType = info[0].As<Napi::Number>().ToNumber();
|
|
182
178
|
|
|
183
|
-
|
|
179
|
+
mVideoPtr->addVP9Codec(payloadType);
|
|
184
180
|
}
|
|
185
181
|
|
|
186
182
|
Napi::Value VideoWrapper::direction(const Napi::CallbackInfo &info)
|
|
187
183
|
{
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
195
|
-
|
|
190
|
+
Napi::Env env = info.Env();
|
|
191
|
+
int length = info.Length();
|
|
196
192
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
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
|
-
|
|
213
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
235
|
-
|
|
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
|
-
|
|
241
|
-
|
|
236
|
+
Napi::Env env = info.Env();
|
|
237
|
+
int length = info.Length();
|
|
242
238
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
245
|
+
std::string fmt = info[0].As<Napi::String>().ToString();
|
|
250
246
|
|
|
251
|
-
|
|
247
|
+
mVideoPtr->removeFormat(fmt);
|
|
252
248
|
}
|
|
253
249
|
|
|
254
250
|
void VideoWrapper::addSSRC(const Napi::CallbackInfo &info)
|
|
255
251
|
{
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
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
|
-
|
|
277
|
+
if (length > 2)
|
|
278
|
+
{
|
|
279
|
+
if (!info[2].IsString())
|
|
281
280
|
{
|
|
282
|
-
|
|
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
|
-
|
|
287
|
+
if (length > 3)
|
|
288
|
+
{
|
|
289
|
+
if (!info[3].IsString())
|
|
291
290
|
{
|
|
292
|
-
|
|
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
|
-
|
|
297
|
+
mVideoPtr->addSSRC(ssrc, name, msid, trackID);
|
|
301
298
|
}
|
|
302
299
|
|
|
303
300
|
void VideoWrapper::removeSSRC(const Napi::CallbackInfo &info)
|
|
304
301
|
{
|
|
305
|
-
|
|
306
|
-
|
|
302
|
+
Napi::Env env = info.Env();
|
|
303
|
+
int length = info.Length();
|
|
307
304
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
311
|
+
uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
|
|
315
312
|
|
|
316
|
-
|
|
313
|
+
mVideoPtr->removeSSRC(ssrc);
|
|
317
314
|
}
|
|
318
315
|
|
|
319
316
|
void VideoWrapper::replaceSSRC(const Napi::CallbackInfo &info)
|
|
320
317
|
{
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
-
|
|
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
|
-
|
|
345
|
+
if (length > 3)
|
|
346
|
+
{
|
|
347
|
+
if (!info[3].IsString())
|
|
347
348
|
{
|
|
348
|
-
|
|
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
|
-
|
|
355
|
+
if (length > 4)
|
|
356
|
+
{
|
|
357
|
+
if (!info[4].IsString())
|
|
357
358
|
{
|
|
358
|
-
|
|
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
|
-
|
|
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
|
-
|
|
372
|
-
|
|
370
|
+
Napi::Env env = info.Env();
|
|
371
|
+
int length = info.Length();
|
|
373
372
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
|
|
379
|
+
uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
|
|
381
380
|
|
|
382
|
-
|
|
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
|
-
|
|
386
|
+
Napi::Env env = info.Env();
|
|
388
387
|
|
|
389
|
-
|
|
388
|
+
auto list = mVideoPtr->getSSRCs();
|
|
390
389
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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
|
-
|
|
394
|
+
return napiArr;
|
|
396
395
|
}
|
|
397
396
|
|
|
398
397
|
Napi::Value VideoWrapper::getCNameForSsrc(const Napi::CallbackInfo &info)
|
|
399
398
|
{
|
|
400
|
-
|
|
401
|
-
|
|
399
|
+
Napi::Env env = info.Env();
|
|
400
|
+
int length = info.Length();
|
|
402
401
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
408
|
+
uint32_t ssrc = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
|
|
410
409
|
|
|
411
|
-
|
|
410
|
+
std::optional<std::string> name = mVideoPtr->getCNameForSsrc(ssrc);
|
|
412
411
|
|
|
413
|
-
|
|
414
|
-
|
|
412
|
+
if (!name.has_value())
|
|
413
|
+
return env.Null();
|
|
415
414
|
|
|
416
|
-
|
|
415
|
+
return Napi::String::New(env, name.value());
|
|
417
416
|
}
|
|
418
417
|
|
|
419
418
|
void VideoWrapper::setBitrate(const Napi::CallbackInfo &info)
|
|
420
419
|
{
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
Napi::Env env = info.Env();
|
|
421
|
+
int length = info.Length();
|
|
423
422
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
431
|
-
|
|
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
|
-
|
|
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
|
-
|
|
442
|
-
|
|
440
|
+
Napi::Env env = info.Env();
|
|
441
|
+
int length = info.Length();
|
|
443
442
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|
-
|
|
449
|
+
int payloadType = static_cast<int32_t>(info[0].As<Napi::Number>().ToNumber());
|
|
451
450
|
|
|
452
|
-
|
|
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
|
-
|
|
458
|
-
|
|
456
|
+
Napi::Env env = info.Env();
|
|
457
|
+
int length = info.Length();
|
|
459
458
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
469
|
+
mVideoPtr->addRtxCodec(payloadType, originalPayloadType, clockRate);
|
|
471
470
|
}
|
|
472
471
|
|
|
473
472
|
void VideoWrapper::addRTPMap(const Napi::CallbackInfo &info)
|
|
474
473
|
{
|
|
475
|
-
|
|
474
|
+
// mVideoPtr->addRTPMap()
|
|
476
475
|
}
|
|
477
476
|
|
|
478
477
|
void VideoWrapper::parseSdpLine(const Napi::CallbackInfo &info)
|
|
479
478
|
{
|
|
480
|
-
|
|
481
|
-
|
|
479
|
+
Napi::Env env = info.Env();
|
|
480
|
+
int length = info.Length();
|
|
482
481
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
-
|
|
488
|
+
std::string line = info[0].As<Napi::String>().ToString();
|
|
490
489
|
|
|
491
|
-
|
|
490
|
+
mVideoPtr->parseSdpLine(line);
|
|
492
491
|
}
|