node-datachannel 0.2.2 → 0.3.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 (130) hide show
  1. package/.editorconfig +12 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.js +8 -0
  4. package/.github/FUNDING.yml +2 -0
  5. package/.github/workflows/build-linux.yml +5 -3
  6. package/.github/workflows/build-mac.yml +1 -1
  7. package/.github/workflows/build-win.yml +4 -10
  8. package/.prettierrc.js +7 -0
  9. package/CMakeLists.txt +8 -2
  10. package/README.md +4 -4
  11. package/lib/datachannel-stream.js +97 -0
  12. package/lib/index.d.ts +60 -53
  13. package/lib/index.js +5 -2
  14. package/node_modules/decompress-response/index.d.ts +14 -21
  15. package/node_modules/decompress-response/index.js +34 -16
  16. package/node_modules/decompress-response/license +1 -1
  17. package/node_modules/decompress-response/package.json +23 -17
  18. package/node_modules/decompress-response/readme.md +2 -6
  19. package/node_modules/detect-libc/README.md +124 -42
  20. package/node_modules/detect-libc/index.d.ts +11 -0
  21. package/node_modules/detect-libc/lib/detect-libc.js +166 -80
  22. package/node_modules/detect-libc/lib/process.js +16 -0
  23. package/node_modules/detect-libc/package.json +20 -19
  24. package/node_modules/{semver → lru-cache}/LICENSE +0 -0
  25. package/node_modules/lru-cache/README.md +166 -0
  26. package/node_modules/lru-cache/index.js +334 -0
  27. package/node_modules/lru-cache/node_modules/yallist/LICENSE +15 -0
  28. package/node_modules/lru-cache/node_modules/yallist/README.md +204 -0
  29. package/node_modules/lru-cache/node_modules/yallist/iterator.js +8 -0
  30. package/node_modules/lru-cache/node_modules/yallist/package.json +65 -0
  31. package/node_modules/lru-cache/node_modules/yallist/yallist.js +426 -0
  32. package/node_modules/lru-cache/package.json +75 -0
  33. package/node_modules/mimic-response/index.d.ts +2 -2
  34. package/node_modules/mimic-response/index.js +41 -2
  35. package/node_modules/mimic-response/package.json +17 -17
  36. package/node_modules/mimic-response/readme.md +22 -1
  37. package/node_modules/minimist/index.js +6 -2
  38. package/node_modules/minimist/package.json +10 -10
  39. package/node_modules/minimist/readme.markdown +4 -1
  40. package/node_modules/minimist/test/proto.js +16 -0
  41. package/node_modules/node-abi/.circleci/config.yml +63 -0
  42. package/node_modules/node-abi/.releaserc.json +9 -0
  43. package/node_modules/node-abi/abi_registry.json +45 -3
  44. package/node_modules/node-abi/index.js +5 -2
  45. package/node_modules/node-abi/node_modules/semver/CHANGELOG.md +111 -0
  46. package/node_modules/node-abi/node_modules/semver/LICENSE +15 -0
  47. package/node_modules/{semver → node-abi/node_modules/semver}/README.md +180 -26
  48. package/node_modules/node-abi/node_modules/semver/bin/semver.js +173 -0
  49. package/node_modules/node-abi/node_modules/semver/classes/comparator.js +135 -0
  50. package/node_modules/node-abi/node_modules/semver/classes/index.js +5 -0
  51. package/node_modules/node-abi/node_modules/semver/classes/range.js +510 -0
  52. package/node_modules/node-abi/node_modules/semver/classes/semver.js +287 -0
  53. package/node_modules/node-abi/node_modules/semver/functions/clean.js +6 -0
  54. package/node_modules/node-abi/node_modules/semver/functions/cmp.js +48 -0
  55. package/node_modules/node-abi/node_modules/semver/functions/coerce.js +51 -0
  56. package/node_modules/node-abi/node_modules/semver/functions/compare-build.js +7 -0
  57. package/node_modules/node-abi/node_modules/semver/functions/compare-loose.js +3 -0
  58. package/node_modules/node-abi/node_modules/semver/functions/compare.js +5 -0
  59. package/node_modules/node-abi/node_modules/semver/functions/diff.js +23 -0
  60. package/node_modules/node-abi/node_modules/semver/functions/eq.js +3 -0
  61. package/node_modules/node-abi/node_modules/semver/functions/gt.js +3 -0
  62. package/node_modules/node-abi/node_modules/semver/functions/gte.js +3 -0
  63. package/node_modules/node-abi/node_modules/semver/functions/inc.js +15 -0
  64. package/node_modules/node-abi/node_modules/semver/functions/lt.js +3 -0
  65. package/node_modules/node-abi/node_modules/semver/functions/lte.js +3 -0
  66. package/node_modules/node-abi/node_modules/semver/functions/major.js +3 -0
  67. package/node_modules/node-abi/node_modules/semver/functions/minor.js +3 -0
  68. package/node_modules/node-abi/node_modules/semver/functions/neq.js +3 -0
  69. package/node_modules/node-abi/node_modules/semver/functions/parse.js +33 -0
  70. package/node_modules/node-abi/node_modules/semver/functions/patch.js +3 -0
  71. package/node_modules/node-abi/node_modules/semver/functions/prerelease.js +6 -0
  72. package/node_modules/node-abi/node_modules/semver/functions/rcompare.js +3 -0
  73. package/node_modules/node-abi/node_modules/semver/functions/rsort.js +3 -0
  74. package/node_modules/node-abi/node_modules/semver/functions/satisfies.js +10 -0
  75. package/node_modules/node-abi/node_modules/semver/functions/sort.js +3 -0
  76. package/node_modules/node-abi/node_modules/semver/functions/valid.js +6 -0
  77. package/node_modules/node-abi/node_modules/semver/index.js +48 -0
  78. package/node_modules/node-abi/node_modules/semver/internal/constants.js +17 -0
  79. package/node_modules/node-abi/node_modules/semver/internal/debug.js +9 -0
  80. package/node_modules/node-abi/node_modules/semver/internal/identifiers.js +23 -0
  81. package/node_modules/node-abi/node_modules/semver/internal/parse-options.js +11 -0
  82. package/node_modules/node-abi/node_modules/semver/internal/re.js +182 -0
  83. package/node_modules/{semver → node-abi/node_modules/semver}/package.json +32 -23
  84. package/node_modules/node-abi/node_modules/semver/preload.js +2 -0
  85. package/node_modules/{semver → node-abi/node_modules/semver}/range.bnf +0 -0
  86. package/node_modules/node-abi/node_modules/semver/ranges/gtr.js +4 -0
  87. package/node_modules/node-abi/node_modules/semver/ranges/intersects.js +7 -0
  88. package/node_modules/node-abi/node_modules/semver/ranges/ltr.js +4 -0
  89. package/node_modules/node-abi/node_modules/semver/ranges/max-satisfying.js +25 -0
  90. package/node_modules/node-abi/node_modules/semver/ranges/min-satisfying.js +24 -0
  91. package/node_modules/node-abi/node_modules/semver/ranges/min-version.js +60 -0
  92. package/node_modules/node-abi/node_modules/semver/ranges/outside.js +80 -0
  93. package/node_modules/node-abi/node_modules/semver/ranges/simplify.js +44 -0
  94. package/node_modules/node-abi/node_modules/semver/ranges/subset.js +222 -0
  95. package/node_modules/node-abi/node_modules/semver/ranges/to-comparators.js +8 -0
  96. package/node_modules/node-abi/node_modules/semver/ranges/valid.js +11 -0
  97. package/node_modules/node-abi/package.json +21 -17
  98. package/node_modules/node-abi/test/index.js +7 -15
  99. package/node_modules/prebuild-install/CHANGELOG.md +24 -7
  100. package/node_modules/prebuild-install/README.md +24 -4
  101. package/node_modules/prebuild-install/asset.js +10 -10
  102. package/node_modules/prebuild-install/bin.js +13 -13
  103. package/node_modules/prebuild-install/download.js +22 -22
  104. package/node_modules/prebuild-install/log.js +4 -4
  105. package/node_modules/prebuild-install/package.json +18 -19
  106. package/node_modules/prebuild-install/proxy.js +10 -10
  107. package/node_modules/prebuild-install/rc.js +12 -12
  108. package/node_modules/prebuild-install/util.js +14 -14
  109. package/node_modules/simple-get/.github/dependabot.yml +15 -0
  110. package/node_modules/simple-get/.github/workflows/ci.yml +23 -0
  111. package/node_modules/simple-get/README.md +17 -3
  112. package/node_modules/simple-get/index.js +9 -0
  113. package/node_modules/simple-get/package.json +27 -13
  114. package/package.json +15 -6
  115. package/src/data-channel-wrapper.cpp +56 -22
  116. package/src/data-channel-wrapper.h +3 -0
  117. package/src/media-audio-wrapper.cpp +7 -7
  118. package/src/media-track-wrapper.cpp +40 -21
  119. package/src/media-track-wrapper.h +2 -0
  120. package/src/media-video-wrapper.cpp +5 -5
  121. package/src/peer-connection-wrapper.cpp +48 -27
  122. package/src/peer-connection-wrapper.h +2 -0
  123. package/test/connectivity.js +6 -6
  124. package/test/test.js +46 -1
  125. package/node_modules/detect-libc/.npmignore +0 -7
  126. package/node_modules/detect-libc/bin/detect-libc.js +0 -18
  127. package/node_modules/node-abi/.travis.yml +0 -17
  128. package/node_modules/semver/CHANGELOG.md +0 -39
  129. package/node_modules/semver/bin/semver +0 -160
  130. package/node_modules/semver/semver.js +0 -1483
