node-datachannel 0.1.14-dev → 0.2.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.
@@ -1,12 +1,12 @@
1
1
  #include "data-channel-wrapper.h"
2
2
 
3
3
  Napi::FunctionReference DataChannelWrapper::constructor;
4
- std::unordered_set<DataChannelWrapper*> DataChannelWrapper::instances;
4
+ std::unordered_set<DataChannelWrapper *> DataChannelWrapper::instances;
5
5
 
6
6
  void DataChannelWrapper::CloseAll()
7
7
  {
8
8
  auto copy(instances);
9
- for(auto inst : copy)
9
+ for (auto inst : copy)
10
10
  inst->doClose();
11
11
  }
12
12
 
@@ -17,21 +17,21 @@ Napi::Object DataChannelWrapper::Init(Napi::Env env, Napi::Object exports)
17
17
  Napi::Function func = DefineClass(
18
18
  env,
19
19
  "DataChannel",
20
- {InstanceMethod("close", &DataChannelWrapper::close),
21
- InstanceMethod("getLabel", &DataChannelWrapper::getLabel),
22
- InstanceMethod("sendMessage", &DataChannelWrapper::sendMessage),
23
- InstanceMethod("sendMessageBinary", &DataChannelWrapper::sendMessageBinary),
24
- InstanceMethod("isOpen", &DataChannelWrapper::isOpen),
25
- InstanceMethod("availableAmount", &DataChannelWrapper::availableAmount),
26
- InstanceMethod("bufferedAmount", &DataChannelWrapper::bufferedAmount),
27
- InstanceMethod("maxMessageSize", &DataChannelWrapper::maxMessageSize),
28
- InstanceMethod("setBufferedAmountLowThreshold", &DataChannelWrapper::setBufferedAmountLowThreshold),
29
- InstanceMethod("onOpen", &DataChannelWrapper::onOpen),
30
- InstanceMethod("onClosed", &DataChannelWrapper::onClosed),
31
- InstanceMethod("onError", &DataChannelWrapper::onError),
32
- InstanceMethod("onAvailable", &DataChannelWrapper::onAvailable),
33
- InstanceMethod("onBufferedAmountLow", &DataChannelWrapper::onBufferedAmountLow),
34
- InstanceMethod("onMessage", &DataChannelWrapper::onMessage)});
20
+ {
21
+ InstanceMethod("close", &DataChannelWrapper::close),
22
+ InstanceMethod("getLabel", &DataChannelWrapper::getLabel),
23
+ InstanceMethod("sendMessage", &DataChannelWrapper::sendMessage),
24
+ InstanceMethod("sendMessageBinary", &DataChannelWrapper::sendMessageBinary),
25
+ InstanceMethod("isOpen", &DataChannelWrapper::isOpen),
26
+ InstanceMethod("bufferedAmount", &DataChannelWrapper::bufferedAmount),
27
+ InstanceMethod("maxMessageSize", &DataChannelWrapper::maxMessageSize),
28
+ InstanceMethod("setBufferedAmountLowThreshold", &DataChannelWrapper::setBufferedAmountLowThreshold),
29
+ InstanceMethod("onOpen", &DataChannelWrapper::onOpen),
30
+ InstanceMethod("onClosed", &DataChannelWrapper::onClosed),
31
+ InstanceMethod("onError", &DataChannelWrapper::onError),
32
+ InstanceMethod("onBufferedAmountLow", &DataChannelWrapper::onBufferedAmountLow),
33
+ InstanceMethod("onMessage", &DataChannelWrapper::onMessage),
34
+ });
35
35
 
36
36
  constructor = Napi::Persistent(func);
37
37
  constructor.SuppressDestruct();
@@ -63,7 +63,6 @@ void DataChannelWrapper::doClose()
63
63
  mOnOpenCallback.reset();
64
64
  mOnClosedCallback.reset();
65
65
  mOnErrorCallback.reset();
66
- mOnAvailableCallback.reset();
67
66
  mOnBufferedAmountLowCallback.reset();
68
67
  mOnMessageCallback.reset();
69
68
 
@@ -171,25 +170,6 @@ Napi::Value DataChannelWrapper::isOpen(const Napi::CallbackInfo &info)
171
170
  }
172
171
  }
173
172
 
