node-datachannel 0.3.5 → 0.4.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.
@@ -2,9 +2,6 @@ name: Build - Linux-Arm64
2
2
 
3
3
  on:
4
4
  workflow_dispatch:
5
- push:
6
- tags:
7
- - v*
8
5
 
9
6
  env:
10
7
  ACTIONS_ALLOW_UNSECURE_COMMANDS: true
@@ -11,31 +11,27 @@ env:
11
11
 
12
12
  jobs:
13
13
  build-macos:
14
- runs-on: macos-11
14
+ runs-on: macos-latest
15
15
  strategy:
16
16
  matrix:
17
- node-version: [ 16.x]
17
+ node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x]
18
18
 
19
19
  steps:
20
- - uses: actions/checkout@v2
20
+ - uses: actions/checkout@v3
21
21
  - name: Install OpenSSL
22
- run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew reinstall openssl@1.1
22
+ run: |
23
+ wget https://mac.r-project.org/bin/darwin20/arm64/openssl-1.1.1o-darwin.20-arm64.tar.xz
24
+ tar -xf openssl-1.1.1o-darwin.20-arm64.tar.xz -C /tmp
25
+ rm -rf openssl-1.1.1o-darwin.20-arm64.tar.xz
23
26
  - name: Use Node.js ${{ matrix.node-version }}
24
- uses: actions/setup-node@v1
27
+ uses: actions/setup-node@v3
25
28
  with:
26
29
  node-version: ${{ matrix.node-version }}
27
- architecture: x64
28
30
  - name: Build
29
- run: npm install --build-from-source
30
- env:
31
- CI: true
32
- OPENSSL_ROOT_DIR: /usr/local/opt/openssl
33
- OPENSSL_LIBRARIES: /usr/local/opt/openssl/lib
34
- - name: Test
35
- run: npm run test
36
- env:
37
- CI: true
38
- - name: Upload
39
- run: node_modules/.bin/prebuild --upload -u ${{ secrets.GITHUB_TOKEN }}
31
+ run: |
32
+ npm install --ignore-scripts
33
+ node_modules/.bin/prebuild --backend cmake-js --arch arm64 --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_OSX_ARCHITECTURES="arm64"
40
34
  env:
41
35
  CI: true
36
+ OPENSSL_ROOT_DIR: /tmp/opt/R/arm64
37
+ OPENSSL_LIBRARIES: /tmp/opt/R/arm64/lib
@@ -1,4 +1,4 @@
1
- name: Build - Mac
1
+ name: Build - Mac x64
2
2
 
3
3
  on:
4
4
  workflow_dispatch:
package/API.md CHANGED
@@ -49,6 +49,10 @@ TURN Server Example (TLS) : turns:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
49
49
 
50
50
  Close Peer Connection
51
51
 
52
+ **destroy: () => void**
53
+
54
+ Close Peer Connection & Clear all callbacks
55
+
52
56
  **setRemoteDescription: (sdp: string, type: DescriptionType) => void**
53
57
 
54
58
  Set Remote Description
package/CMakeLists.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  cmake_minimum_required(VERSION 3.15)
2
2
  cmake_policy(SET CMP0091 NEW)
3
- project(node_datachannel VERSION 0.3.5)
3
+ project(node_datachannel VERSION 0.4.0)
4
4
 
5
5
  # Workaround for https://github.com/murat-dogan/node-datachannel/issues/65
6
6
  if( NODE_RUNTIMEVERSION VERSION_GREATER_EQUAL "17.0.0")
@@ -17,13 +17,18 @@ if(WIN32)
17
17
  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
18
18
  endif()
19
19
 
20
- # Got linker error for arm64
21
- # /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
22
- # ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): in function `sha1_block_armv8':
23
- # (.text+0x1240): dangerous relocation: unsupported relocation
24
- if(NOT ${NODE_ARCH} STREQUAL "arm64")
25
- set(OPENSSL_USE_STATIC_LIBS TRUE)
26
- find_package(OpenSSL REQUIRED)
20
+ if(APPLE)
21
+ set(OPENSSL_USE_STATIC_LIBS TRUE)
22
+ find_package(OpenSSL REQUIRED)
23
+ elseif(UNIX)
24
+ # Got linker error for arm64
25
+ # /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
26
+ # ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): in function `sha1_block_armv8':
27
+ # (.text+0x1240): dangerous relocation: unsupported relocation
28
+ if(NOT ${NODE_ARCH} STREQUAL "arm64")
29
+ set(OPENSSL_USE_STATIC_LIBS TRUE)
30
+ find_package(OpenSSL REQUIRED)
31
+ endif()
27
32
  endif()
28
33
 
29
34
 
@@ -33,7 +38,7 @@ include(FetchContent)
33
38
  FetchContent_Declare(
34
39
  libdatachannel
35
40
  GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
36
- GIT_TAG "v0.17.9"
41
+ GIT_TAG "v0.17.10"
37
42
  )
38
43
 
39
44
  option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