@@ -22,6 +22,7 @@ Napi::Object TrackWrapper::Init(Napi::Env env, Napi::Object exports)
22
22
  {
23
23
  InstanceMethod("direction", &TrackWrapper::direction),
24
24
  InstanceMethod("mid", &TrackWrapper::mid),
25
+ InstanceMethod("type", &TrackWrapper::type),
25
26
  InstanceMethod("close", &TrackWrapper::close),
26
27
  InstanceMethod("sendMessage", &TrackWrapper::sendMessage),
27
28
  InstanceMethod("sendMessageBinary", &TrackWrapper::sendMessageBinary),
@@ -45,8 +46,26 @@ Napi::Object TrackWrapper::Init(Napi::Env env, Napi::Object exports)
45
46
 
46
47
  TrackWrapper::TrackWrapper(const Napi::CallbackInfo &info) : Napi::ObjectWrap<TrackWrapper>(info)
47
48
  {
48
- mTrackPtr = *(info[0].As<Napi::External<std::shared_ptr<rtc::Track>>>().Data());
49
+ mTrackPtr = *(info[0].As<Napi::External<std::shared_ptr<rtc::Track>>>().Data());
49
50
 
51
+ mTrackPtr->onClosed([&]()
52
+ {
53
+ if (mOnClosedCallback)
54
+ mOnClosedCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
55
+ // Check the peer connection is not closed
56
+ if(instances.find(this) == instances.end())
57
+ throw ThreadSafeCallback::CancelException();
58
+
59
+ cleanCbsAndEraseInstance();
60
+
61
+ // This will run in main thread and needs to construct the
62
+ // arguments for the call
63
+ args = {};
64
+ });
65
+ else {
66
+ cleanCbsAndEraseInstance();
67
+ } });
68
+
50
69
  instances.insert(this);