174
- Napi::Value DataChannelWrapper::availableAmount(const Napi::CallbackInfo &info)
175
- {
176
- Napi::Env env = info.Env();
177
- if (!mDataChannelPtr)
178
- {
179
- return Napi::Number::New(info.Env(), 0);
180
- }
181
-
182
- try
183
- {
184
- return Napi::Number::New(info.Env(), mDataChannelPtr->availableAmount());
185
- }
186
- catch (std::exception &ex)
187
- {
188
- Napi::Error::New(env, std::string("libdatachannel error# ") + ex.what()).ThrowAsJavaScriptException();
189
- return Napi::Number::New(info.Env(), 0);
190
- }
191
- }
192
-
193
173
  Napi::Value DataChannelWrapper::bufferedAmount(const Napi::CallbackInfo &info)
194
174
  {
195
175
  Napi::Env env = info.Env();
@@ -270,7 +250,8 @@ void DataChannelWrapper::onOpen(const Napi::CallbackInfo &info)
270
250
  // Callback
271
251
  mOnOpenCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
272
252
 
273
- mDataChannelPtr->onOpen([&]() {
253
+ mDataChannelPtr->onOpen([&]()
254
+ {
274
255
  if (mOnOpenCallback)
275
256
  mOnOpenCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
276
257
  // Check the peer connection is not closed
@@ -280,8 +261,7 @@ void DataChannelWrapper::onOpen(const Napi::CallbackInfo &info)
280
261
  // This will run in main thread and needs to construct the
281
262
  // arguments for the call
282
263
  args = {};
283
- });
284
- });
264
+ }); });
285
265
  }
286
266
 
287
267
  void DataChannelWrapper::onClosed(const Napi::CallbackInfo &info)
@@ -298,7 +278,8 @@ void DataChannelWrapper::onClosed(const Napi::CallbackInfo &info)
298
278
  // Callback
299
279
  mOnClosedCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
300
280
 
301
- mDataChannelPtr->onClosed([&]() {
281
+ mDataChannelPtr->onClosed([&]()
282
+ {
302
283
  if (mOnClosedCallback)
303
284
  mOnClosedCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
304
285
  // Check the peer connection is not closed
@@ -308,8 +289,7 @@ void DataChannelWrapper::onClosed(const Napi::CallbackInfo &info)
308
289
  // This will run in main thread and needs to construct the
309
290
  // arguments for the call
310
291
  args = {};
311
- });
312
- });
292
+ }); });
313
293
  }
314
294
 
315
295
  void DataChannelWrapper::onError(const Napi::CallbackInfo &info)
@@ -326,7 +306,8 @@ void DataChannelWrapper::onError(const Napi::CallbackInfo &info)
326
306
  // Callback
327
307
  mOnErrorCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
328
308
 
329
- mDataChannelPtr->onError([&](const std::string &error) {
309
+ mDataChannelPtr->onError([&](const std::string &error)
310
+ {
330
311
  if (mOnErrorCallback)
331
312
  mOnErrorCallback->call([this, error](Napi::Env env, std::vector<napi_value> &args) {
332
313
  // Check the peer connection is not closed
@@ -336,36 +317,7 @@ void DataChannelWrapper::onError(const Napi::CallbackInfo &info)
336
317
  // This will run in main thread and needs to construct the
337
318
  // arguments for the call
338
319
  args = {Napi::String::New(env, error)};
339
- });
340
- });
341
- }
342
-
343
- void DataChannelWrapper::onAvailable(const Napi::CallbackInfo &info)
344
- {
345
- Napi::Env env = info.Env();
346
- int length = info.Length();
347
-
348
- if (length < 1 || !info[0].IsFunction())
349
- {
350
- Napi::TypeError::New(env, "Function expected").ThrowAsJavaScriptException();
351
- return;
352
- }
353
-
354
- // Callback
355
- mOnAvailableCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
356
-
357
- mDataChannelPtr->onAvailable([&]() {
358
- if (mOnAvailableCallback)
359
- mOnAvailableCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
360
- // Check the peer connection is not closed
361
- if(instances.find(this) == instances.end())
362
- throw ThreadSafeCallback::CancelException();
363
-
364
- // This will run in main thread and needs to construct the
365
- // arguments for the call
366
- args = {};
367
- });
368
- });
320
+ }); });
369
321
  }
370
322
 
371
323
  void DataChannelWrapper::onBufferedAmountLow(const Napi::CallbackInfo &info)
@@ -382,7 +334,8 @@ void DataChannelWrapper::onBufferedAmountLow(const Napi::CallbackInfo &info)
382
334
  // Callback
383
335
  mOnBufferedAmountLowCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
384
336
 
