node-datachannel 0.29.0 → 0.30.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.
Files changed (33) hide show
  1. package/.clang-format +17 -0
  2. package/CMakeLists.txt +5 -1
  3. package/dist/cjs/polyfill/RTCPeerConnection.cjs +6 -1
  4. package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
  5. package/dist/esm/polyfill/RTCPeerConnection.mjs +6 -1
  6. package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
  7. package/dist/types/polyfill/RTCPeerConnection.d.ts +1 -2
  8. package/package.json +3 -2
  9. package/src/cpp/data-channel-wrapper.cpp +432 -411
  10. package/src/cpp/data-channel-wrapper.h +0 -2
  11. package/src/cpp/ice-udp-mux-listener-wrapper.cpp +104 -97
  12. package/src/cpp/main.cpp +11 -11
  13. package/src/cpp/media-audio-wrapper.cpp +291 -294
  14. package/src/cpp/media-audio-wrapper.h +1 -3
  15. package/src/cpp/media-direction.cpp +32 -32
  16. package/src/cpp/media-direction.h +1 -1
  17. package/src/cpp/media-rtcpreceivingsession-wrapper.cpp +24 -28
  18. package/src/cpp/media-rtcpreceivingsession-wrapper.h +0 -5
  19. package/src/cpp/media-track-wrapper.cpp +350 -339
  20. package/src/cpp/media-track-wrapper.h +0 -3
  21. package/src/cpp/media-video-wrapper.cpp +312 -313
  22. package/src/cpp/media-video-wrapper.h +1 -3
  23. package/src/cpp/peer-connection-wrapper.cpp +1094 -1047
  24. package/src/cpp/peer-connection-wrapper.h +0 -2
  25. package/src/cpp/rtc-wrapper.cpp +142 -138
  26. package/src/cpp/rtc-wrapper.h +8 -10
  27. package/src/cpp/thread-safe-callback.cpp +39 -50
  28. package/src/cpp/thread-safe-callback.h +26 -28
  29. package/src/cpp/web-socket-server-wrapper.cpp +205 -199
  30. package/src/cpp/web-socket-server-wrapper.h +0 -4
  31. package/src/cpp/web-socket-wrapper.cpp +625 -598
  32. package/src/cpp/web-socket-wrapper.h +0 -3
  33. package/src/polyfill/RTCPeerConnection.ts +9 -3
@@ -1,9 +1,7 @@
1
1
  #ifndef DATA_CHANNEL_WRAPPER_H
2
2
  #define DATA_CHANNEL_WRAPPER_H
3
3
 
4
- #include <iostream>
5
4
  #include <string>
6
- #include <variant>
7
5
  #include <memory>
8
6
  #include <unordered_set>
9
7
 
@@ -3,104 +3,106 @@
3
3
  #include "plog/Log.h"
4
4
 
5
5
  #include <cctype>
6
- #include <sstream>
7
6
 
8
7
  Napi::FunctionReference IceUdpMuxListenerWrapper::constructor = Napi::FunctionReference();
9
8
  std::unordered_set<IceUdpMuxListenerWrapper *> IceUdpMuxListenerWrapper::instances;
10
9
 
11
10
  void IceUdpMuxListenerWrapper::StopAll()
12
11
  {
13
- PLOG_DEBUG << "IceUdpMuxListenerWrapper StopAll() called";
14
- auto copy(instances);
15
- for (auto inst : copy)
16
- inst->doCleanup();
12
+ PLOG_DEBUG << "IceUdpMuxListenerWrapper StopAll() called";
13
+ auto copy(instances);
14
+ for (auto inst : copy)
15
+ inst->doCleanup();
17
16
  }
18
17
 
19
18
  Napi::Object IceUdpMuxListenerWrapper::Init(Napi::Env env, Napi::Object exports)
