node-datachannel 0.3.6 → 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.
- package/API.md +4 -0
- package/CMakeLists.txt +8 -5
- package/README.md +1 -0
- package/lib/index.d.ts +1 -0
- package/package.json +2 -1
- package/src/peer-connection-wrapper.cpp +27 -6
- package/src/peer-connection-wrapper.h +8 -1
- package/src/rtc-wrapper.cpp +4 -1
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
|
+
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")
|
|
@@ -38,7 +38,7 @@ include(FetchContent)
|
|
|
38
38
|
FetchContent_Declare(
|
|
39
39
|
libdatachannel
|
|
40
40
|
GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
|
|
41
|
-
GIT_TAG "v0.17.
|
|
41
|
+
GIT_TAG "v0.17.10"
|
|
42
42
|
)
|
|
43
43
|
|
|
44
44
|
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
|
|
@@ -73,9 +73,12 @@ target_include_directories(${PROJECT_NAME} PRIVATE
|
|
|
73
73
|
${CMAKE_BINARY_DIR}/_deps/libdatachannel-src/include
|
|
74
74
|
)
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
#
|
|
78
|
-
|
|
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
|
+
|
|
79
82
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
|
80
83
|
${CMAKE_SOURCE_DIR}/node_modules/napi-thread-safe-callback-cancellable
|
|
81
84
|
)
|
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ npm install node-datachannel
|
|
|
30
30
|
| Node V15 | + | + | + | + | + | + |
|
|
31
31
|
| Node V16 | + | + | + | + | + | + |
|
|
32
32
|
| Node V17 | + | + | + | + | + | + |
|
|
33
|
+
| Node V18 | + | + | + | + | + | + |
|
|
33
34
|
|
|
34
35
|
1) Please note that; For Linux-arm64 platform we need OpenSSL to be installed locally.
|
|
35
36
|
|
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
|
+
"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
|
-
|
|
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::
|
|
279
|
+
void PeerConnectionWrapper::destroy(const Napi::CallbackInfo &info)
|
|
258
280
|
{
|
|
259
|
-
|
|
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
|
-
|
|
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
|
|
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;
|
package/src/rtc-wrapper.cpp
CHANGED
|
@@ -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();
|