@@ -68,9 +73,12 @@ target_include_directories(${PROJECT_NAME} PRIVATE
68
73
  ${CMAKE_BINARY_DIR}/_deps/libdatachannel-src/include
69
74
  )
70
75
 
71
- # For compatibility with Node.js 12
72
- # This should be removed along with the napi-thread-safe-callback-cancellable dependency when dropping support at end-of-life
73
- target_compile_definitions(${PROJECT_NAME} PRIVATE -DLEGACY_NAPI_THREAD_SAFE_CALLBACK)
76
+ if( NODE_RUNTIMEVERSION VERSION_LESS "16.0.0")
77
+ # For compatibility with Node.js 12
78
+ # This should be removed along with the napi-thread-safe-callback-cancellable dependency when dropping support at end-of-life
79
+ target_compile_definitions(${PROJECT_NAME} PRIVATE -DLEGACY_NAPI_THREAD_SAFE_CALLBACK)
80
+ endif()
81
+
74
82
  target_include_directories(${PROJECT_NAME} PRIVATE
75
83
  ${CMAKE_SOURCE_DIR}/node_modules/napi-thread-safe-callback-cancellable
76
84
  )
@@ -81,8 +89,7 @@ set(LINK_LIBRARIES
81
89
  )
82
90
 
83
91
  if(APPLE)
84
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64 -arch arm64 ")
85
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_LINK_FLAGS} -arch x86_64 -arch arm64 ")
92
+ #
86
93
  elseif(UNIX)
87
94
  list(APPEND LINK_LIBRARIES -static-libgcc -static-libstdc++)
88
95
  endif()
package/README.md CHANGED
@@ -20,18 +20,19 @@ npm install node-datachannel
20
20
 
21
21
  ## Supported Platforms
22
22
 
23
- | | Linux-x64 | Linux-armv7 | Linux-arm64(1) | Windows-x86 | Windows-x64 | Mac |
24
- |----------|:---------:|:-----------:|:----------------:|:-----------:|:-----------:|:---:|
25
- | Node V10 | + | + | + | + | + | + |
26
- | Node V11 | + | + | + | + | + | + |
27
- | Node V12 | + | + | + | + | + | + |
28
- | Node V13 | + | + | + | + | + | + |
29
- | Node V14 | + | + | + | + | + | + |
30
- | Node V15 | + | + | + | + | + | + |
31
- | Node V16 | + | + | + | + | + | + |
32
- | Node V17 | + | + | + | + | + | + |
33
-
34
- 1) Please note that; For arm64 platform we need OpenSSL to be installed locally.
23
+ | | Linux-x64 | Linux-armv7 | Linux-arm64(1) | Windows-x86 | Windows-x64 | Mac (M1 + x64) |
24
+ |----------|:---------:|:-----------:|:----------------:|:-----------:|:-----------:|:--------------:|
25
+ | Node V10 | + | + | + | + | + | + |
26
+ | Node V11 | + | + | + | + | + | + |
27
+ | Node V12 | + | + | + | + | + | + |
28
+ | Node V13 | + | + | + | + | + | + |
29
+ | Node V14 | + | + | + | + | + | + |
30
+ | Node V15 | + | + | + | + | + | + |
31
+ | Node V16 | + | + | + | + | + | + |
32
+ | Node V17 | + | + | + | + | + | + |
33
+ | Node V18 | + | + | + | + | + | + |
34
+
35
+ 1) Please note that; For Linux-arm64 platform we need OpenSSL to be installed locally.
35
36
 
36
37
 
37
38
  ## Example Usage
package/lib/index.d.ts CHANGED
@@ -204,6 +204,7 @@ export class DataChannel {
204
204
  export class PeerConnection {
205
205
  constructor(peerName: string, config: RtcConfig);
206
206
  close(): void;
207
+ destroy(): void;
207
208
  setLocalDescription(type?: DescriptionType): void;
208
209
  setRemoteDescription(sdp: string, type: DescriptionType): void;
209
210
  localDescription(): { type: string; sdp: string } | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-datachannel",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
4
4
  "description": "libdatachannel node bindings",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -13,6 +13,7 @@
13
13
  "install": "prebuild-install || (npm install --ignore-scripts && npm run _prebuild)",
14
14
  "install-nice": "npm run clean && cmake-js build --CDUSE_NICE=1",
15
15
  "build": "cmake-js build",
16
+ "build:debug": "cmake-js build -D",
16
17
  "_prebuild": "prebuild --backend cmake-js",
17
18
  "clean": "cmake-js clean",
18
19
  "lint": "eslint lib/**/* test/**/*",
@@ -17,6 +17,13 @@ void PeerConnectionWrapper::CloseAll()
17
17
  inst->doClose();
18
18
  }
19
19
 
20
+ void PeerConnectionWrapper::ResetCallbacksAll()
21
+ {
22
+ auto copy(instances);
23
+ for (auto inst : copy)
24
+ inst->doResetCallbacks();
25
+ }
26
+
20
27
  Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
21
28
  {
22
29
  Napi::HandleScope scope(env);
@@ -26,6 +33,7 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
26
33
  "PeerConnection",
27
34
  {
28
35
  InstanceMethod("close", &PeerConnectionWrapper::close),
36
+ InstanceMethod("destroy", &PeerConnectionWrapper::destroy),
29
37
  InstanceMethod("setLocalDescription", &PeerConnectionWrapper::setLocalDescription),
30
38
  InstanceMethod("setRemoteDescription", &PeerConnectionWrapper::setRemoteDescription),
31
39
  InstanceMethod("localDescription", &PeerConnectionWrapper::localDescription),
@@ -225,7 +233,7 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
225
233
 
226
234
  PeerConnectionWrapper::~PeerConnectionWrapper()
227
235
  {
228
- doClose();
236
+ doDestroy();
229
237
  }
230
238
 
231
239
  void PeerConnectionWrapper::doClose()
@@ -243,7 +251,21 @@ void PeerConnectionWrapper::doClose()
243
251
  return;
244
252
  }
245
253
  }
254
+ }
246
255
 