20
19
  {
21
- Napi::HandleScope scope(env);
22
-
23
- Napi::Function func = DefineClass(
24
- env,
25
- "IceUdpMuxListener",
26
- {
27
- InstanceMethod("stop", &IceUdpMuxListenerWrapper::stop),
28
- InstanceMethod("onUnhandledStunRequest", &IceUdpMuxListenerWrapper::onUnhandledStunRequest),
29
- InstanceMethod("port", &IceUdpMuxListenerWrapper::port),
30
- InstanceMethod("address", &IceUdpMuxListenerWrapper::address)
31
- });
32
-
33
- // If this is not the first call, we don't want to reassign the constructor (hot-reload problem)
34
- if(constructor.IsEmpty())
35
- {
36
- constructor = Napi::Persistent(func);
37
- constructor.SuppressDestruct();
38
- }
39
-
40
- exports.Set("IceUdpMuxListener", func);
41
- return exports;
20
+ Napi::HandleScope scope(env);
21
+
22
+ Napi::Function func =
23
+ DefineClass(env, "IceUdpMuxListener",
24
+ {InstanceMethod("stop", &IceUdpMuxListenerWrapper::stop),
25
+ InstanceMethod("onUnhandledStunRequest", &IceUdpMuxListenerWrapper::onUnhandledStunRequest),
26
+ InstanceMethod("port", &IceUdpMuxListenerWrapper::port),
27
+ InstanceMethod("address", &IceUdpMuxListenerWrapper::address)});
28
+
29
+ // If this is not the first call, we don't want to reassign the constructor (hot-reload problem)
30
+ if (constructor.IsEmpty())
31
+ {
32
+ constructor = Napi::Persistent(func);
33
+ constructor.SuppressDestruct();
34
+ }
35
+
36
+ exports.Set("IceUdpMuxListener", func);
37
+ return exports;
42
38
  }
43
39
 
44
- IceUdpMuxListenerWrapper::IceUdpMuxListenerWrapper(const Napi::CallbackInfo &info) : Napi::ObjectWrap<IceUdpMuxListenerWrapper>(info)
40
+ IceUdpMuxListenerWrapper::IceUdpMuxListenerWrapper(const Napi::CallbackInfo &info)
41
+ : Napi::ObjectWrap<IceUdpMuxListenerWrapper>(info)
45
42
  {
46
- PLOG_DEBUG << "IceUdpMuxListenerWrapper Constructor called";
47
- Napi::Env env = info.Env();
48
- int length = info.Length();
49
-
50
- // We expect (Number, String?) as param
51
- if (length > 0 && info[0].IsNumber()) {
52
- // Port
53
- mPort = info[0].As<Napi::Number>().ToNumber().Uint32Value();
54
- } else {
55
- Napi::TypeError::New(env, "Port (Number) and optional Address (String) expected").ThrowAsJavaScriptException();
56
- return;
57
- }
58
-
59
- if (length > 1 && info[1].IsString()) {
60
- // Address
61
- mAddress = info[1].As<Napi::String>().ToString();
62
- }
63
-
64
- iceUdpMuxListenerPtr = std::make_unique<rtc::IceUdpMuxListener>(mPort, mAddress);
65
- instances.insert(this);
43
+ PLOG_DEBUG << "IceUdpMuxListenerWrapper Constructor called";
44
+ Napi::Env env = info.Env();
45
+ int length = info.Length();
46
+
47
+ // We expect (Number, String?) as param
48
+ if (length > 0 && info[0].IsNumber())
49
+ {
50
+ // Port
51
+ mPort = info[0].As<Napi::Number>().ToNumber().Uint32Value();
52
+ }
53
+ else
54
+ {
55
+ Napi::TypeError::New(env, "Port (Number) and optional Address (String) expected").ThrowAsJavaScriptException();
56
+ return;
57
+ }
58
+
59
+ if (length > 1 && info[1].IsString())
60
+ {
61
+ // Address
62
+ mAddress = info[1].As<Napi::String>().ToString();
63
+ }
64
+
65
+ iceUdpMuxListenerPtr = std::make_unique<rtc::IceUdpMuxListener>(mPort, mAddress);
66
+ instances.insert(this);
66
67
  }
67
68
 
68
69
  IceUdpMuxListenerWrapper::~IceUdpMuxListenerWrapper()
