node-datachannel 0.2.1 → 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.
- package/CMakeLists.txt +1 -1
- package/README.md +18 -3
- package/lib/index.d.ts +5 -1
- package/package.json +1 -1
- package/src/peer-connection-wrapper.cpp +63 -10
- package/src/peer-connection-wrapper.h +7 -2
package/CMakeLists.txt
CHANGED
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ TURN Server Example : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
|
|
|
133
133
|
TURN Server Example (TCP) : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT?transport=tcp
|
|
134
134
|
TURN Server Example (TLS) : turns:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
|
|
135
135
|
|
|
136
|
-
```
|
|
136
|
+
```
|
|
137
137
|
|
|
138
138
|
**close: () => void**
|
|
139
139
|
|
|
@@ -179,7 +179,18 @@ export interface DataChannelInitConfig {
|
|
|
179
179
|
export const enum ReliabilityType {
|
|
180
180
|
Reliable = 0, Rexmit = 1, Timed = 2
|
|
181
181
|
}
|
|
182
|
-
```
|
|
182
|
+
```
|
|
183
|
+
**state: () => string**
|
|
184
|
+
|
|
185
|
+
Get current state
|
|
186
|
+
|
|
187
|
+
**signalingState: () => string**
|
|
188
|
+
|
|
189
|
+
Get current signaling state
|
|
190
|
+
|
|
191
|
+
**gatheringState: () => string**
|
|
192
|
+
|
|
193
|
+
Get current gathering state
|
|
183
194
|
|
|
184
195
|
**onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void**
|
|
185
196
|
|
|
@@ -200,6 +211,10 @@ Local Candidate Callback
|
|
|
200
211
|
|
|
201
212
|
State Change Callback
|
|
202
213
|
|
|
214
|
+
**onSignalingStateChange: (state: (sdp: string) => void) => void**
|
|
215
|
+
|
|
216
|
+
Signaling State Change Callback
|
|
217
|
+
|
|
203
218
|
**onGatheringStateChange: (state: (sdp: string) => void) => void**
|
|
204
219
|
|
|
205
220
|
Gathering State Change Callback
|
|
@@ -238,7 +253,7 @@ export interface SelectedCandidateInfo {
|
|
|
238
253
|
|
|
239
254
|
**close: () => void**
|
|
240
255
|
|
|
241
|
-
Close data channel
|
|
256
|
+
Close data channel
|
|
242
257
|
|
|
243
258
|
**getLabel: () => string**
|
|
244
259
|
|
package/lib/index.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export class Video {
|
|
|
134
134
|
addH264Codec: (payloadType: Number, profile?: string) => void;
|
|
135
135
|
addVP8Codec: (payloadType: Number) => void;
|
|
136
136
|
addVP9Codec: (payloadType: Number) => void;
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
direction: () => Direction;
|
|
139
139
|
generateSdp: (eol: string, addr: string, port: string) => string;
|
|
140
140
|
mid: () => string;
|
|
@@ -205,9 +205,13 @@ export class PeerConnection {
|
|
|
205
205
|
createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel;
|
|
206
206
|
addTrack: (media: Video | Audio) => Track;
|
|
207
207
|
hasMedia: () => boolean;
|
|
208
|
+
state: () => string;
|
|
209
|
+
signalingState: () => string;
|
|
210
|
+
gatheringState: () => string;
|
|
208
211
|
onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void;
|
|
209
212
|
onLocalCandidate: (cb: (candidate: string, mid: string) => void) => void;
|
|
210
213
|
onStateChange: (cb: (state: string) => void) => void;
|
|
214
|
+
onSignalingStateChange: (state: (sdp: string) => void) => void;
|
|
211
215
|
onGatheringStateChange: (state: (sdp: string) => void) => void;
|
|
212
216
|
onDataChannel: (cb: (dc: DataChannel) => void) => void;
|
|
213
217
|
onTrack: () => Track;
|
package/package.json
CHANGED
|
@@ -32,9 +32,13 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
|
|
|
32
32
|
InstanceMethod("createDataChannel", &PeerConnectionWrapper::createDataChannel),
|
|
33
33
|
InstanceMethod("addTrack", &PeerConnectionWrapper::addTrack),
|
|
34
34
|
InstanceMethod("hasMedia", &PeerConnectionWrapper::hasMedia),
|
|
35
|
+
InstanceMethod("state", &PeerConnectionWrapper::state),
|
|
36
|
+
InstanceMethod("signalingState", &PeerConnectionWrapper::signalingState),
|
|
37
|
+
InstanceMethod("gatheringState", &PeerConnectionWrapper::gatheringState),
|
|
35
38
|
InstanceMethod("onLocalDescription", &PeerConnectionWrapper::onLocalDescription),
|
|
36
39
|
InstanceMethod("onLocalCandidate", &PeerConnectionWrapper::onLocalCandidate),
|
|
37
40
|
InstanceMethod("onStateChange", &PeerConnectionWrapper::onStateChange),
|
|
41
|
+
InstanceMethod("onSignalingStateChange", &PeerConnectionWrapper::onSignalingStateChange),
|
|
38
42
|
InstanceMethod("onGatheringStateChange", &PeerConnectionWrapper::onGatheringStateChange),
|
|
39
43
|
InstanceMethod("onDataChannel", &PeerConnectionWrapper::onDataChannel),
|
|
40
44
|
InstanceMethod("onTrack", &PeerConnectionWrapper::onTrack),
|
|
@@ -536,8 +540,7 @@ void PeerConnectionWrapper::onLocalDescription(const Napi::CallbackInfo &info)
|
|
|
536
540
|
// Callback
|
|
537
541
|
mOnLocalDescriptionCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
538
542
|
|
|
539
|
-
mRtcPeerConnPtr->onLocalDescription([&](const rtc::Description &sdp)
|
|
540
|
-
{
|
|
543
|
+
mRtcPeerConnPtr->onLocalDescription([&](const rtc::Description &sdp) {
|
|
541
544
|
if (mOnLocalDescriptionCallback)
|
|
542
545
|
mOnLocalDescriptionCallback->call([this, sdp](Napi::Env env, std::vector<napi_value> &args) {
|
|
543
546
|
// Check the peer connection is not closed
|
|
@@ -566,8 +569,7 @@ void PeerConnectionWrapper::onLocalCandidate(const Napi::CallbackInfo &info)
|
|
|
566
569
|
// Callback
|
|
567
570
|
mOnLocalCandidateCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
568
571
|
|
|
569
|
-
mRtcPeerConnPtr->onLocalCandidate([&](const rtc::Candidate &candidate)
|
|
570
|
-
{
|
|
572
|
+
mRtcPeerConnPtr->onLocalCandidate([&](const rtc::Candidate &candidate) {
|
|
571
573
|
if (mOnLocalCandidateCallback)
|
|
572
574
|
mOnLocalCandidateCallback->call([this, candidate](Napi::Env env, std::vector<napi_value> &args) {
|
|
573
575
|
// Check the peer connection is not closed
|
|
@@ -596,8 +598,7 @@ void PeerConnectionWrapper::onStateChange(const Napi::CallbackInfo &info)
|
|
|
596
598
|
// Callback
|
|
597
599
|
mOnStateChangeCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
598
600
|
|
|
599
|
-
mRtcPeerConnPtr->onStateChange([&](rtc::PeerConnection::State state)
|
|
600
|
-
{
|
|
601
|
+
mRtcPeerConnPtr->onStateChange([&](rtc::PeerConnection::State state) {
|
|
601
602
|
if (mOnStateChangeCallback)
|
|
602
603
|
mOnStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
|
|
603
604
|
// Check the peer connection is not closed
|
|
@@ -612,6 +613,35 @@ void PeerConnectionWrapper::onStateChange(const Napi::CallbackInfo &info)
|
|
|
612
613
|
}); });
|
|
613
614
|
}
|
|
614
615
|
|
|
616
|
+
void PeerConnectionWrapper::onSignalingStateChange(const Napi::CallbackInfo &info)
|
|
617
|
+
{
|
|
618
|
+
Napi::Env env = info.Env();
|
|
619
|
+
int length = info.Length();
|
|
620
|
+
|
|
621
|
+
if (length < 1 || !info[0].IsFunction())
|
|
622
|
+
{
|
|
623
|
+
Napi::TypeError::New(env, "Function expected").ThrowAsJavaScriptException();
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// Callback
|
|
628
|
+
mOnSignalingStateChangeCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
629
|
+
|
|
630
|
+
mRtcPeerConnPtr->onSignalingStateChange([&](rtc::PeerConnection::SignalingState state) {
|
|
631
|
+
if (mOnSignalingStateChangeCallback)
|
|
632
|
+
mOnSignalingStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
|
|
633
|
+
// Check the peer connection is not closed
|
|
634
|
+
if(instances.find(this) == instances.end())
|
|
635
|
+
throw ThreadSafeCallback::CancelException();
|
|
636
|
+
|
|
637
|
+
// This will run in main thread and needs to construct the
|
|
638
|
+
// arguments for the call
|
|
639
|
+
std::ostringstream stream;
|
|
640
|
+
stream << state;
|
|
641
|
+
args = {Napi::String::New(env, stream.str())};
|
|
642
|
+
}); });
|
|
643
|
+
}
|
|
644
|
+
|
|
615
645
|
void PeerConnectionWrapper::onGatheringStateChange(const Napi::CallbackInfo &info)
|
|
616
646
|
{
|
|
617
647
|
Napi::Env env = info.Env();
|
|
@@ -626,8 +656,7 @@ void PeerConnectionWrapper::onGatheringStateChange(const Napi::CallbackInfo &inf
|
|
|
626
656
|
// Callback
|
|
627
657
|
mOnGatheringStateChangeCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
628
658
|
|
|
629
|
-
mRtcPeerConnPtr->onGatheringStateChange([&](rtc::PeerConnection::GatheringState state)
|
|
630
|
-
{
|
|
659
|
+
mRtcPeerConnPtr->onGatheringStateChange([&](rtc::PeerConnection::GatheringState state) {
|
|
631
660
|
if (mOnGatheringStateChangeCallback)
|
|
632
661
|
mOnGatheringStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
|
|
633
662
|
// Check the peer connection is not closed
|
|
@@ -841,7 +870,7 @@ Napi::Value PeerConnectionWrapper::addTrack(const Napi::CallbackInfo &info)
|
|
|
841
870
|
return instance;
|
|
842
871
|
}
|
|
843
872
|
|
|
844
|
-
|
|
873
|
+
Napi::Error::New(env, std::string("Unknown media type")).ThrowAsJavaScriptException();
|
|
845
874
|
return env.Null();
|
|
846
875
|
}
|
|
847
876
|
catch (std::exception &ex)
|
|
@@ -885,4 +914,28 @@ Napi::Value PeerConnectionWrapper::hasMedia(const Napi::CallbackInfo &info)
|
|
|
885
914
|
{
|
|
886
915
|
Napi::Env env = info.Env();
|
|
887
916
|
return Napi::Boolean::New(env, mRtcPeerConnPtr->hasMedia());
|
|
888
|
-
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
Napi::Value PeerConnectionWrapper::state(const Napi::CallbackInfo &info)
|
|
920
|
+
{
|
|
921
|
+
Napi::Env env = info.Env();
|
|
922
|
+
std::ostringstream stream;
|
|
923
|
+
stream << mRtcPeerConnPtr->state();
|
|
924
|
+
return Napi::String::New(env, stream.str());
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
Napi::Value PeerConnectionWrapper::signalingState(const Napi::CallbackInfo &info)
|
|
928
|
+
{
|
|
929
|
+
Napi::Env env = info.Env();
|
|
930
|
+
std::ostringstream stream;
|
|
931
|
+
stream << mRtcPeerConnPtr->signalingState();
|
|
932
|
+
return Napi::String::New(env, stream.str());
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
Napi::Value PeerConnectionWrapper::gatheringState(const Napi::CallbackInfo &info)
|
|
936
|
+
{
|
|
937
|
+
Napi::Env env = info.Env();
|
|
938
|
+
std::ostringstream stream;
|
|
939
|
+
stream << mRtcPeerConnPtr->gatheringState();
|
|
940
|
+
return Napi::String::New(env, stream.str());
|
|
941
|
+
}
|
|
@@ -26,13 +26,17 @@ public:
|
|
|
26
26
|
Napi::Value localDescription(const Napi::CallbackInfo &info);
|
|
27
27
|
void addRemoteCandidate(const Napi::CallbackInfo &info);
|
|
28
28
|
Napi::Value createDataChannel(const Napi::CallbackInfo &info);
|
|
29
|
-
Napi::Value addTrack(const Napi::CallbackInfo &info);
|
|
30
|
-
Napi::Value hasMedia(const Napi::CallbackInfo &info);
|
|
29
|
+
Napi::Value addTrack(const Napi::CallbackInfo &info);
|
|
30
|
+
Napi::Value hasMedia(const Napi::CallbackInfo &info);
|
|
31
|
+
Napi::Value state(const Napi::CallbackInfo &info);
|
|
32
|
+
Napi::Value signalingState(const Napi::CallbackInfo &info);
|
|
33
|
+
Napi::Value gatheringState(const Napi::CallbackInfo &info);
|
|
31
34
|
|
|
32
35
|
// Callbacks
|
|
33
36
|
void onLocalDescription(const Napi::CallbackInfo &info);
|
|
34
37
|
void onLocalCandidate(const Napi::CallbackInfo &info);
|
|
35
38
|
void onStateChange(const Napi::CallbackInfo &info);
|
|
39
|
+
void onSignalingStateChange(const Napi::CallbackInfo &info);
|
|
36
40
|
void onGatheringStateChange(const Napi::CallbackInfo &info);
|
|
37
41
|
void onDataChannel(const Napi::CallbackInfo &info);
|
|
38
42
|
void onTrack(const Napi::CallbackInfo &info);
|
|
@@ -59,6 +63,7 @@ private:
|
|
|
59
63
|
std::unique_ptr<ThreadSafeCallback> mOnLocalDescriptionCallback = nullptr;
|
|
60
64
|
std::unique_ptr<ThreadSafeCallback> mOnLocalCandidateCallback = nullptr;
|
|
61
65
|
std::unique_ptr<ThreadSafeCallback> mOnStateChangeCallback = nullptr;
|
|
66
|
+
std::unique_ptr<ThreadSafeCallback> mOnSignalingStateChangeCallback = nullptr;
|
|
62
67
|
std::unique_ptr<ThreadSafeCallback> mOnGatheringStateChangeCallback = nullptr;
|
|
63
68
|
std::unique_ptr<ThreadSafeCallback> mOnDataChannelCallback = nullptr;
|
|
64
69
|
std::unique_ptr<ThreadSafeCallback> mOnTrackCallback = nullptr;
|