385
- mDataChannelPtr->onBufferedAmountLow([&]() {
337
+ mDataChannelPtr->onBufferedAmountLow([&]()
338
+ {
386
339
  if (mOnBufferedAmountLowCallback)
387
340
  mOnBufferedAmountLowCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
388
341
  // Check the peer connection is not closed
@@ -392,8 +345,7 @@ void DataChannelWrapper::onBufferedAmountLow(const Napi::CallbackInfo &info)
392
345
  // This will run in main thread and needs to construct the
393
346
  // arguments for the call
394
347
  args = {};
395
- });
396
- });
348
+ }); });
397
349
  }
398
350
 
399
351
  void DataChannelWrapper::onMessage(const Napi::CallbackInfo &info)
@@ -410,7 +362,8 @@ void DataChannelWrapper::onMessage(const Napi::CallbackInfo &info)
410
362
  // Callback
411
363
  mOnMessageCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
412
364
 
413
- mDataChannelPtr->onMessage([&](const std::variant<rtc::binary, std::string> &message) {
365
+ mDataChannelPtr->onMessage([&](const std::variant<rtc::binary, std::string> &message)
366
+ {
414
367
  if (mOnMessageCallback)
415
368
  mOnMessageCallback->call([this, message](Napi::Env env, std::vector<napi_value> &args) {
416
369
  // Check the peer connection is not closed
@@ -428,6 +381,5 @@ void DataChannelWrapper::onMessage(const Napi::CallbackInfo &info)
428
381
  {
429
382
  args = {Napi::Buffer<std::byte>::Copy(env, std::get<rtc::binary>(message).data(), std::get<rtc::binary>(message).size())};
430
383
  }
431
- });
432
- });
384
+ }); });
433
385
  }
@@ -26,7 +26,6 @@ public:
26
26
  Napi::Value sendMessage(const Napi::CallbackInfo &info);
27
27
  Napi::Value sendMessageBinary(const Napi::CallbackInfo &info);
28
28
  Napi::Value isOpen(const Napi::CallbackInfo &info);
29
- Napi::Value availableAmount(const Napi::CallbackInfo &info);
30
29
  Napi::Value bufferedAmount(const Napi::CallbackInfo &info);
31
30
  Napi::Value maxMessageSize(const Napi::CallbackInfo &info);
32
31
  void setBufferedAmountLowThreshold(const Napi::CallbackInfo &info);
@@ -35,7 +34,6 @@ public:
35
34
  void onOpen(const Napi::CallbackInfo &info);
36
35
  void onClosed(const Napi::CallbackInfo &info);
37
36
  void onError(const Napi::CallbackInfo &info);
38
- void onAvailable(const Napi::CallbackInfo &info);
39
37
  void onBufferedAmountLow(const Napi::CallbackInfo &info);
40
38
  void onMessage(const Napi::CallbackInfo &info);
41
39
 
@@ -54,7 +52,6 @@ private:
54
52
  std::unique_ptr<ThreadSafeCallback> mOnOpenCallback = nullptr;
55
53
  std::unique_ptr<ThreadSafeCallback> mOnClosedCallback = nullptr;
56
54
  std::unique_ptr<ThreadSafeCallback> mOnErrorCallback = nullptr;
57
- std::unique_ptr<ThreadSafeCallback> mOnAvailableCallback = nullptr;
58
55
  std::unique_ptr<ThreadSafeCallback> mOnBufferedAmountLowCallback = nullptr;
59
56
  std::unique_ptr<ThreadSafeCallback> mOnMessageCallback = nullptr;
60
57
  };
package/src/main.cpp CHANGED
@@ -2,10 +2,18 @@
2
2
  #include "rtc-wrapper.h"
3
3
  #include "peer-connection-wrapper.h"
4
4
  #include "data-channel-wrapper.h"
5
+ #include "media-rtcpreceivingsession-wrapper.h"
6
+ #include "media-track-wrapper.h"
7
+ #include "media-video-wrapper.h"
8
+ #include "media-audio-wrapper.h"
5
9
 
6
10
  Napi::Object InitAll(Napi::Env env, Napi::Object exports)
7
11
  {
8
12
  RtcWrapper::Init(env, exports);
13
+ RtcpReceivingSessionWrapper::Init(env,exports);
14
+ TrackWrapper::Init(env,exports);
15
+ VideoWrapper::Init(env,exports);
16
+ AudioWrapper::Init(env,exports);
9
17
  DataChannelWrapper::Init(env, exports);
10
18
  PeerConnectionWrapper::Init(env, exports);
11
19
  return exports;