51
70
  }
52
71
 
@@ -57,19 +76,11 @@ TrackWrapper::~TrackWrapper()
57
76
 
58
77
  void TrackWrapper::doClose()
59
78
  {
60
- instances.erase(this);
61
-
62
79
  if (mTrackPtr)
63
80
  {
64
81
  try
65
82
  {
66
- mOnOpenCallback.reset();
67
- mOnClosedCallback.reset();
68
- mOnErrorCallback.reset();
69
- mOnMessageCallback.reset();
70
-
71
83
  mTrackPtr->close();
72
- mTrackPtr.reset();
73
84
  }
74
85
  catch (std::exception &ex)
75
86
  {
@@ -79,6 +90,17 @@ void TrackWrapper::doClose()
79
90
  }
80
91
  }
81
92
 
93
+ void TrackWrapper::cleanCbsAndEraseInstance()
94
+ {
95
+ mOnOpenCallback.reset();
96
+ mOnClosedCallback.reset();
97
+ mOnErrorCallback.reset();
98
+ mOnMessageCallback.reset();
99
+
100
+ instances.erase(this);
101
+ mTrackPtr.reset();
102
+ }
103
+
82
104
  void TrackWrapper::close(const Napi::CallbackInfo &info)
83
105
  {
84
106
  doClose();
@@ -96,6 +118,12 @@ Napi::Value TrackWrapper::mid(const Napi::CallbackInfo &info)
96
118
  return Napi::String::New(env, mTrackPtr->mid());
97
119
  }
98
120
 
121
+ Napi::Value TrackWrapper::type(const Napi::CallbackInfo &info)
122
+ {
123
+ Napi::Env env = info.Env();
124
+ return Napi::String::New(env, mTrackPtr->description().type());
125
+ }
126
+
99
127
  Napi::Value TrackWrapper::sendMessage(const Napi::CallbackInfo &info)
100
128
  {
101
129
  if (!mTrackPtr)
@@ -254,18 +282,7 @@ void TrackWrapper::onClosed(const Napi::CallbackInfo &info)
254
282
  // Callback
255
283
  mOnClosedCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
256
284
 
257
- mTrackPtr->onClosed([&]()
258
- {
259
- if (mOnClosedCallback)
260
- mOnClosedCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
261
- // Check the peer connection is not closed
262
- if(instances.find(this) == instances.end())
263
- throw ThreadSafeCallback::CancelException();
264
-
265
- // This will run in main thread and needs to construct the
266
- // arguments for the call
267
- args = {};
268
- }); });
285
+ // Object cb call moved to the constructor
269
286
  }