69
70
  {
70
- PLOG_DEBUG << "IceUdpMuxListenerWrapper Destructor called";
71
- doCleanup();
71
+ PLOG_DEBUG << "IceUdpMuxListenerWrapper Destructor called";
72
+ doCleanup();
72
73
  }
73
74
 
74
75
  void IceUdpMuxListenerWrapper::doCleanup()
75
76
  {
76
- PLOG_DEBUG << "IceUdpMuxListenerWrapper::doCleanup() called";
77
+ PLOG_DEBUG << "IceUdpMuxListenerWrapper::doCleanup() called";
77
78
 
78
- if (iceUdpMuxListenerPtr)
79
- {
80
- iceUdpMuxListenerPtr->stop();
81
- iceUdpMuxListenerPtr.reset();
82
- }
79
+ if (iceUdpMuxListenerPtr)
80
+ {
81
+ iceUdpMuxListenerPtr->stop();
82
+ iceUdpMuxListenerPtr.reset();
83
+ }
83
84
 
84
- mOnUnhandledStunRequestCallback.reset();
85
- instances.erase(this);
85
+ mOnUnhandledStunRequestCallback.reset();
86
+ instances.erase(this);
86
87
  }
87
88
 
88
89
  Napi::Value IceUdpMuxListenerWrapper::port(const Napi::CallbackInfo &info)
89
90
  {
90
- Napi::Env env = info.Env();
91
+ Napi::Env env = info.Env();
91
92
 
92
- return Napi::Number::New(env, mPort);
93
+ return Napi::Number::New(env, mPort);
93
94
  }
94
95
 
95
96
  Napi::Value IceUdpMuxListenerWrapper::address(const Napi::CallbackInfo &info)
96
97
  {
97
- Napi::Env env = info.Env();
98
+ Napi::Env env = info.Env();
98
99
 
99
- if (!mAddress.has_value()) {
100
- return env.Undefined();
101
- }
100
+ if (!mAddress.has_value())
101
+ {
102
+ return env.Undefined();
103
+ }
102
104
 
103
- return Napi::String::New(env, mAddress.value());
105
+ return Napi::String::New(env, mAddress.value());
104
106
  }
105
107
 
106
108
  void IceUdpMuxListenerWrapper::stop(const Napi::CallbackInfo &info)
@@ -111,40 +113,45 @@ void IceUdpMuxListenerWrapper::stop(const Napi::CallbackInfo &info)
111
113
 
112
114
  void IceUdpMuxListenerWrapper::onUnhandledStunRequest(const Napi::CallbackInfo &info)
