node-datachannel 0.4.0 → 0.4.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/README.md CHANGED
@@ -31,6 +31,7 @@ npm install node-datachannel
31
31
  | Node V16 | + | + | + | + | + | + |
32
32
  | Node V17 | + | + | + | + | + | + |
33
33
  | Node V18 | + | + | + | + | + | + |
34
+ | Node V19 | + | + | + | + | + | + |
34
35
 
35
36
  1) Please note that; For Linux-arm64 platform we need OpenSSL to be installed locally.
36
37
 
package/lib/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export interface SctpSettings {
17
17
 
18
18
  // Functions
19
19
  export function preload(): void;
20
- export function initLogger(level: LogLevel): void;
20
+ export function initLogger(level: LogLevel, callback?: (level: LogLevel, message: string) => void): void;
21
21
  export function cleanup(): void;
22
22
  export function setSctpSettings(settings: SctpSettings): void;
23
23
 
@@ -46,9 +46,11 @@ export interface IceServer {
46
46
  }
47
47
 
48
48
  export type TransportPolicy = 'all' | 'relay';
49
+
49
50
  export interface RtcConfig {
50
51
  iceServers: (string | IceServer)[];
51
52
  proxyServer?: ProxyServer;
53
+ bindAddress?: string;
52
54
  enableIceTcp?: boolean;
53
55
  enableIceUdpMux?: boolean;
54
56
  disableAutoNegotiation?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-datachannel",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "libdatachannel node bindings",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "_from": "node-datachannel@latest",
12
12
  "scripts": {
13
- "install": "prebuild-install || (npm install --ignore-scripts && npm run _prebuild)",
13
+ "install": "prebuild-install || (npm install --ignore-scripts --production=false && npm run _prebuild)",
14
14
  "install-nice": "npm run clean && cmake-js build --CDUSE_NICE=1",
15
15
  "build": "cmake-js build",
16
16
  "build:debug": "cmake-js build -D",
@@ -41,7 +41,7 @@
41
41
  "url": "https://github.com/paullouisageneau"
42
42
  }
43
43
  ],
44
- "license": "LGPL",
44
+ "license": "MPL 2.0",
45
45
  "gypfile": true,
46
46
  "bugs": {
47
47
  "url": "https://github.com/murat-dogan/node-datachannel/issues"
@@ -103,7 +103,7 @@ Napi::Value DataChannelWrapper::getId(const Napi::CallbackInfo &info)
103
103
  return info.Env().Null();
104
104
  }
105
105
 
106
- return Napi::Number::New(info.Env(), mDataChannelPtr->id());
106
+ return Napi::Number::New(info.Env(), mDataChannelPtr->id().value_or(-1));
107
107
  }
108
108
 
109
109
  Napi::Value DataChannelWrapper::getProtocol(const Napi::CallbackInfo &info)
@@ -171,6 +171,10 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
171
171
  rtcConfig.proxyServer = rtc::ProxyServer(type, ip, port, username, password);
172
172
  }
173
173
 
174
+ // bind address, libjuice only
175
+ if(config.Get("bindAddress").IsString())
176
+ rtcConfig.bindAddress = config.Get("bindAddress").As<Napi::String>().ToString();
177
+
174
178
  // Port Ranges
175
179
  if (config.Get("portRangeBegin").IsNumber())
176
180
  rtcConfig.portRangeBegin = config.Get("portRangeBegin").As<Napi::Number>().Uint32Value();
@@ -265,7 +269,7 @@ void PeerConnectionWrapper::doDestroy()
265
269
  }
266
270
 
267
271
  void PeerConnectionWrapper::doResetCallbacks()