270
287
 
271
288
  void TrackWrapper::onError(const Napi::CallbackInfo &info)
@@ -323,6 +340,8 @@ void TrackWrapper::onMessage(const Napi::CallbackInfo &info)
323
340
  Napi::Object payload = Napi::Object::New(env);
324
341
  if (std::holds_alternative<std::string>(message))
325
342
  {
343
+ // Track will always send message as binary
344
+ // So this code is not needed actually
326
345
  args = {Napi::String::New(env, std::get<std::string>(message))};
327
346
  }
328
347
  else
@@ -23,6 +23,7 @@ public:
23
23
  // Functions
24
24
  Napi::Value direction(const Napi::CallbackInfo &info);
25
25
  Napi::Value mid(const Napi::CallbackInfo &info);
26
+ Napi::Value type(const Napi::CallbackInfo &info);
26
27
  void close(const Napi::CallbackInfo &info);
27
28
  Napi::Value sendMessage(const Napi::CallbackInfo &info);
28
29
  Napi::Value sendMessageBinary(const Napi::CallbackInfo &info);
@@ -45,6 +46,7 @@ private:
45
46
  static std::unordered_set<TrackWrapper *> instances;
46
47
 
47
48
  void doClose();
49
+ void cleanCbsAndEraseInstance();
48
50
 
49
51
  std::shared_ptr<rtc::Track> mTrackPtr = nullptr;
50
52
 
@@ -190,15 +190,15 @@ Napi::Value VideoWrapper::generateSdp(const Napi::CallbackInfo &info)
190
190
  Napi::Env env = info.Env();
191
191
  int length = info.Length();
192
192
 
193
- if (length < 3 || !info[0].IsString() || !info[1].IsString() || !info[2].IsString())
193
+ if (length < 3 || !info[0].IsString() || !info[1].IsString() || !info[2].IsNumber())
194
194
  {
195
- Napi::TypeError::New(env, "We expect (String, String, String) as param").ThrowAsJavaScriptException();
195
+ Napi::TypeError::New(env, "We expect (String, String, Number) as param").ThrowAsJavaScriptException();
196
196
  return Napi::String::New(env, "");
197
197
  }
198
198
 
199
199
  std::string eol = info[0].As<Napi::String>().ToString();
200
200
  std::string addr = info[1].As<Napi::String>().ToString();
201
- std::string port = info[2].As<Napi::String>().ToString();
201
+ uint16_t port = info[2].As<Napi::Number>().Uint32Value();
202
202
 
203
203
  return Napi::String::New(env, mVideoPtr->generateSdp(eol, addr, port));
204
204
  }
@@ -431,7 +431,7 @@ void VideoWrapper::setBitrate(const Napi::CallbackInfo &info)
431
431
  Napi::Value VideoWrapper::getBitrate(const Napi::CallbackInfo &info)
432
432
  {
433
433
 
434
- return Napi::Number::New(info.Env(), mVideoPtr->getBitrate());
434
+ return Napi::Number::New(info.Env(), mVideoPtr->bitrate());
435
435
  }
436
436
 
437
437
  Napi::Value VideoWrapper::hasPayloadType(const Napi::CallbackInfo &info)
@@ -465,7 +465,7 @@ void VideoWrapper::addRTXCodec(const Napi::CallbackInfo &info)
465
465
  unsigned int originalPayloadType = static_cast<unsigned int>(info[1].As<Napi::Number>().ToNumber());
