node-datachannel 0.3.1 → 0.3.4

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 (56) hide show
  1. package/.github/workflows/build-linux.yml +1 -1
  2. package/.github/workflows/build-mac.yml +1 -1
  3. package/.github/workflows/build-win.yml +1 -1
  4. package/.github/workflows/lint.yml +19 -0
  5. package/API.md +214 -0
  6. package/BULDING.md +19 -0
  7. package/CMakeLists.txt +2 -2
  8. package/README.md +28 -250
  9. package/examples/client-server/client-benchmark.js +43 -32
  10. package/examples/client-server/client-periodic.js +30 -14
  11. package/examples/client-server/client.js +6 -5
  12. package/examples/client-server/package-lock.json +183 -44
  13. package/examples/client-server/signaling-server.js +3 -5
  14. package/examples/media/media.js +9 -9
  15. package/lib/index.d.ts +101 -100
  16. package/node_modules/lru-cache/package.json +2 -4
  17. package/node_modules/minimist/package.json +0 -1
  18. package/node_modules/node-abi/node_modules/semver/README.md +3 -1
  19. package/node_modules/node-abi/node_modules/semver/bin/semver.js +19 -9
  20. package/node_modules/node-abi/node_modules/semver/classes/comparator.js +3 -2
  21. package/node_modules/node-abi/node_modules/semver/classes/index.js +1 -1
  22. package/node_modules/node-abi/node_modules/semver/classes/range.js +31 -22
  23. package/node_modules/node-abi/node_modules/semver/classes/semver.js +1 -1
  24. package/node_modules/node-abi/node_modules/semver/functions/cmp.js +8 -4
  25. package/node_modules/node-abi/node_modules/semver/functions/coerce.js +3 -2
  26. package/node_modules/node-abi/node_modules/semver/functions/inc.js +4 -1
  27. package/node_modules/node-abi/node_modules/semver/functions/parse.js +1 -1
  28. package/node_modules/node-abi/node_modules/semver/internal/constants.js +2 -2
  29. package/node_modules/node-abi/node_modules/semver/internal/identifiers.js +1 -1
  30. package/node_modules/node-abi/node_modules/semver/internal/parse-options.js +3 -3
  31. package/node_modules/node-abi/node_modules/semver/internal/re.js +3 -3
  32. package/node_modules/node-abi/node_modules/semver/package.json +51 -18
  33. package/node_modules/node-abi/node_modules/semver/ranges/min-version.js +2 -1
  34. package/node_modules/node-abi/node_modules/semver/ranges/outside.js +1 -1
  35. package/node_modules/node-abi/node_modules/semver/ranges/simplify.js +15 -12
  36. package/node_modules/node-abi/node_modules/semver/ranges/subset.js +53 -31
  37. package/node_modules/npmlog/node_modules/are-we-there-yet/package.json +10 -10
  38. package/node_modules/npmlog/package.json +1 -1
  39. package/node_modules/tar-stream/node_modules/bl/.travis.yml +4 -3
  40. package/node_modules/tar-stream/node_modules/bl/BufferList.js +1 -1
  41. package/node_modules/tar-stream/node_modules/bl/package.json +10 -10
  42. package/node_modules/tar-stream/node_modules/bl/test/test.js +20 -2
  43. package/node_modules/wide-align/LICENSE +0 -0
  44. package/node_modules/wide-align/README.md +0 -0
  45. package/node_modules/wide-align/align.js +0 -0
  46. package/node_modules/wide-align/package.json +14 -14
  47. package/package.json +2 -2
  48. package/src/data-channel-wrapper.cpp +69 -53
  49. package/src/data-channel-wrapper.h +0 -1
  50. package/src/media-track-wrapper.cpp +91 -52
  51. package/src/media-track-wrapper.h +0 -1
  52. package/src/peer-connection-wrapper.cpp +111 -71
  53. package/src/peer-connection-wrapper.h +0 -2
  54. package/test/connectivity.js +18 -17
  55. package/test/test.js +22 -30
  56. package/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -111
@@ -2,7 +2,7 @@ name: Build - Linux
2
2
 
3
3
  on:
4
4
  workflow_dispatch:
5
- create:
5
+ push:
6
6
  tags:
7
7
  - v*
8
8
 
@@ -2,7 +2,7 @@ name: Build - Mac
2
2
 
3
3
  on:
4
4
  workflow_dispatch:
5
- create:
5
+ push:
6
6
  tags:
7
7
  - v*
8
8
 
@@ -2,7 +2,7 @@ name: Build - Win
2
2
 
3
3
  on:
4
4
  workflow_dispatch:
5
- create:
5
+ push:
6
6
  tags:
7
7
  - v*
8
8
 
@@ -0,0 +1,19 @@
1
+ name: Lint
2
+
3
+ on:
4
+ pull_request:
5
+ workflow_dispatch:
6
+
7
+ jobs:
8
+ build:
9
+
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ - name: Use Node.js
15
+ uses: actions/setup-node@v3
16
+ with:
17
+ node-version: '16.x'
18
+ - run: npm ci
19
+ - run: npm run lint
package/API.md ADDED
@@ -0,0 +1,214 @@
1
+ # API
2
+
3
+ ## PeerConnection Class
4
+
5
+ **Constructor**
6
+
7
+ let pc = new PeerConnection(peerName[,options])
8
+ - peerName `<string>` Peer name to use for logs etc..
9
+ - options `<Object>` WebRTC Config Options
10
+ ```
11
+ export interface RtcConfig {
12
+ iceServers: (string | IceServer)[];
13
+ proxyServer?: ProxyServer;
14
+ enableIceTcp?: boolean;
15
+ enableIceUdpMux?: boolean;
16
+ portRangeBegin?: number;
17
+ portRangeEnd?: number;
18
+ maxMessageSize?: number;
19
+ mtu?: number;
20
+ iceTransportPolicy?: TransportPolicy;
21
+ }
22
+
23
+ export const enum RelayType {
24
+ TurnUdp = 'TurnUdp',
25
+ TurnTcp = 'TurnTcp',
26
+ TurnTls = 'TurnTls'
27
+ }
28
+
29
+ export interface IceServer {
30
+ hostname: string;
31
+ port: number;
32
+ username?: string;
33
+ password?: string;
34
+ relayType?: RelayType;
35
+ }
36
+
37
+ export type TransportPolicy = 'all' | 'relay';
38
+
39
+ "iceServers" option is an array of stun/turn server urls
40
+ Examples;
41
+ STUN Server Example : stun:stun.l.google.com:19302
42
+ TURN Server Example : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
43
+ TURN Server Example (TCP) : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT?transport=tcp
44
+ TURN Server Example (TLS) : turns:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
45
+
46
+ ```
47
+
48
+ **close: () => void**
49
+
50
+ Close Peer Connection
51
+
52
+ **setRemoteDescription: (sdp: string, type: DescriptionType) => void**
53
+
54
+ Set Remote Description
55
+ ```
56
+ export const enum DescriptionType {
57
+ Unspec = 'Unspec',
58
+ Offer = 'Offer',
59
+ Answer = 'Answer'
60
+ }
61
+ ```
62
+
63
+ **addRemoteCandidate: (candidate: string, mid: string) => void**
64
+
65
+ Add remote candidate info
66
+
67
+ **createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel**
68
+
69
+ Create new data-channel
70
+ * label `<string>` Data channel name
71
+ * config `<Object>` Data channel options
72
+ ```
73
+ export interface DataChannelInitConfig {
74
+ protocol?: string;
75
+ negotiated?: boolean;
76
+ id?: number;
77
+ ordered?: boolean;
78
+ maxPacketLifeTime?: number;
79
+ maxRetransmits?: number;
80
+
81
+ // Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
82
+ reliability?: {
83
+ type?: ReliabilityType;
84
+ unordered?: boolean;
85
+ rexmit?: number;
86
+ }
87
+ }
88
+
89
+ export const enum ReliabilityType {
90
+ Reliable = 0, Rexmit = 1, Timed = 2
91
+ }
92
+ ```
93
+ **state: () => string**
94
+
95
+ Get current state
96
+
97
+ **signalingState: () => string**
98
+
99
+ Get current signaling state
100
+
101
+ **gatheringState: () => string**
102
+
103
+ Get current gathering state
104
+
105
+ **onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void**
106
+
107
+ Local Description Callback
108
+ ```
109
+ export const enum DescriptionType {
110
+ Unspec = 'Unspec',
111
+ Offer = 'Offer',
112
+ Answer = 'Answer'
113
+ }
114
+ ```
115
+
116
+ **onLocalCandidate: (cb: (candidate: string, mid: string) => void) => void**
117
+
118
+ Local Candidate Callback
119
+
120
+ **onStateChange: (cb: (state: string) => void) => void**
121
+
122
+ State Change Callback
123
+
124
+ **onSignalingStateChange: (state: (sdp: string) => void) => void**
125
+
126
+ Signaling State Change Callback
127
+
128
+ **onGatheringStateChange: (state: (sdp: string) => void) => void**
129
+
130
+ Gathering State Change Callback
131
+
132
+ **onDataChannel: (cb: (dc: DataChannel) => void) => void**
133
+
134
+ New Data Channel Callback
135
+
136
+ **bytesSent: () => number**
137
+
138
+ Get bytes sent stat
139
+
140
+ **bytesReceived: () => number**
141
+
142
+ Get bytes received stat
143
+
144
+ **rtt: () => number**
145
+
146
+ Get rtt stat
147
+
148
+ **getSelectedCandidatePair: () => { local: SelectedCandidateInfo, remote: SelectedCandidateInfo }**
149
+
150
+ Get info about selected candidate pair
151
+ ```
152
+ export interface SelectedCandidateInfo {
153
+ address: string;
154
+ port: number;
155
+ type: string;
156
+ transportType: string;
157
+ }
158
+ ```
159
+
160
+ ## DataChannel Class
161
+
162
+ > You can create a new Datachannel instance by calling `PeerConnection.createDataChannel` function.
163
+
164
+ **close: () => void**
165
+
166
+ Close data channel
167
+
168
+ **getLabel: () => string**
169
+
170
+ Get label of data-channel
171
+
172
+ **sendMessage: (msg: string) => boolean**
173
+
174
+ Send Message as string
175
+
176
+ **sendMessageBinary: (buffer: Buffer) => boolean**
177
+
178
+ Send Message as binary
179
+
180
+ **isOpen: () => boolean**
181
+
182
+ Query data-channel
183
+
184
+ **bufferedAmount: () => number**
185
+
186
+ Get current buffered amount level
187
+
188
+ **maxMessageSize: () => number**
189
+
190
+ Get max message size of the data-channel, that could be sent
191
+
192
+ **setBufferedAmountLowThreshold: (newSize: number) => void**
193
+
194
+ Set buffer level of the `onBufferedAmountLow` callback
195
+
196
+ **onOpen: (cb: () => void) => void**
197
+
198
+ Open callback
199
+
200
+ **onClosed: (cb: () => void) => void**
201
+
202
+ Closed callback
203
+
204
+ **onError: (cb: (err: string) => void) => void**
205
+
206
+ Error callback
207
+
208
+ **onBufferedAmountLow: (cb: () => void) => void**
209
+
210
+ Buffer level low callback
211
+
212
+ **onMessage: (cb: (msg: string | Buffer) => void) => void**
213
+
214
+ New Message callback
package/BULDING.md ADDED
@@ -0,0 +1,19 @@
1
+ # Build
2
+
3
+ ## Requirements
4
+ * cmake >= V3.14
5
+ * [libdatachannel dependencies](https://github.com/paullouisageneau/libdatachannel/blob/master/README.md#dependencies)
6
+
7
+ ## Building from source
8
+
9
+ ```sh
10
+ > git clone https://github.com/murat-dogan/node-datachannel.git
11
+ > cd node-datachannel
12
+ > npm i
13
+ ```
14
+
15
+ Other Options
16
+ ```sh
17
+ > npm run install -- -DUSE_GNUTLS=1 # Use GnuTLS instead of OpenSSL (Default False)
18
+ > npm run install -- -DUSE_NICE=1 # Use libnice instead of libjuice (Default False)
19
+ ```
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.1)
3
+ project(node_datachannel VERSION 0.3.4)
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")
@@ -33,7 +33,7 @@ include(FetchContent)
33
33
  FetchContent_Declare(
34
34
  libdatachannel
35
35
  GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
36
- GIT_TAG "v0.17.1"
36
+ GIT_TAG "v0.17.7"
37
37
  )