256
+ void PeerConnectionWrapper::close(const Napi::CallbackInfo &info)
257
+ {
258
+ doClose();
259
+ }
260
+
261
+ void PeerConnectionWrapper::doDestroy()
262
+ {
263
+ doClose();
264
+ doResetCallbacks();
265
+ }
266
+
267
+ void PeerConnectionWrapper::doResetCallbacks()
268
+ {
247
269
  mOnLocalDescriptionCallback.reset();
248
270
  mOnLocalCandidateCallback.reset();
249
271
  mOnStateChangeCallback.reset();
@@ -254,9 +276,9 @@ void PeerConnectionWrapper::doClose()
254
276
  instances.erase(this);
255
277
  }
256
278
 
257
- void PeerConnectionWrapper::close(const Napi::CallbackInfo &info)
279
+ void PeerConnectionWrapper::destroy(const Napi::CallbackInfo &info)
258
280
  {
259
- doClose();
281
+ doDestroy();
260
282
  }
261
283
 
262
284
  void PeerConnectionWrapper::setLocalDescription(const Napi::CallbackInfo &info)
@@ -639,9 +661,8 @@ void PeerConnectionWrapper::onStateChange(const Napi::CallbackInfo &info)
639
661
 
640
662
  mRtcPeerConnPtr->onStateChange([&](rtc::PeerConnection::State state) {
641
663
  if (mOnStateChangeCallback)
642
- mOnStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
643
- // Check the peer connection is not closed but still allow a call for State::Closed
644
- if(state != rtc::PeerConnection::State::Closed && instances.find(this) == instances.end())
664
+ mOnStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
665
+ if(instances.find(this) == instances.end())
645
666
  throw ThreadSafeCallback::CancelException();
646
667
 
647
668
  // This will run in main thread and needs to construct the
@@ -19,6 +19,8 @@ public:
19
19
  PeerConnectionWrapper(const Napi::CallbackInfo &info);
20
20
  ~PeerConnectionWrapper();
21
21
 
22
+ void destroy(const Napi::CallbackInfo &info);
23
+
22
24
  // Functions
23
25
  void close(const Napi::CallbackInfo &info);
24
26
  void setLocalDescription(const Napi::CallbackInfo &info);
@@ -47,14 +49,19 @@ public:
47
49
  Napi::Value rtt(const Napi::CallbackInfo &info);
48
50
  Napi::Value getSelectedCandidatePair(const Napi::CallbackInfo &info);
49
51
 
50
- // Close all existing DataChannels
52
+ // Close all existing Peer Connections
51
53
  static void CloseAll();
52
54
 
55
+ // Reset all Callbacks for existing Peer Connections
56
+ static void ResetCallbacksAll();
57
+
53
58
  private:
54
59
  static Napi::FunctionReference constructor;
55
60
  static std::unordered_set<PeerConnectionWrapper *> instances;
56
61
 
57
62
  void doClose();
63
+ void doDestroy();
64
+ void doResetCallbacks();
58
65
 
59
66
  std::string mPeerName;
60
67
  std::unique_ptr<rtc::PeerConnection> mRtcPeerConnPtr = nullptr;
@@ -82,7 +82,10 @@ void RtcWrapper::cleanup(const Napi::CallbackInfo &info)
82
82
  const auto timeout = std::chrono::seconds(10);
83
83
  if(rtc::Cleanup().wait_for(std::chrono::seconds(timeout)) == std::future_status::timeout)
84
84
  throw std::runtime_error("cleanup timeout (possible deadlock)");
85
- }
85
+
86
+ // Clear Callbacks
87
+ PeerConnectionWrapper::ResetCallbacksAll();
88
+ }
86
89
  catch (std::exception &ex)
87
90
  {
88
91
  Napi::Error::New(env, std::string("libdatachannel error# ") + ex.what()).ThrowAsJavaScriptException();