466
466
  unsigned int clockRate = static_cast<unsigned int>(info[2].As<Napi::Number>().ToNumber());
467
467
 
468
- mVideoPtr->addRTXCodec(payloadType, originalPayloadType, clockRate);
468
+ mVideoPtr->addRtxCodec(payloadType, originalPayloadType, clockRate);
469
469
  }
470
470
 
471
471
  void VideoWrapper::addRTPMap(const Napi::CallbackInfo &info)
@@ -147,10 +147,6 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
147
147
  std::string strType = proxyServer.Get("type").As<Napi::String>().ToString();
148
148
  rtc::ProxyServer::Type type = rtc::ProxyServer::Type::Http;
149
149
 
150
- if (strType == "None")
151
- type = rtc::ProxyServer::Type::None;
152
- if (strType == "Http")
153
- type = rtc::ProxyServer::Type::Http;
154
150
  if (strType == "Socks5")
155
151
  type = rtc::ProxyServer::Type::Socks5;
156
152
 
@@ -176,6 +172,14 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
176
172
  if (config.Get("enableIceTcp").IsBoolean())
177
173
  rtcConfig.enableIceTcp = config.Get("enableIceTcp").As<Napi::Boolean>();
178
174
 
175
+ // enableIceUdpMux option
176
+ if (config.Get("enableIceUdpMux").IsBoolean())
177
+ rtcConfig.enableIceUdpMux = config.Get("enableIceUdpMux").As<Napi::Boolean>();
178
+
179
+ // disableAutoNegotiation option
180
+ if (config.Get("disableAutoNegotiation").IsBoolean())
181
+ rtcConfig.disableAutoNegotiation = config.Get("disableAutoNegotiation").As<Napi::Boolean>();
182
+
179
183
  // Max Message Size
180
184
  if (config.Get("maxMessageSize").IsNumber())
181
185
  rtcConfig.maxMessageSize = config.Get("maxMessageSize").As<Napi::Number>().Uint32Value();
@@ -211,6 +215,27 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
211
215
  return;
212
216
  }
213
217
 
218
+ mRtcPeerConnPtr->onStateChange([&](rtc::PeerConnection::State state) {
219
+ if (mOnStateChangeCallback)
220
+ mOnStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
221
+ // Check the peer connection is not closed
222
+ if(instances.find(this) == instances.end())
223
+ throw ThreadSafeCallback::CancelException();
224
+
225
+ if(mDoCloseFlag && state == rtc::PeerConnection::State::Closed)
226
+ cleanCbsAndEraseInstance();
227
+
228
+ // This will run in main thread and needs to construct the
229
+ // arguments for the call
230
+ std::ostringstream stream;
231
+ stream << state;
232
+ args = {Napi::String::New(env, stream.str())};
233
+ });
234
+ else {
235
+ if(mDoCloseFlag && state == rtc::PeerConnection::State::Closed)
236
+ cleanCbsAndEraseInstance();
237
+ } });
238
+
214
239
  instances.insert(this);
215
240
  }
216
241
 
@@ -221,20 +246,14 @@ PeerConnectionWrapper::~PeerConnectionWrapper()
221
246
 
222
247
  void PeerConnectionWrapper::doClose()
223
248
  {
224
- instances.erase(this);
225
-
226
- if (mRtcPeerConnPtr)
249
+ if (mRtcPeerConnPtr && !mDoCloseFlag)
227
250
  {
228
251
  try
229
252
  {
230
- mOnLocalDescriptionCallback.reset();
231
- mOnLocalCandidateCallback.reset();
232
- mOnStateChangeCallback.reset();
233
- mOnGatheringStateChangeCallback.reset();
234
- mOnDataChannelCallback.reset();
235
- mOnTrackCallback.reset();
236
-
253
+ mDoCloseFlag = true;
237
254
  mRtcPeerConnPtr->close();
255
+
256
+ // Resetting in cleanCbsAndEraseInstance causes a deadlock
238
257
  mRtcPeerConnPtr.reset();
239
258
  }
240
259
  catch (std::exception &ex)
@@ -245,6 +264,20 @@ void PeerConnectionWrapper::doClose()
245
264
  }
246
265
  }
247
266
 