38
38
 
39
39
  option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
package/README.md CHANGED
@@ -6,17 +6,33 @@
6
6
  - Lightweight
7
7
  - No need to deal with WebRTC stack!
8
8
  - Small binary sizes
9
- - Has Prebuilt binaries (Linux,Windows,ARM)
10
9
  - Type infos for Typescript
11
10
 
12
- > "libdatachannel is a standalone implementation of WebRTC Data Channels, WebRTC Media Transport, and WebSockets in C++17 with C bindings for POSIX platforms (including GNU/Linux, Android, and Apple macOS) and Microsoft Windows. It enables direct connectivity between native applications and web browsers without the pain of importing the entire WebRTC stack. "
13
-
14
-
15
11
  This project is NodeJS bindings for [libdatachannel](https://github.com/paullouisageneau/libdatachannel) library.
16
12
 
17
13
  Please check [libdatachannel](https://github.com/paullouisageneau/libdatachannel) for Compatibility & WebRTC details.
18
14
 
15
+ ## Install
16
+
17
+ ```sh
18
+ npm install node-datachannel
19
+ ```
20
+
21
+ ## Supported Platforms
22
+
23
+ | | Linux-x64 | Linux-armv7 | Linux-arm64 | 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
+
19
34
  ## Example Usage
35
+
20
36
  ```js
21
37
  const nodeDataChannel = require('node-datachannel');
22
38
 
@@ -77,264 +93,26 @@ setTimeout(() => {
77
93
  }, 10 * 1000);
78
94
  ```
79
95
 
80
- > Please check examples/media folder for media usage example
81
-
82
- ## Install
83
-
84
- Prebuilt binaries are available (Node Version >= 10);
85
- * Windows (x86, x64)
86
- * Linux (x64, armv7, arm64)
87
- * Mac
88
-
96
+ ## Test
89
97
  ```sh
90
- > npm install node-datachannel --save
91
- ```
92
-
93
- ## API
94
-
95
- ### PeerConnection Class
96
-
97
- **Constructor**
98
-
99
- let pc = new PeerConnection(peerName[,options])
100
- - peerName `<string>` Peer name to use for logs etc..
101
- - options `<Object>` WebRTC Config Options
102
- ```
103
- export interface RtcConfig {
104
- iceServers: (string | IceServer)[];
105
- proxyServer?: ProxyServer;
106
- enableIceTcp?: boolean;
107
- portRangeBegin?: number;
108
- portRangeEnd?: number;
109
- maxMessageSize?: number;
110
- iceTransportPolicy?: TransportPolicy;
111
- }
112
-
113
- export const enum RelayType {
114
- TurnUdp = 'TurnUdp',
115
- TurnTcp = 'TurnTcp',
116
- TurnTls = 'TurnTls'
117
- }
118
-
119
- export interface IceServer {
120
- hostname: string;
121
- port: number;
122
- username?: string;
123
- password?: string;
124
- relayType?: RelayType;
125
- }
126
-
127
- export type TransportPolicy = 'all' | 'relay';
128
-
129
- "iceServers" option is an array of stun/turn server urls
130
- Examples;
131
- STUN Server Example : stun:stun.l.google.com:19302
132
- TURN Server Example : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
133
- TURN Server Example (TCP) : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT?transport=tcp
134
- TURN Server Example (TLS) : turns:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
135
-
136
- ```
137
-
138
- **close: () => void**
139
-
140
- Close Peer Connection
141
-
142
- **setRemoteDescription: (sdp: string, type: DescriptionType) => void**
143
-
144
- Set Remote Description
145
- ```
146
- export const enum DescriptionType {
147
- Unspec = 'Unspec',
148
- Offer = 'Offer',
149
- Answer = 'Answer'
150
- }
151
- ```
152
-
153
- **addRemoteCandidate: (candidate: string, mid: string) => void**
154
-
155
- Add remote candidate info
156
-
157
- **createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel**
158
-
159
- Create new data-channel
160
- * label `<string>` Data channel name
161
- * config `<Object>` Data channel options
162
- ```
163
- export interface DataChannelInitConfig {
164
- protocol?: string;
165
- negotiated?: boolean;
166
- id?: number;
167
- ordered?: boolean;
168
- maxPacketLifeTime?: number;
169
- maxRetransmits?: number;
170
-
171
- // Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
172
- reliability?: {
173
- type?: ReliabilityType;
174
- unordered?: boolean;
175
- rexmit?: number;
176
- }
177
- }
178
-
179
- export const enum ReliabilityType {
180
- Reliable = 0, Rexmit = 1, Timed = 2
181
- }
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
194
-
195
- **onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void**
196
-
197
- Local Description Callback
198
- ```
199
- export const enum DescriptionType {
200
- Unspec = 'Unspec',
201
- Offer = 'Offer',
202
- Answer = 'Answer'
203
- }
204
- ```
205
-
206
- **onLocalCandidate: (cb: (candidate: string, mid: string) => void) => void**
207
-
208
- Local Candidate Callback
209
-
210
- **onStateChange: (cb: (state: string) => void) => void**
211
-
212
- State Change Callback
213
-
214
- **onSignalingStateChange: (state: (sdp: string) => void) => void**
215
-
216
- Signaling State Change Callback
217
-
218
- **onGatheringStateChange: (state: (sdp: string) => void) => void**
219
-
220
- Gathering State Change Callback
221
-
222
- **onDataChannel: (cb: (dc: DataChannel) => void) => void**
223
-
224
- New Data Channel Callback
225
-
226
- **bytesSent: () => number**
227
-
228
- Get bytes sent stat
229
-
230
- **bytesReceived: () => number**
231
-
232
- Get bytes received stat
233
-
234
- **rtt: () => number**
235
-
236
- Get rtt stat
237
-
238
- **getSelectedCandidatePair: () => { local: SelectedCandidateInfo, remote: SelectedCandidateInfo }**
239
-
240
- Get info about selected candidate pair
98
+ npm run test # Unit tests
99
+ node test/connectivity.js # Connectivity
241
100
  ```
242
- export interface SelectedCandidateInfo {
243
- address: string;
244
- port: number;
245
- type: string;
246
- transportType: string;
247
- }
248
- ```
249
-
250
- ### DataChannel Class
251
-
252
- > You can create a new Datachannel instance by calling `PeerConnection.createDataChannel` function.
253
-
254
- **close: () => void**
255
-
256
- Close data channel
257
-
258
- **getLabel: () => string**
259
-
260
- Get label of data-channel
261
-
262
- **sendMessage: (msg: string) => boolean**
263
-
264
- Send Message as string
265
-
266
- **sendMessageBinary: (buffer: Buffer) => boolean**
267
-
268
- Send Message as binary
269
101
 
270
- **isOpen: () => boolean**
271
-
272
- Query data-channel
273
-
274
- **bufferedAmount: () => number**
275
-
276
- Get current buffered amount level
277
-
278
- **maxMessageSize: () => number**
279
-
280
- Get max message size of the data-channel, that could be sent
281
-
282
- **setBufferedAmountLowThreshold: (newSize: number) => void**
283
-
284
- Set buffer level of the `onBufferedAmountLow` callback
285
-
286
- **onOpen: (cb: () => void) => void**
287
-
288
- Open callback
289
-
290
- **onClosed: (cb: () => void) => void**
291
-
292
- Closed callback
293
-
294
- **onError: (cb: (err: string) => void) => void**
295
-
296
- Error callback
297
-
298
- **onBufferedAmountLow: (cb: () => void) => void**
299
-
300
- Buffer level low callback
301
-
302
- **onMessage: (cb: (msg: string | Buffer) => void) => void**
303
-
304
- New Message callback
305
102
 
306
103
  ## Build
307
104
 
308
- ### Requirements
309
- * cmake >= V3.14
310
- * [libdatachannel dependencies](https://github.com/paullouisageneau/libdatachannel/blob/master/README.md#dependencies)
105
+ Please check [here](/BULDING.md)
311
106
 
312
- ### Building from source
107
+ ## Examples
313
108
 
314
- ```sh
315
- > git clone https://github.com/murat-dogan/node-datachannel.git
316
- > cd node-datachannel
317
- > npm i
318
- ```
109
+ Please check [examples](/examples/) folder
319
110
 
320
- Other Options
321
- ```sh
322
- > npm run install -- -DUSE_GNUTLS=1 # Use GnuTLS instead of OpenSSL (Default False)
323
- > npm run install -- -DUSE_NICE=1 # Use libnice instead of libjuice (Default False)
324
- ```
325
-
326
- ### Test
327
- ```sh
328
- > npm run test # Unit tests
329
- > node test/connectivity.js # Connectivity
330
- ```
331
-
332
- ### More Examples
111
+ ## API Docs
333
112
 
334
- Check `examples` folder
113
+ Please check [docs](/API.md) page
335
114
 
336
115
  ## Thanks
337
116
 
338
-
339
117
  Thanks to [Streamr](https://streamr.network/) for supporting this project by being a Sponsor!
340
118