268
- {
272
+ {
269
273
  mOnLocalDescriptionCallback.reset();
270
274
  mOnLocalCandidateCallback.reset();
271
275
  mOnStateChangeCallback.reset();
@@ -513,10 +517,10 @@ Napi::Value PeerConnectionWrapper::createDataChannel(const Napi::CallbackInfo &i
513
517
  switch (reliability.Get("type").As<Napi::Number>().Uint32Value())
514
518
  {
515
519
  case 1:
516
- init.reliability.rexmit = reliability.Get("rexmit").As<Napi::Number>();
520
+ init.reliability.rexmit = static_cast<int>(reliability.Get("rexmit").As<Napi::Number>().ToNumber());
517
521
  break;
518
522
  case 2:
519
- init.reliability.rexmit = std::chrono::milliseconds(reliability.Get("rexmit").As<Napi::Number>());
523
+ init.reliability.rexmit = std::chrono::milliseconds(reliability.Get("rexmit").As<Napi::Number>().Uint32Value());
520
524
  break;
521
525
  }
522
526
  }
@@ -661,7 +665,7 @@ void PeerConnectionWrapper::onStateChange(const Napi::CallbackInfo &info)
661
665
 
662
666
  mRtcPeerConnPtr->onStateChange([&](rtc::PeerConnection::State state) {
663
667
  if (mOnStateChangeCallback)
664
- mOnStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
668
+ mOnStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
665
669
  if(instances.find(this) == instances.end())
666
670
  throw ThreadSafeCallback::CancelException();
667
671
 
@@ -61,7 +61,42 @@ void RtcWrapper::initLogger(const Napi::CallbackInfo &info)
61
61
 
62
62
  try
63
63
  {
64
- rtc::InitLogger(logLevel);
64
+ if (length < 2)
65
+ {
66
+ rtc::InitLogger(logLevel);
67
+ }
68
+ else
69
+ {
70
+ if (!info[1].IsFunction())
71
+ {
72
+ Napi::TypeError::New(env, "Function expected").ThrowAsJavaScriptException();
73
+ return;
74
+ }
75
+ logCallback = std::make_unique<ThreadSafeCallback>(info[1].As<Napi::Function>());
76
+ rtc::InitLogger(logLevel, [&](rtc::LogLevel level, std::string message) {
77
+ if (logCallback)
78
+ logCallback->call([level, message = std::move(message)](Napi::Env env, std::vector<napi_value> &args) {
79
+ // This will run in main thread and needs to construct the
80
+ // arguments for the call
81
+
82
+ std::string logLevel;
83
+ if (level == rtc::LogLevel::Verbose)
84
+ logLevel = "Verbose";
85
+ if (level == rtc::LogLevel::Debug)
86
+ logLevel = "Debug";
87
+ if (level == rtc::LogLevel::Info)
88
+ logLevel = "Info";
89
+ if (level == rtc::LogLevel::Warning)
90
+ logLevel = "Warning";
91
+ if (level == rtc::LogLevel::Error)
92
+ logLevel = "Error";
93
+ if (level == rtc::LogLevel::Fatal)
94
+ logLevel = "Fatal";
95
+ args = {Napi::String::New(env, logLevel), Napi::String::New(env, message)};
96
+ });
97
+ });
98
+ }
99
+
65
100
  }
66
101
  catch (std::exception &ex)
67
102
  {
@@ -85,6 +120,8 @@ void RtcWrapper::cleanup(const Napi::CallbackInfo &info)
85
120
 
86
121
  // Clear Callbacks
87
122
  PeerConnectionWrapper::ResetCallbacksAll();
123
+
124
+ if (logCallback) logCallback.reset();
88
125
  }
89
126
  catch (std::exception &ex)
90
127
  {
package/src/rtc-wrapper.h CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  #include "rtc/rtc.hpp"
10
10
 
11
+ #include "thread-safe-callback.h"
12
+
11
13
  class RtcWrapper
12
14
  {
13
15
  public:
@@ -16,6 +18,8 @@ public:
16
18
  static void initLogger(const Napi::CallbackInfo &info);
17
19
  static void cleanup(const Napi::CallbackInfo &info);
18
20
  static void setSctpSettings(const Napi::CallbackInfo &info);
21
+ private:
22
+ static inline std::unique_ptr<ThreadSafeCallback> logCallback = nullptr;
19
23
  };
20
24
 
21
25
  #endif // RTC_WRAPPER_H
@@ -11,6 +11,7 @@ let dc2 = null;
11
11
  // export interface RtcConfig {
12
12
  // iceServers: string[];
13
13
  // proxyServer?: ProxyServer;
14
+ // bindAddress?: string;
14
15
  // enableIceTcp?: boolean;
15
16
  // portRangeBegin?: number;
16
17
  // portRangeEnd?: number;