267
+ void PeerConnectionWrapper::cleanCbsAndEraseInstance()
268
+ {
269
+ mOnLocalDescriptionCallback.reset();
270
+ mOnLocalCandidateCallback.reset();
271
+ mOnStateChangeCallback.reset();
272
+ mOnGatheringStateChangeCallback.reset();
273
+ mOnDataChannelCallback.reset();
274
+ mOnTrackCallback.reset();
275
+
276
+ instances.erase(this);
277
+
278
+ mDoCloseFlag = false;
279
+ }
280
+
248
281
  void PeerConnectionWrapper::close(const Napi::CallbackInfo &info)
249
282
  {
250
283
  doClose();
@@ -598,19 +631,7 @@ void PeerConnectionWrapper::onStateChange(const Napi::CallbackInfo &info)
598
631
  // Callback
599
632
  mOnStateChangeCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
600
633
 
601
- mRtcPeerConnPtr->onStateChange([&](rtc::PeerConnection::State state) {
602
- if (mOnStateChangeCallback)
603
- mOnStateChangeCallback->call([this, state](Napi::Env env, std::vector<napi_value> &args) {
604
- // Check the peer connection is not closed
605
- if(instances.find(this) == instances.end())
606
- throw ThreadSafeCallback::CancelException();
607
-
608
- // This will run in main thread and needs to construct the
609
- // arguments for the call
610
- std::ostringstream stream;
611
- stream << state;
612
- args = {Napi::String::New(env, stream.str())};
613
- }); });
634
+ // onState cb will be called from constructor
614
635
  }
615
636
 
616
637
  void PeerConnectionWrapper::onSignalingStateChange(const Napi::CallbackInfo &info)
@@ -55,6 +55,8 @@ private:
55
55
  static std::unordered_set<PeerConnectionWrapper *> instances;
56
56
 
57
57
  void doClose();
58
+ void cleanCbsAndEraseInstance();
59
+ bool mDoCloseFlag = false;
58
60
 
59
61
  std::string mPeerName;
60
62
  std::unique_ptr<rtc::PeerConnection> mRtcPeerConnPtr = nullptr;
@@ -66,6 +66,9 @@ peer2.onDataChannel((dc) => {
66
66
  console.log('Peer2 Received Msg:', msg);
67
67
  });
68
68
  dc2.sendMessage("Hello From Peer2");
69
+ dc2.onClosed(() => {
70
+ console.log('dc2 closed');
71
+ });
69
72
  });
70
73
 
71
74
  // DataChannel Options
