node-datachannel 0.3.1 → 0.3.2
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/.github/workflows/lint.yml +22 -0
- package/CMakeLists.txt +2 -2
- package/examples/client-server/client-benchmark.js +43 -32
- package/examples/client-server/client-periodic.js +30 -14
- package/examples/client-server/client.js +6 -5
- package/examples/client-server/package-lock.json +183 -44
- package/examples/client-server/signaling-server.js +3 -5
- package/examples/media/media.js +9 -9
- package/lib/index.d.ts +100 -100
- package/node_modules/lru-cache/package.json +2 -4
- package/node_modules/minimist/package.json +0 -1
- package/node_modules/node-abi/node_modules/semver/README.md +3 -1
- package/node_modules/node-abi/node_modules/semver/bin/semver.js +19 -9
- package/node_modules/node-abi/node_modules/semver/classes/comparator.js +3 -2
- package/node_modules/node-abi/node_modules/semver/classes/index.js +1 -1
- package/node_modules/node-abi/node_modules/semver/classes/range.js +31 -22
- package/node_modules/node-abi/node_modules/semver/classes/semver.js +1 -1
- package/node_modules/node-abi/node_modules/semver/functions/cmp.js +8 -4
- package/node_modules/node-abi/node_modules/semver/functions/coerce.js +3 -2
- package/node_modules/node-abi/node_modules/semver/functions/inc.js +4 -1
- package/node_modules/node-abi/node_modules/semver/functions/parse.js +1 -1
- package/node_modules/node-abi/node_modules/semver/internal/constants.js +2 -2
- package/node_modules/node-abi/node_modules/semver/internal/identifiers.js +1 -1
- package/node_modules/node-abi/node_modules/semver/internal/parse-options.js +3 -3
- package/node_modules/node-abi/node_modules/semver/internal/re.js +3 -3
- package/node_modules/node-abi/node_modules/semver/package.json +51 -18
- package/node_modules/node-abi/node_modules/semver/ranges/min-version.js +2 -1
- package/node_modules/node-abi/node_modules/semver/ranges/outside.js +1 -1
- package/node_modules/node-abi/node_modules/semver/ranges/simplify.js +15 -12
- package/node_modules/node-abi/node_modules/semver/ranges/subset.js +53 -31
- package/node_modules/npmlog/node_modules/are-we-there-yet/package.json +10 -10
- package/node_modules/npmlog/package.json +1 -1
- package/node_modules/tar-stream/node_modules/bl/.travis.yml +4 -3
- package/node_modules/tar-stream/node_modules/bl/BufferList.js +1 -1
- package/node_modules/tar-stream/node_modules/bl/package.json +10 -10
- package/node_modules/tar-stream/node_modules/bl/test/test.js +20 -2
- package/node_modules/wide-align/LICENSE +0 -0
- package/node_modules/wide-align/README.md +0 -0
- package/node_modules/wide-align/align.js +0 -0
- package/node_modules/wide-align/package.json +14 -14
- package/package.json +2 -2
- package/src/data-channel-wrapper.cpp +69 -53
- package/src/data-channel-wrapper.h +0 -1
- package/src/media-track-wrapper.cpp +91 -52
- package/src/media-track-wrapper.h +0 -1
- package/src/peer-connection-wrapper.cpp +106 -70
- package/src/peer-connection-wrapper.h +0 -2
- package/test/connectivity.js +18 -17
- package/test/test.js +22 -30
- package/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -111
|
@@ -46,26 +46,8 @@ Napi::Object TrackWrapper::Init(Napi::Env env, Napi::Object exports)
|
|
|
46
46
|
|
|
47
47
|
TrackWrapper::TrackWrapper(const Napi::CallbackInfo &info) : Napi::ObjectWrap<TrackWrapper>(info)
|
|
48
48
|
{
|
|
49
|
-
mTrackPtr = *(info[0].As<Napi::External<std::shared_ptr<rtc::Track>>>().Data());
|
|
49
|
+
mTrackPtr = *(info[0].As<Napi::External<std::shared_ptr<rtc::Track>>>().Data());
|
|
50
50
|
|
|
51
|
-
mTrackPtr->onClosed([&]()
|
|
52
|
-
{
|
|
53
|
-
if (mOnClosedCallback)
|
|
54
|
-
mOnClosedCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
|
|
55
|
-
// Check the peer connection is not closed
|
|
56
|
-
if(instances.find(this) == instances.end())
|
|
57
|
-
throw ThreadSafeCallback::CancelException();
|
|
58
|
-
|
|
59
|
-
cleanCbsAndEraseInstance();
|
|
60
|
-
|
|
61
|
-
// This will run in main thread and needs to construct the
|
|
62
|
-
// arguments for the call
|
|
63
|
-
args = {};
|
|
64
|
-
});
|
|
65
|
-
else {
|
|
66
|
-
cleanCbsAndEraseInstance();
|
|
67
|
-
} });
|
|
68
|
-
|
|
69
51
|
instances.insert(this);
|
|
70
52
|
}
|
|
71
53
|
|
|
@@ -81,24 +63,21 @@ void TrackWrapper::doClose()
|
|
|
81
63
|
try
|
|
82
64
|
{
|
|
83
65
|
mTrackPtr->close();
|
|
66
|
+
mTrackPtr.reset();
|
|
84
67
|
}
|
|
85
68
|
catch (std::exception &ex)
|
|
86
69
|
{
|
|
87
|
-
std::
|
|
70
|
+
std::cerr << std::string("libdatachannel error while closing track: ") + ex.what() << std::endl;
|
|
88
71
|
return;
|
|
89
72
|
}
|
|
90
73
|
}
|
|
91
|
-
}
|
|
92
74
|
|
|
93
|
-
void TrackWrapper::cleanCbsAndEraseInstance()
|
|
94
|
-
{
|
|
95
75
|
mOnOpenCallback.reset();
|
|
96
76
|
mOnClosedCallback.reset();
|
|
97
77
|
mOnErrorCallback.reset();
|
|
98
78
|
mOnMessageCallback.reset();
|
|
99
79
|
|
|
100
80
|
instances.erase(this);
|
|
101
|
-
mTrackPtr.reset();
|
|
102
81
|
}
|
|
103
82
|
|
|
104
83
|
void TrackWrapper::close(const Napi::CallbackInfo &info)
|
|
@@ -108,18 +87,36 @@ void TrackWrapper::close(const Napi::CallbackInfo &info)
|
|
|
108
87
|
|
|
109
88
|
Napi::Value TrackWrapper::direction(const Napi::CallbackInfo &info)
|
|
110
89
|
{
|
|
90
|
+
if (!mTrackPtr)
|
|
91
|
+
{
|
|
92
|
+
Napi::Error::New(info.Env(), "direction() called on destroyed track").ThrowAsJavaScriptException();
|
|
93
|
+
return info.Env().Null();
|
|
94
|
+
}
|
|
95
|
+
|
|
111
96
|
Napi::Env env = info.Env();
|
|
112
97
|
return Napi::String::New(env, directionToStr(mTrackPtr->direction()));
|
|
113
98
|
}
|
|
114
99
|
|
|
115
100
|
Napi::Value TrackWrapper::mid(const Napi::CallbackInfo &info)
|
|
116
101
|
{
|
|
102
|
+
if (!mTrackPtr)
|
|
103
|
+
{
|
|
104
|
+
Napi::Error::New(info.Env(), "mid() called on destroyed track").ThrowAsJavaScriptException();
|
|
105
|
+
return info.Env().Null();
|
|
106
|
+
}
|
|
107
|
+
|
|
117
108
|
Napi::Env env = info.Env();
|
|
118
109
|
return Napi::String::New(env, mTrackPtr->mid());
|
|
119
110
|
}
|
|
120
111
|
|
|
121
112
|
Napi::Value TrackWrapper::type(const Napi::CallbackInfo &info)
|
|
122
113
|
{
|
|
114
|
+
if (!mTrackPtr)
|
|
115
|
+
{
|
|
116
|
+
Napi::Error::New(info.Env(), "type() called on destroyed track").ThrowAsJavaScriptException();
|
|
117
|
+
return info.Env().Null();
|
|
118
|
+
}
|
|
119
|
+
|
|
123
120
|
Napi::Env env = info.Env();
|
|
124
121
|
return Napi::String::New(env, mTrackPtr->description().type());
|
|
125
122
|
}
|
|
@@ -128,7 +125,7 @@ Napi::Value TrackWrapper::sendMessage(const Napi::CallbackInfo &info)
|
|
|
128
125
|
{
|
|
129
126
|
if (!mTrackPtr)
|
|
130
127
|
{
|
|
131
|
-
Napi::Error::New(info.Env(), "
|
|
128
|
+
Napi::Error::New(info.Env(), "sendMessage() called on destroyed track").ThrowAsJavaScriptException();
|
|
132
129
|
return info.Env().Null();
|
|
133
130
|
}
|
|
134
131
|
|
|
@@ -148,7 +145,7 @@ Napi::Value TrackWrapper::sendMessage(const Napi::CallbackInfo &info)
|
|
|
148
145
|
}
|
|
149
146
|
catch (std::exception &ex)
|
|
150
147
|
{
|
|
151
|
-
Napi::Error::New(env, std::string("libdatachannel error while sending track
|
|
148
|
+
Napi::Error::New(env, std::string("libdatachannel error while sending track message: ") + ex.what()).ThrowAsJavaScriptException();
|
|
152
149
|
return Napi::Boolean::New(info.Env(), false);
|
|
153
150
|
}
|
|
154
151
|
}
|
|
@@ -157,7 +154,7 @@ Napi::Value TrackWrapper::sendMessageBinary(const Napi::CallbackInfo &info)
|
|
|
157
154
|
{
|
|
158
155
|
if (!mTrackPtr)
|
|
159
156
|
{
|
|
160
|
-
Napi::Error::New(info.Env(), "
|
|
157
|
+
Napi::Error::New(info.Env(), "sendMessageBinary() called on destroyed track").ThrowAsJavaScriptException();
|
|
161
158
|
return info.Env().Null();
|
|
162
159
|
}
|
|
163
160
|
|
|
@@ -177,7 +174,7 @@ Napi::Value TrackWrapper::sendMessageBinary(const Napi::CallbackInfo &info)
|
|
|
177
174
|
}
|
|
178
175
|
catch (std::exception &ex)
|
|
179
176
|
{
|
|
180
|
-
Napi::Error::New(env, std::string("libdatachannel error while sending track
|
|
177
|
+
Napi::Error::New(env, std::string("libdatachannel error while sending track message: ") + ex.what()).ThrowAsJavaScriptException();
|
|
181
178
|
return Napi::Boolean::New(info.Env(), false);
|
|
182
179
|
}
|
|
183
180
|
}
|
|
@@ -185,18 +182,31 @@ Napi::Value TrackWrapper::sendMessageBinary(const Napi::CallbackInfo &info)
|
|
|
185
182
|
Napi::Value TrackWrapper::isOpen(const Napi::CallbackInfo &info)
|
|
186
183
|
{
|
|
187
184
|
Napi::Env env = info.Env();
|
|
185
|
+
|
|
186
|
+
if (!mTrackPtr)
|
|
187
|
+
{
|
|
188
|
+
return Napi::Boolean::New(env, false);
|
|
189
|
+
}
|
|
190
|
+
|
|
188
191
|
return Napi::Boolean::New(env, mTrackPtr->isOpen());
|
|
189
192
|
}
|
|
190
193
|
|
|
191
194
|
Napi::Value TrackWrapper::isClosed(const Napi::CallbackInfo &info)
|
|
192
195
|
{
|
|
193
196
|
Napi::Env env = info.Env();
|
|
197
|
+
|
|
198
|
+
if (!mTrackPtr)
|
|
199
|
+
{
|
|
200
|
+
return Napi::Boolean::New(env, true);
|
|
201
|
+
}
|
|
202
|
+
|
|
194
203
|
return Napi::Boolean::New(env, mTrackPtr->isClosed());
|
|
195
204
|
}
|
|
196
205
|
|
|
197
206
|
Napi::Value TrackWrapper::maxMessageSize(const Napi::CallbackInfo &info)
|
|
198
207
|
{
|
|
199
208
|
Napi::Env env = info.Env();
|
|
209
|
+
|
|
200
210
|
if (!mTrackPtr)
|
|
201
211
|
{
|
|
202
212
|
return Napi::Number::New(info.Env(), 0);
|
|
@@ -208,13 +218,19 @@ Napi::Value TrackWrapper::maxMessageSize(const Napi::CallbackInfo &info)
|
|
|
208
218
|
}
|
|
209
219
|
catch (std::exception &ex)
|
|
210
220
|
{
|
|
211
|
-
Napi::Error::New(env, std::string("libdatachannel error
|
|
221
|
+
Napi::Error::New(env, std::string("libdatachannel error: ") + ex.what()).ThrowAsJavaScriptException();
|
|
212
222
|
return Napi::Number::New(info.Env(), 0);
|
|
213
223
|
}
|
|
214
224
|
}
|
|
215
225
|
|
|
216
226
|
Napi::Value TrackWrapper::requestKeyframe(const Napi::CallbackInfo &info)
|
|
217
227
|
{
|
|
228
|
+
if (!mTrackPtr)
|
|
229
|
+
{
|
|
230
|
+
Napi::Error::New(info.Env(), "requestKeyframe() called on destroyed track").ThrowAsJavaScriptException();
|
|
231
|
+
return info.Env().Null();
|
|
232
|
+
}
|
|
233
|
+
|
|
218
234
|
Napi::Env env = info.Env();
|
|
219
235
|
return Napi::Boolean::New(env, mTrackPtr->requestKeyframe());
|
|
220
236
|
}
|
|
@@ -223,7 +239,7 @@ void TrackWrapper::setMediaHandler(const Napi::CallbackInfo &info)
|
|
|
223
239
|
{
|
|
224
240
|
if (!mTrackPtr)
|
|
225
241
|
{
|
|
226
|
-
Napi::Error::New(info.Env(), "
|
|
242
|
+
Napi::Error::New(info.Env(), "setMediaHandler() called on destroyed track").ThrowAsJavaScriptException();
|
|
227
243
|
return;
|
|
228
244
|
}
|
|
229
245
|
|
|
@@ -232,7 +248,7 @@ void TrackWrapper::setMediaHandler(const Napi::CallbackInfo &info)
|
|
|
232
248
|
|
|
233
249
|
if (length < 1 || !info[0].IsObject())
|
|
234
250
|
{
|
|
235
|
-
Napi::TypeError::New(env, "
|
|
251
|
+
Napi::TypeError::New(env, "MediaHandler class instance expected").ThrowAsJavaScriptException();
|
|
236
252
|
return;
|
|
237
253
|
}
|
|
238
254
|
|
|
@@ -242,6 +258,12 @@ void TrackWrapper::setMediaHandler(const Napi::CallbackInfo &info)
|
|
|
242
258
|
|
|
243
259
|
void TrackWrapper::onOpen(const Napi::CallbackInfo &info)
|
|
244
260
|
{
|
|
261
|
+
if (!mTrackPtr)
|
|
262
|
+
{
|
|
263
|
+
Napi::Error::New(info.Env(), "onOpen() called on destroyed track").ThrowAsJavaScriptException();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
245
267
|
Napi::Env env = info.Env();
|
|
246
268
|
int length = info.Length();
|
|
247
269
|
|
|
@@ -254,11 +276,10 @@ void TrackWrapper::onOpen(const Napi::CallbackInfo &info)
|
|
|
254
276
|
// Callback
|
|
255
277
|
mOnOpenCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
256
278
|
|
|
257
|
-
mTrackPtr->onOpen([&]()
|
|
258
|
-
{
|
|
279
|
+
mTrackPtr->onOpen([&]() {
|
|
259
280
|
if (mOnOpenCallback)
|
|
260
281
|
mOnOpenCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
|
|
261
|
-
// Check the
|
|
282
|
+
// Check the track is not closed
|
|
262
283
|
if(instances.find(this) == instances.end())
|
|
263
284
|
throw ThreadSafeCallback::CancelException();
|
|
264
285
|
|
|
@@ -270,6 +291,12 @@ void TrackWrapper::onOpen(const Napi::CallbackInfo &info)
|
|
|
270
291
|
|
|
271
292
|
void TrackWrapper::onClosed(const Napi::CallbackInfo &info)
|
|
272
293
|
{
|
|
294
|
+
if (!mTrackPtr)
|
|
295
|
+
{
|
|
296
|
+
Napi::Error::New(info.Env(), "onClosed() called on destroyed track").ThrowAsJavaScriptException();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
273
300
|
Napi::Env env = info.Env();
|
|
274
301
|
int length = info.Length();
|
|
275
302
|
|
|
@@ -282,11 +309,25 @@ void TrackWrapper::onClosed(const Napi::CallbackInfo &info)
|
|
|
282
309
|
// Callback
|
|
283
310
|
mOnClosedCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
284
311
|
|
|
285
|
-
|
|
312
|
+
mTrackPtr->onClosed([&]() {
|
|
313
|
+
if (mOnClosedCallback)
|
|
314
|
+
mOnClosedCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
|
|
315
|
+
// Do not check if the data channel has been closed here
|
|
316
|
+
|
|
317
|
+
// This will run in main thread and needs to construct the
|
|
318
|
+
// arguments for the call
|
|
319
|
+
args = {};
|
|
320
|
+
}); });
|
|
286
321
|
}
|
|
287
322
|
|
|
288
323
|
void TrackWrapper::onError(const Napi::CallbackInfo &info)
|
|
289
324
|
{
|
|
325
|
+
if (!mTrackPtr)
|
|
326
|
+
{
|
|
327
|
+
Napi::Error::New(info.Env(), "onError() called on destroyed track").ThrowAsJavaScriptException();
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
|
|
290
331
|
Napi::Env env = info.Env();
|
|
291
332
|
int length = info.Length();
|
|
292
333
|
|
|
@@ -299,11 +340,10 @@ void TrackWrapper::onError(const Napi::CallbackInfo &info)
|
|
|
299
340
|
// Callback
|
|
300
341
|
mOnErrorCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
301
342
|
|
|
302
|
-
mTrackPtr->onError([&](const std::string &error)
|
|
303
|
-
{
|
|
343
|
+
mTrackPtr->onError([&](const std::string &error) {
|
|
304
344
|
if (mOnErrorCallback)
|
|
305
345
|
mOnErrorCallback->call([this, error](Napi::Env env, std::vector<napi_value> &args) {
|
|
306
|
-
// Check the
|
|
346
|
+
// Check the track is not closed
|
|
307
347
|
if(instances.find(this) == instances.end())
|
|
308
348
|
throw ThreadSafeCallback::CancelException();
|
|
309
349
|
|
|
@@ -315,6 +355,12 @@ void TrackWrapper::onError(const Napi::CallbackInfo &info)
|
|
|
315
355
|
|
|
316
356
|
void TrackWrapper::onMessage(const Napi::CallbackInfo &info)
|
|
317
357
|
{
|
|
358
|
+
if (!mTrackPtr)
|
|
359
|
+
{
|
|
360
|
+
Napi::Error::New(info.Env(), "onMessage() called on destroyed track").ThrowAsJavaScriptException();
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
|
|
318
364
|
Napi::Env env = info.Env();
|
|
319
365
|
int length = info.Length();
|
|
320
366
|
|
|
@@ -327,26 +373,19 @@ void TrackWrapper::onMessage(const Napi::CallbackInfo &info)
|
|
|
327
373
|
// Callback
|
|
328
374
|
mOnMessageCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
329
375
|
|
|
330
|
-
mTrackPtr->onMessage([&](
|
|
331
|
-
{
|
|
376
|
+
mTrackPtr->onMessage([&](std::variant<rtc::binary, std::string> message) {
|
|
332
377
|
if (mOnMessageCallback)
|
|
333
|
-
mOnMessageCallback->call([this, message](Napi::Env env, std::vector<napi_value> &args) {
|
|
334
|
-
// Check the
|
|
378
|
+
mOnMessageCallback->call([this, message = std::move(message)](Napi::Env env, std::vector<napi_value> &args) {
|
|
379
|
+
// Check the track is not closed
|
|
335
380
|
if(instances.find(this) == instances.end())
|
|
336
381
|
throw ThreadSafeCallback::CancelException();
|
|
337
382
|
|
|
338
383
|
// This will run in main thread and needs to construct the
|
|
339
384
|
// arguments for the call
|
|
340
|
-
|
|
341
|
-
if (std::holds_alternative<std::string>(message))
|
|
342
|
-
{
|
|
343
|
-
// Track will always send message as binary
|
|
344
|
-
// So this code is not needed actually
|
|
345
|
-
args = {Napi::String::New(env, std::get<std::string>(message))};
|
|
346
|
-
}
|
|
347
|
-
else
|
|
385
|
+
if (std::holds_alternative<rtc::binary>(message)) // Track will always receive messages as binary
|
|
348
386
|
{
|
|
349
|
-
|
|
387
|
+
auto bin = std::get<rtc::binary>(std::move(message));
|
|
388
|
+
args = {Napi::Buffer<std::byte>::Copy(env, bin.data(), bin.size())};
|
|
350
389
|
}
|
|
351
390
|
}); });
|
|
352
|
-
}
|
|
391
|
+
}
|