node-datachannel 0.3.2 → 0.3.5
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/.github/workflows/build-linux-arm64-test.yml +39 -0
- package/.github/workflows/build-linux.yml +4 -4
- package/.github/workflows/build-mac-m1.yml +41 -0
- package/.github/workflows/build-mac.yml +2 -2
- package/.github/workflows/build-win.yml +3 -3
- package/.github/workflows/lint.yml +0 -3
- package/API.md +214 -0
- package/BULDING.md +19 -0
- package/CMakeLists.txt +4 -3
- package/README.md +31 -250
- package/lib/index.d.ts +9 -5
- package/package.json +1 -1
- package/src/peer-connection-wrapper.cpp +14 -5
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Build - Linux-Arm64
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
tags:
|
|
7
|
+
- v*
|
|
8
|
+
|
|
9
|
+
env:
|
|
10
|
+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build-linux-arm64:
|
|
14
|
+
runs-on: ubuntu-20.04
|
|
15
|
+
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
node-version: [12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v2
|
|
21
|
+
- name: Prepare Cross Compile
|
|
22
|
+
run: |
|
|
23
|
+
sudo apt update
|
|
24
|
+
sudo apt install -y g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
|
|
25
|
+
mkdir sysroot && cd sysroot
|
|
26
|
+
wget https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/953c2471bc7e71a788309f6c2d2003e8b703305d/debian_sid_arm64_sysroot.tar.xz
|
|
27
|
+
tar xf debian_sid_arm64_sysroot.tar.xz
|
|
28
|
+
echo "ARM64_SYSROOT=$(pwd)" >> $GITHUB_ENV
|
|
29
|
+
ls -l
|
|
30
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
31
|
+
uses: actions/setup-node@v1
|
|
32
|
+
with:
|
|
33
|
+
node-version: ${{ matrix.node-version }}
|
|
34
|
+
- name: Build & Upload
|
|
35
|
+
run: |
|
|
36
|
+
npm install --ignore-scripts
|
|
37
|
+
node_modules/.bin/prebuild --backend cmake-js --arch arm64 --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/arm64.cmake
|
|
38
|
+
env:
|
|
39
|
+
CI: true
|
|
@@ -2,7 +2,7 @@ name: Build - Linux
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
workflow_dispatch:
|
|
5
|
-
|
|
5
|
+
push:
|
|
6
6
|
tags:
|
|
7
7
|
- v*
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ jobs:
|
|
|
14
14
|
runs-on: ubuntu-20.04
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
17
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
20
|
- uses: actions/checkout@v2
|
|
@@ -40,7 +40,7 @@ jobs:
|
|
|
40
40
|
|
|
41
41
|
strategy:
|
|
42
42
|
matrix:
|
|
43
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
43
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x]
|
|
44
44
|
steps:
|
|
45
45
|
- uses: actions/checkout@v2
|
|
46
46
|
- name: Prepare Cross Compile
|
|
@@ -68,7 +68,7 @@ jobs:
|
|
|
68
68
|
|
|
69
69
|
strategy:
|
|
70
70
|
matrix:
|
|
71
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
71
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x]
|
|
72
72
|
steps:
|
|
73
73
|
- uses: actions/checkout@v2
|
|
74
74
|
- name: Prepare Cross Compile
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Build - Mac M1
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
tags:
|
|
7
|
+
- v*
|
|
8
|
+
|
|
9
|
+
env:
|
|
10
|
+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build-macos:
|
|
14
|
+
runs-on: macos-11
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
node-version: [ 16.x]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v2
|
|
21
|
+
- name: Install OpenSSL
|
|
22
|
+
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew reinstall openssl@1.1
|
|
23
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
24
|
+
uses: actions/setup-node@v1
|
|
25
|
+
with:
|
|
26
|
+
node-version: ${{ matrix.node-version }}
|
|
27
|
+
architecture: x64
|
|
28
|
+
- name: Build
|
|
29
|
+
run: npm install --build-from-source
|
|
30
|
+
env:
|
|
31
|
+
CI: true
|
|
32
|
+
OPENSSL_ROOT_DIR: /usr/local/opt/openssl
|
|
33
|
+
OPENSSL_LIBRARIES: /usr/local/opt/openssl/lib
|
|
34
|
+
- name: Test
|
|
35
|
+
run: npm run test
|
|
36
|
+
env:
|
|
37
|
+
CI: true
|
|
38
|
+
- name: Upload
|
|
39
|
+
run: node_modules/.bin/prebuild --upload -u ${{ secrets.GITHUB_TOKEN }}
|
|
40
|
+
env:
|
|
41
|
+
CI: true
|
|
@@ -2,7 +2,7 @@ name: Build - Mac
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
workflow_dispatch:
|
|
5
|
-
|
|
5
|
+
push:
|
|
6
6
|
tags:
|
|
7
7
|
- v*
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ jobs:
|
|
|
14
14
|
runs-on: macos-latest
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
17
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
20
|
- uses: actions/checkout@v2
|
|
@@ -2,7 +2,7 @@ name: Build - Win
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
workflow_dispatch:
|
|
5
|
-
|
|
5
|
+
push:
|
|
6
6
|
tags:
|
|
7
7
|
- v*
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ jobs:
|
|
|
14
14
|
runs-on: windows-2019
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
17
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
20
|
- uses: actions/checkout@v2
|
|
@@ -42,7 +42,7 @@ jobs:
|
|
|
42
42
|
runs-on: windows-2019
|
|
43
43
|
strategy:
|
|
44
44
|
matrix:
|
|
45
|
-
node_version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
45
|
+
node_version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x]
|
|
46
46
|
node_arch:
|
|
47
47
|
- x86
|
|
48
48
|
steps:
|
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.
|
|
3
|
+
project(node_datachannel VERSION 0.3.5)
|
|
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.
|
|
36
|
+
GIT_TAG "v0.17.9"
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
|
|
@@ -81,7 +81,8 @@ set(LINK_LIBRARIES
|
|
|
81
81
|
)
|
|
82
82
|
|
|
83
83
|
if(APPLE)
|
|
84
|
-
|
|
84
|
+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64 -arch arm64 ")
|
|
85
|
+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_LINK_FLAGS} -arch x86_64 -arch arm64 ")
|
|
85
86
|
elseif(UNIX)
|
|
86
87
|
list(APPEND LINK_LIBRARIES -static-libgcc -static-libstdc++)
|
|
87
88
|
endif()
|
package/README.md
CHANGED
|
@@ -6,17 +6,36 @@
|
|
|
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(1) | 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
|
+
|
|
34
|
+
1) Please note that; For arm64 platform we need OpenSSL to be installed locally.
|
|
35
|
+
|
|
36
|
+
|
|
19
37
|
## Example Usage
|
|
38
|
+
|
|
20
39
|
```js
|
|
21
40
|
const nodeDataChannel = require('node-datachannel');
|
|
22
41
|
|
|
@@ -77,264 +96,26 @@ setTimeout(() => {
|
|
|
77
96
|
}, 10 * 1000);
|
|
78
97
|
```
|
|
79
98
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
## Install
|
|
83
|
-
|
|
84
|
-
Prebuilt binaries are available (Node Version >= 10);
|
|
85
|
-
* Windows (x86, x64)
|
|
86
|
-
* Linux (x64, armv7, arm64)
|
|
87
|
-
* Mac
|
|
88
|
-
|
|
99
|
+
## Test
|
|
89
100
|
```sh
|
|
90
|
-
|
|
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
|
|
101
|
+
npm run test # Unit tests
|
|
102
|
+
node test/connectivity.js # Connectivity
|
|
241
103
|
```
|
|
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
|
-
|
|
270
|
-
**isOpen: () => boolean**
|
|
271
104
|
|
|
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
105
|
|
|
306
106
|
## Build
|
|
307
107
|
|
|
308
|
-
|
|
309
|
-
* cmake >= V3.14
|
|
310
|
-
* [libdatachannel dependencies](https://github.com/paullouisageneau/libdatachannel/blob/master/README.md#dependencies)
|
|
311
|
-
|
|
312
|
-
### Building from source
|
|
313
|
-
|
|
314
|
-
```sh
|
|
315
|
-
> git clone https://github.com/murat-dogan/node-datachannel.git
|
|
316
|
-
> cd node-datachannel
|
|
317
|
-
> npm i
|
|
318
|
-
```
|
|
108
|
+
Please check [here](/BULDING.md)
|
|
319
109
|
|
|
320
|
-
|
|
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
|
-
```
|
|
110
|
+
## Examples
|
|
325
111
|
|
|
326
|
-
|
|
327
|
-
```sh
|
|
328
|
-
> npm run test # Unit tests
|
|
329
|
-
> node test/connectivity.js # Connectivity
|
|
330
|
-
```
|
|
112
|
+
Please check [examples](/examples/) folder
|
|
331
113
|
|
|
332
|
-
|
|
114
|
+
## API Docs
|
|
333
115
|
|
|
334
|
-
|
|
116
|
+
Please check [docs](/API.md) page
|
|
335
117
|
|
|
336
118
|
## Thanks
|
|
337
119
|
|
|
338
|
-
|
|
339
120
|
Thanks to [Streamr](https://streamr.network/) for supporting this project by being a Sponsor!
|
|
340
121
|
|
package/lib/index.d.ts
CHANGED
|
@@ -50,18 +50,22 @@ export interface RtcConfig {
|
|
|
50
50
|
iceServers: (string | IceServer)[];
|
|
51
51
|
proxyServer?: ProxyServer;
|
|
52
52
|
enableIceTcp?: boolean;
|
|
53
|
+
enableIceUdpMux?: boolean;
|
|
54
|
+
disableAutoNegotiation?: boolean;
|
|
53
55
|
portRangeBegin?: number;
|
|
54
56
|
portRangeEnd?: number;
|
|
55
57
|
maxMessageSize?: number;
|
|
58
|
+
mtu?: number;
|
|
56
59
|
iceTransportPolicy?: TransportPolicy;
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
// Lowercase to match the description type string from libdatachannel
|
|
59
63
|
export const enum DescriptionType {
|
|
60
|
-
Unspec = '
|
|
61
|
-
Offer = '
|
|
62
|
-
Answer = '
|
|
63
|
-
Pranswer = '
|
|
64
|
-
Rollback = '
|
|
64
|
+
Unspec = 'unspec',
|
|
65
|
+
Offer = 'offer',
|
|
66
|
+
Answer = 'answer',
|
|
67
|
+
Pranswer = 'pranswer',
|
|
68
|
+
Rollback = 'rollback',
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
export const enum ReliabilityType {
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include "media-video-wrapper.h"
|
|
5
5
|
#include "media-audio-wrapper.h"
|
|
6
6
|
|
|
7
|
+
#include <cctype>
|
|
7
8
|
#include <sstream>
|
|
8
9
|
|
|
9
10
|
Napi::FunctionReference PeerConnectionWrapper::constructor;
|
|
@@ -182,7 +183,11 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
|
|
|
182
183
|
|
|
183
184
|
// Max Message Size
|
|
184
185
|
if (config.Get("maxMessageSize").IsNumber())
|
|
185
|
-
rtcConfig.maxMessageSize = config.Get("maxMessageSize").As<Napi::Number>().
|
|
186
|
+
rtcConfig.maxMessageSize = config.Get("maxMessageSize").As<Napi::Number>().Int32Value();
|
|
187
|
+
|
|
188
|
+
// MTU
|
|
189
|
+
if (config.Get("mtu").IsNumber())
|
|
190
|
+
rtcConfig.mtu = config.Get("mtu").As<Napi::Number>().Int32Value();
|
|
186
191
|
|
|
187
192
|
// ICE transport policy
|
|
188
193
|
if (!config.Get("iceTransportPolicy").IsUndefined())
|
|
@@ -277,13 +282,17 @@ void PeerConnectionWrapper::setLocalDescription(const Napi::CallbackInfo &info)
|
|
|
277
282
|
}
|
|
278
283
|
std::string typeStr = info[0].As<Napi::String>().ToString();
|
|
279
284
|
|
|
280
|
-
|
|
285
|
+
// Accept uppercase first letter for backward compatibility
|
|
286
|
+
if(typeStr.size() > 0)
|
|
287
|
+
typeStr[0] = std::tolower(typeStr[0]);
|
|
288
|
+
|
|
289
|
+
if (typeStr == "answer")
|
|
281
290
|
type = rtc::Description::Type::Answer;
|
|
282
|
-
if (typeStr == "
|
|
291
|
+
else if (typeStr == "offer")
|
|
283
292
|
type = rtc::Description::Type::Offer;
|
|
284
|
-
if (typeStr == "
|
|
293
|
+
else if (typeStr == "pranswer")
|
|
285
294
|
type = rtc::Description::Type::Pranswer;
|
|
286
|
-
if (typeStr == "
|
|
295
|
+
else if (typeStr == "rollback")
|
|
287
296
|
type = rtc::Description::Type::Rollback;
|
|
288
297
|
}
|
|
289
298
|
|