113
115
  {
114
- PLOG_DEBUG << "IceUdpMuxListenerWrapper::onUnhandledStunRequest() called";
115
- Napi::Env env = info.Env();
116
- int length = info.Length();
117
-
118
- if (!iceUdpMuxListenerPtr)
119
- {
120
- Napi::Error::New(env, "IceUdpMuxListenerWrapper::onUnhandledStunRequest() called on destroyed IceUdpMuxListener").ThrowAsJavaScriptException();
121
- return;
122
- }
123
-
124
- if (length < 1 || !info[0].IsFunction())
116
+ PLOG_DEBUG << "IceUdpMuxListenerWrapper::onUnhandledStunRequest() called";
117
+ Napi::Env env = info.Env();
118
+ int length = info.Length();
119
+
120
+ if (!iceUdpMuxListenerPtr)
121
+ {
122
+ Napi::Error::New(env, "IceUdpMuxListenerWrapper::onUnhandledStunRequest() called on destroyed IceUdpMuxListener")
123
+ .ThrowAsJavaScriptException();
124
+ return;
125
+ }
126
+
127
+ if (length < 1 || !info[0].IsFunction())
128
+ {
129
+ Napi::TypeError::New(env, "Function expected").ThrowAsJavaScriptException();
130
+ return;
131
+ }
132
+
133
+ // Callback
134
+ mOnUnhandledStunRequestCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
135
+
136
+ iceUdpMuxListenerPtr->OnUnhandledStunRequest(
137
+ [&](rtc::IceUdpMuxRequest request)
138
+ {
139
+ PLOG_DEBUG << "IceUdpMuxListenerWrapper::onUnhandledStunRequest() IceUdpMuxCallback call(1)";
140
+
141
+ if (mOnUnhandledStunRequestCallback)
125
142
  {
126
- Napi::TypeError::New(env, "Function expected").ThrowAsJavaScriptException();
127
- return;
143
+ mOnUnhandledStunRequestCallback->call(
144
+ [request = std::move(request)](Napi::Env env, std::vector<napi_value> &args)
145
+ {
146
+ Napi::Object reqObj = Napi::Object::New(env);
147
+ reqObj.Set("ufrag", request.remoteUfrag.c_str());
148
+ reqObj.Set("host", request.remoteAddress.c_str());
149
+ reqObj.Set("port", request.remotePort);
150
+
151
+ args = {reqObj};
152
+ });
128
153
  }
129
154
 
130
- // Callback
131
- mOnUnhandledStunRequestCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
132
-
133
- iceUdpMuxListenerPtr->OnUnhandledStunRequest([&](rtc::IceUdpMuxRequest request)
134
- {
135
- PLOG_DEBUG << "IceUdpMuxListenerWrapper::onUnhandledStunRequest() IceUdpMuxCallback call(1)";
136
-
137
- if (mOnUnhandledStunRequestCallback) {
138
- mOnUnhandledStunRequestCallback->call([request = std::move(request)](Napi::Env env, std::vector<napi_value> &args) {
139
- Napi::Object reqObj = Napi::Object::New(env);
140
- reqObj.Set("ufrag", request.remoteUfrag.c_str());
141
- reqObj.Set("host", request.remoteAddress.c_str());
142
- reqObj.Set("port", request.remotePort);
143
-
144
- args = {reqObj};
145
- });
146
- }
147
-
148
- PLOG_DEBUG << "IceUdpMuxListenerWrapper::onUnhandledStunRequest() IceUdpMuxCallback call(2)";
149
- });
155
+ PLOG_DEBUG << "IceUdpMuxListenerWrapper::onUnhandledStunRequest() IceUdpMuxCallback call(2)";
156
+ });
150
157
  }
package/src/cpp/main.cpp CHANGED
@@ -18,25 +18,25 @@
18
18
 
19
19
  Napi::Object InitAll(Napi::Env env, Napi::Object exports)
20
20
  {
21
- RtcWrapper::Init(env, exports);
21
+ RtcWrapper::Init(env, exports);
22
22
 
23
23
  #if RTC_ENABLE_MEDIA == 1
24
- RtcpReceivingSessionWrapper::Init(env, exports);
25
- TrackWrapper::Init(env, exports);
26
- VideoWrapper::Init(env, exports);
27
- AudioWrapper::Init(env, exports);
24
+ RtcpReceivingSessionWrapper::Init(env, exports);
25
+ TrackWrapper::Init(env, exports);
26
+ VideoWrapper::Init(env, exports);
27
+ AudioWrapper::Init(env, exports);
28
28
  #endif
29
29
 
30
- DataChannelWrapper::Init(env, exports);
31
- IceUdpMuxListenerWrapper::Init(env, exports);
32
- PeerConnectionWrapper::Init(env, exports);
30
+ DataChannelWrapper::Init(env, exports);
31
+ IceUdpMuxListenerWrapper::Init(env, exports);
32
+ PeerConnectionWrapper::Init(env, exports);
33
33
 
34
34
  #if RTC_ENABLE_WEBSOCKET == 1
35
- WebSocketWrapper::Init(env, exports);
36
- WebSocketServerWrapper::Init(env, exports);
35
+ WebSocketWrapper::Init(env, exports);
36
+ WebSocketServerWrapper::Init(env, exports);
37
37
  #endif
38
38
 
39
- return exports;
39
+ return exports;
40
40
  }
41
41
 
42
42
  NODE_API_MODULE(nodeDataChannel, InitAll)