@@ -85,17 +88,14 @@ dc1.onOpen(() => {
85
88
  dc1.onMessage((msg) => {
86
89
  console.log('Peer1 Received Msg:', msg);
87
90
  });
91
+ dc1.onClosed(() => {
92
+ console.log('dc1 closed');
93
+ });
88
94
 
89
95
  setTimeout(() => {
90
96
  dc1.close();
91
97
  dc2.close();
92
98
  peer1.close();
93
99
  peer2.close();
94
- dc1 = null;
95
- dc2 = null;
96
- peer1 = null;
97
- peer2 = null;
98
100
  nodeDataChannel.cleanup();
99
- // No need for this (>= V0.1.14)
100
- // process.exit();
101
101
  }, 5 * 1000);
package/test/test.js CHANGED
@@ -24,8 +24,11 @@ describe('PeerConnection Classes', () => {
24
24
 
25
25
  test('Create Data Channel', () => {
26
26
  let peer = new nodeDataChannel.PeerConnection("Peer", { iceServers: ["stun:stun.l.google.com:19302"] });
27
- let dc = peer.createDataChannel('test');
27
+ let dc = peer.createDataChannel('test', { protocol: 'test-protocol' });
28
28
  expect(dc).toBeDefined();
29
+ expect(dc.getId()).toBeDefined();
30
+ expect(dc.getProtocol()).toBe('test-protocol');
31
+ expect(dc.getLabel()).toBe('test');
29
32
  expect(dc.onOpen).toBeDefined();
30
33
  expect(dc.onMessage).toBeDefined();
31
34
 
@@ -145,4 +148,46 @@ describe('P2P', () => {
145
148
  }, 12 * 1000);
146
149
 
147
150
  });
151
+ });
152
+
153
+ function waitForGathering(peer) {
154
+ return new Promise((resolve) => {
155
+ peer.onGatheringStateChange((state) => {
156
+ if (state === 'complete') resolve();
157
+ });
158
+ // Handle race conditions where gathering has already completed
159
+ if (peer.gatheringState() === 'complete') resolve();
160
+ });
161
+ }
162
+
163
+ describe('DataChannel streams', () => {
164
+
165
+ test('can build an echo pipeline', async () => {
166
+ let clientPeer = new nodeDataChannel.PeerConnection("Client", { iceServers: [] });
167
+ let echoPeer = new nodeDataChannel.PeerConnection("Client", { iceServers: [] });
168
+
169
+ const echoStream = new nodeDataChannel.DataChannelStream(
170
+ echoPeer.createDataChannel("echo-channel")
171
+ );
172
+ echoStream.pipe(echoStream); // Echo all received data back to the client
173
+
174
+ await waitForGathering(echoPeer);
175
+
176
+ const { sdp: echoDescSdp, type: echoDescType } = echoPeer.localDescription();
177
+ clientPeer.setRemoteDescription(echoDescSdp, echoDescType);
178
+ await waitForGathering(clientPeer);
179
+
180
+ const { sdp: clientDescSdp, type: clientDescType } = clientPeer.localDescription();
181
+ echoPeer.setRemoteDescription(clientDescSdp, clientDescType);
182
+
183
+ const clientChannel = await new Promise((resolve) => clientPeer.onDataChannel(resolve));
184
+
185
+ const clientResponsePromise = new Promise((resolve) => clientChannel.onMessage(resolve));
186
+ clientChannel.sendMessage("test message");
187
+
188
+ expect(await clientResponsePromise).toBe("test message");
189
+
190
+ clientPeer.close();
191
+ echoPeer.close();
192
+ });
148
193
  });
@@ -1,7 +0,0 @@
1
- .nyc_output
2
- .travis.yml
3
- coverage
4
- test.js
5
- node_modules
6
- /.circleci
7
- /tests/integration
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict';
4
-
5
- var spawnSync = require('child_process').spawnSync;
6
- var libc = require('../');
7
-
8
- var spawnOptions = {
9
- env: process.env,
10
- shell: true,
11
- stdio: 'inherit'
12
- };
13
-
14
- if (libc.isNonGlibcLinux) {
15
- spawnOptions.env.LIBC = process.env.LIBC || libc.family;
16
- }
17
-
18
- process.exit(spawnSync(process.argv[2], process.argv.slice(3), spawnOptions).status);
@@ -1,17 +0,0 @@
1
- language: node_js
2
- cache:
3
- directories:
4
- - ~/.npm
5
- notifications:
6
- email: false
7
- node_js:
8
- - '14'
9
- - '12'
10
- - '10'
11
- - '9'
12
- - '8'
13
- after_success:
14
- - npm run travis-deploy-once "npm run semantic-release"
15
- branches:
16
- except:
17
- - /^v\d+\.\d+\.\d+$/
@@ -1,39 +0,0 @@
1
- # changes log
2
-
3
- ## 5.7
4
-
5
- * Add `minVersion` method
6
-
7
- ## 5.6
8
-
9
- * Move boolean `loose` param to an options object, with
10
- backwards-compatibility protection.
11
- * Add ability to opt out of special prerelease version handling with
12
- the `includePrerelease` option flag.
13
-
14
- ## 5.5
15
-
16
- * Add version coercion capabilities
17
-
18
- ## 5.4
19
-
20
- * Add intersection checking
21
-
22
- ## 5.3
23
-
24
- * Add `minSatisfying` method
25
-
26
- ## 5.2
27
-
28
- * Add `prerelease(v)` that returns prerelease components
29
-
30
- ## 5.1
31
-
32
- * Add Backus-Naur for ranges
33
- * Remove excessively cute inspection methods
34
-
35
- ## 5.0
36
-
37
- * Remove AMD/Browserified build artifacts
38
- * Fix ltr and gtr when using the `*` range
39
- * Fix for range `*` with a prerelease identifier
@@ -1,160 +0,0 @@
1
- #!/usr/bin/env node
2
- // Standalone semver comparison program.
3
- // Exits successfully and prints matching version(s) if
4
- // any supplied version is valid and passes all tests.
5
-
6
- var argv = process.argv.slice(2)
7
-
8
- var versions = []
9
-
10
- var range = []
11
-
12
- var inc = null
13
-
14
- var version = require('../package.json').version
15
-
16
- var loose = false
17
-
18
- var includePrerelease = false
19
-
20
- var coerce = false
21
-
22
- var identifier
23
-
24
- var semver = require('../semver')
25
-
26
- var reverse = false
27
-
28
- var options = {}
29
-
30
- main()
31
-
32
- function main () {
33
- if (!argv.length) return help()
34
- while (argv.length) {
35
- var a = argv.shift()
36
- var indexOfEqualSign = a.indexOf('=')
37
- if (indexOfEqualSign !== -1) {
38
- a = a.slice(0, indexOfEqualSign)
39
- argv.unshift(a.slice(indexOfEqualSign + 1))
40
- }
41
- switch (a) {
42
- case '-rv': case '-rev': case '--rev': case '--reverse':
43
- reverse = true
44
- break
45
- case '-l': case '--loose':
46
- loose = true
47
- break
48
- case '-p': case '--include-prerelease':
49
- includePrerelease = true
50
- break
51
- case '-v': case '--version':
52
- versions.push(argv.shift())
53
- break
54
- case '-i': case '--inc': case '--increment':
55
- switch (argv[0]) {
56
- case 'major': case 'minor': case 'patch': case 'prerelease':
57
- case 'premajor': case 'preminor': case 'prepatch':
58
- inc = argv.shift()
59
- break
60
- default:
61
- inc = 'patch'
62
- break
63
- }
64
- break
65
- case '--preid':
66
- identifier = argv.shift()
67
- break
68
- case '-r': case '--range':
69
- range.push(argv.shift())
70
- break
71
- case '-c': case '--coerce':
72
- coerce = true
73
- break
74
- case '-h': case '--help': case '-?':
75
- return help()
76
- default:
77
- versions.push(a)
78
- break
79
- }
80
- }
81
-
82
- var options = { loose: loose, includePrerelease: includePrerelease }
83
-
84
- versions = versions.map(function (v) {
85
- return coerce ? (semver.coerce(v) || { version: v }).version : v
86
- }).filter(function (v) {
87
- return semver.valid(v)
88
- })
89
- if (!versions.length) return fail()
90
- if (inc && (versions.length !== 1 || range.length)) { return failInc() }
91
-
92
- for (var i = 0, l = range.length; i < l; i++) {
93
- versions = versions.filter(function (v) {
94
- return semver.satisfies(v, range[i], options)
95
- })
96
- if (!versions.length) return fail()
97
- }
98
- return success(versions)
99
- }
100
-
101
- function failInc () {
102
- console.error('--inc can only be used on a single version with no range')
103
- fail()
104
- }
105
-
106
- function fail () { process.exit(1) }
107
-
108
- function success () {
109
- var compare = reverse ? 'rcompare' : 'compare'
110
- versions.sort(function (a, b) {
111
- return semver[compare](a, b, options)
112
- }).map(function (v) {
113
- return semver.clean(v, options)
114
- }).map(function (v) {
115
- return inc ? semver.inc(v, inc, options, identifier) : v
116
- }).forEach(function (v, i, _) { console.log(v) })
117
- }
118
-
119
- function help () {
120
- console.log(['SemVer ' + version,
121
- '',
122
- 'A JavaScript implementation of the https://semver.org/ specification',
123
- 'Copyright Isaac Z. Schlueter',
124
- '',
125
- 'Usage: semver [options] <version> [<version> [...]]',
126
- 'Prints valid versions sorted by SemVer precedence',
127
- '',
128
- 'Options:',
129
- '-r --range <range>',
130
- ' Print versions that match the specified range.',
131
- '',
132
- '-i --increment [<level>]',
133
- ' Increment a version by the specified level. Level can',
134
- ' be one of: major, minor, patch, premajor, preminor,',
135
- " prepatch, or prerelease. Default level is 'patch'.",
136
- ' Only one version may be specified.',
137
- '',
138
- '--preid <identifier>',
139
- ' Identifier to be used to prefix premajor, preminor,',
140
- ' prepatch or prerelease version increments.',
141
- '',
142
- '-l --loose',
143
- ' Interpret versions and ranges loosely',
144
- '',
145
- '-p --include-prerelease',
146
- ' Always include prerelease versions in range matching',
147
- '',
148
- '-c --coerce',
149
- ' Coerce a string into SemVer if possible',
150
- ' (does not imply --loose)',
151
- '',
152
- 'Program exits successfully if any valid version satisfies',
153
- 'all supplied ranges, and prints all satisfying versions.',
154
- '',
155
- 'If no satisfying versions are found, then exits failure.',
156
- '',
157
- 'Versions are printed in ascending order, so supplying',
158
- 'multiple versions to the utility will just sort them.'
159
- ].join('\n'))
160
- }