node-datachannel 0.3.3 → 0.3.6
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 +36 -0
- package/.github/workflows/build-linux.yml +3 -3
- package/.github/workflows/build-mac-m1.yml +37 -0
- package/.github/workflows/{build-mac.yml → build-mac-x64.yml} +2 -2
- package/.github/workflows/build-win.yml +2 -2
- package/API.md +214 -0
- package/BULDING.md +19 -0
- package/CMakeLists.txt +15 -10
- package/README.md +31 -252
- package/lib/index.d.ts +8 -5
- package/package.json +1 -1
- package/src/peer-connection-wrapper.cpp +9 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Build - Linux-Arm64
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
env:
|
|
7
|
+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build-linux-arm64:
|
|
11
|
+
runs-on: ubuntu-20.04
|
|
12
|
+
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
node-version: [12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v2
|
|
18
|
+
- name: Prepare Cross Compile
|
|
19
|
+
run: |
|
|
20
|
+
sudo apt update
|
|
21
|
+
sudo apt install -y g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
|
|
22
|
+
mkdir sysroot && cd sysroot
|
|
23
|
+
wget https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/953c2471bc7e71a788309f6c2d2003e8b703305d/debian_sid_arm64_sysroot.tar.xz
|
|
24
|
+
tar xf debian_sid_arm64_sysroot.tar.xz
|
|
25
|
+
echo "ARM64_SYSROOT=$(pwd)" >> $GITHUB_ENV
|
|
26
|
+
ls -l
|
|
27
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
28
|
+
uses: actions/setup-node@v1
|
|
29
|
+
with:
|
|
30
|
+
node-version: ${{ matrix.node-version }}
|
|
31
|
+
- name: Build & Upload
|
|
32
|
+
run: |
|
|
33
|
+
npm install --ignore-scripts
|
|
34
|
+
node_modules/.bin/prebuild --backend cmake-js --arch arm64 --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/arm64.cmake
|
|
35
|
+
env:
|
|
36
|
+
CI: true
|
|
@@ -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,37 @@
|
|
|
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-latest
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v3
|
|
21
|
+
- name: Install OpenSSL
|
|
22
|
+
run: |
|
|
23
|
+
wget https://mac.r-project.org/bin/darwin20/arm64/openssl-1.1.1o-darwin.20-arm64.tar.xz
|
|
24
|
+
tar -xf openssl-1.1.1o-darwin.20-arm64.tar.xz -C /tmp
|
|
25
|
+
rm -rf openssl-1.1.1o-darwin.20-arm64.tar.xz
|
|
26
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
27
|
+
uses: actions/setup-node@v3
|
|
28
|
+
with:
|
|
29
|
+
node-version: ${{ matrix.node-version }}
|
|
30
|
+
- name: Build
|
|
31
|
+
run: |
|
|
32
|
+
npm install --ignore-scripts
|
|
33
|
+
node_modules/.bin/prebuild --backend cmake-js --arch arm64 --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_OSX_ARCHITECTURES="arm64"
|
|
34
|
+
env:
|
|
35
|
+
CI: true
|
|
36
|
+
OPENSSL_ROOT_DIR: /tmp/opt/R/arm64
|
|
37
|
+
OPENSSL_LIBRARIES: /tmp/opt/R/arm64/lib
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
name: Build - Mac
|
|
1
|
+
name: Build - Mac x64
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
workflow_dispatch:
|
|
@@ -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
|
|
@@ -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.6)
|
|
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")
|
|
@@ -17,13 +17,18 @@ if(WIN32)
|
|
|
17
17
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
18
18
|
endif()
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
if(APPLE)
|
|
21
|
+
set(OPENSSL_USE_STATIC_LIBS TRUE)
|
|
22
|
+
find_package(OpenSSL REQUIRED)
|
|
23
|
+
elseif(UNIX)
|
|
24
|
+
# Got linker error for arm64
|
|
25
|
+
# /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
|
|
26
|
+
# ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): in function `sha1_block_armv8':
|
|
27
|
+
# (.text+0x1240): dangerous relocation: unsupported relocation
|
|
28
|
+
if(NOT ${NODE_ARCH} STREQUAL "arm64")
|
|
29
|
+
set(OPENSSL_USE_STATIC_LIBS TRUE)
|
|
30
|
+
find_package(OpenSSL REQUIRED)
|
|
31
|
+
endif()
|
|
27
32
|
endif()
|
|
28
33
|
|
|
29
34
|
|
|
@@ -33,7 +38,7 @@ include(FetchContent)
|
|
|
33
38
|
FetchContent_Declare(
|
|
34
39
|
libdatachannel
|
|
35
40
|
GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
|
|
36
|
-
GIT_TAG "v0.17.
|
|
41
|
+
GIT_TAG "v0.17.9"
|
|
37
42
|
)
|
|
38
43
|
|
|
39
44
|
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
|
|
@@ -81,7 +86,7 @@ set(LINK_LIBRARIES
|
|
|
81
86
|
)
|
|
82
87
|
|
|
83
88
|
if(APPLE)
|
|
84
|
-
|
|
89
|
+
#
|
|
85
90
|
elseif(UNIX)
|
|
86
91
|
list(APPEND LINK_LIBRARIES -static-libgcc -static-libstdc++)
|
|
87
92
|
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 (M1 + x64) |
|
|
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 Linux-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,266 +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
|
-
enableIceUdpMux?: boolean;
|
|
108
|
-
portRangeBegin?: number;
|
|
109
|
-
portRangeEnd?: number;
|
|
110
|
-
maxMessageSize?: number;
|
|
111
|
-
mtu?: number;
|
|
112
|
-
iceTransportPolicy?: TransportPolicy;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export const enum RelayType {
|
|
116
|
-
TurnUdp = 'TurnUdp',
|
|
117
|
-
TurnTcp = 'TurnTcp',
|
|
118
|
-
TurnTls = 'TurnTls'
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface IceServer {
|
|
122
|
-
hostname: string;
|
|
123
|
-
port: number;
|
|
124
|
-
username?: string;
|
|
125
|
-
password?: string;
|
|
126
|
-
relayType?: RelayType;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export type TransportPolicy = 'all' | 'relay';
|
|
130
|
-
|
|
131
|
-
"iceServers" option is an array of stun/turn server urls
|
|
132
|
-
Examples;
|
|
133
|
-
STUN Server Example : stun:stun.l.google.com:19302
|
|
134
|
-
TURN Server Example : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
|
|
135
|
-
TURN Server Example (TCP) : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT?transport=tcp
|
|
136
|
-
TURN Server Example (TLS) : turns:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
**close: () => void**
|
|
141
|
-
|
|
142
|
-
Close Peer Connection
|
|
143
|
-
|
|
144
|
-
**setRemoteDescription: (sdp: string, type: DescriptionType) => void**
|
|
145
|
-
|
|
146
|
-
Set Remote Description
|
|
147
|
-
```
|
|
148
|
-
export const enum DescriptionType {
|
|
149
|
-
Unspec = 'Unspec',
|
|
150
|
-
Offer = 'Offer',
|
|
151
|
-
Answer = 'Answer'
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
**addRemoteCandidate: (candidate: string, mid: string) => void**
|
|
156
|
-
|
|
157
|
-
Add remote candidate info
|
|
158
|
-
|
|
159
|
-
**createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel**
|
|
160
|
-
|
|
161
|
-
Create new data-channel
|
|
162
|
-
* label `<string>` Data channel name
|
|
163
|
-
* config `<Object>` Data channel options
|
|
164
|
-
```
|
|
165
|
-
export interface DataChannelInitConfig {
|
|
166
|
-
protocol?: string;
|
|
167
|
-
negotiated?: boolean;
|
|
168
|
-
id?: number;
|
|
169
|
-
ordered?: boolean;
|
|
170
|
-
maxPacketLifeTime?: number;
|
|
171
|
-
maxRetransmits?: number;
|
|
172
|
-
|
|
173
|
-
// Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
|
|
174
|
-
reliability?: {
|
|
175
|
-
type?: ReliabilityType;
|
|
176
|
-
unordered?: boolean;
|
|
177
|
-
rexmit?: number;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export const enum ReliabilityType {
|
|
182
|
-
Reliable = 0, Rexmit = 1, Timed = 2
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
**state: () => string**
|
|
186
|
-
|
|
187
|
-
Get current state
|
|
188
|
-
|
|
189
|
-
**signalingState: () => string**
|
|
190
|
-
|
|
191
|
-
Get current signaling state
|
|
192
|
-
|
|
193
|
-
**gatheringState: () => string**
|
|
194
|
-
|
|
195
|
-
Get current gathering state
|
|
196
|
-
|
|
197
|
-
**onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void**
|
|
198
|
-
|
|
199
|
-
Local Description Callback
|
|
200
|
-
```
|
|
201
|
-
export const enum DescriptionType {
|
|
202
|
-
Unspec = 'Unspec',
|
|
203
|
-
Offer = 'Offer',
|
|
204
|
-
Answer = 'Answer'
|
|
205
|
-
}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
**onLocalCandidate: (cb: (candidate: string, mid: string) => void) => void**
|
|
209
|
-
|
|
210
|
-
Local Candidate Callback
|
|
211
|
-
|
|
212
|
-
**onStateChange: (cb: (state: string) => void) => void**
|
|
213
|
-
|
|
214
|
-
State Change Callback
|
|
215
|
-
|
|
216
|
-
**onSignalingStateChange: (state: (sdp: string) => void) => void**
|
|
217
|
-
|
|
218
|
-
Signaling State Change Callback
|
|
219
|
-
|
|
220
|
-
**onGatheringStateChange: (state: (sdp: string) => void) => void**
|
|
221
|
-
|
|
222
|
-
Gathering State Change Callback
|
|
223
|
-
|
|
224
|
-
**onDataChannel: (cb: (dc: DataChannel) => void) => void**
|
|
225
|
-
|
|
226
|
-
New Data Channel Callback
|
|
227
|
-
|
|
228
|
-
**bytesSent: () => number**
|
|
229
|
-
|
|
230
|
-
Get bytes sent stat
|
|
231
|
-
|
|
232
|
-
**bytesReceived: () => number**
|
|
233
|
-
|
|
234
|
-
Get bytes received stat
|
|
235
|
-
|
|
236
|
-
**rtt: () => number**
|
|
237
|
-
|
|
238
|
-
Get rtt stat
|
|
239
|
-
|
|
240
|
-
**getSelectedCandidatePair: () => { local: SelectedCandidateInfo, remote: SelectedCandidateInfo }**
|
|
241
|
-
|
|
242
|
-
Get info about selected candidate pair
|
|
101
|
+
npm run test # Unit tests
|
|
102
|
+
node test/connectivity.js # Connectivity
|
|
243
103
|
```
|
|
244
|
-
export interface SelectedCandidateInfo {
|
|
245
|
-
address: string;
|
|
246
|
-
port: number;
|
|
247
|
-
type: string;
|
|
248
|
-
transportType: string;
|
|
249
|
-
}
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
### DataChannel Class
|
|
253
|
-
|
|
254
|
-
> You can create a new Datachannel instance by calling `PeerConnection.createDataChannel` function.
|
|
255
|
-
|
|
256
|
-
**close: () => void**
|
|
257
|
-
|
|
258
|
-
Close data channel
|
|
259
|
-
|
|
260
|
-
**getLabel: () => string**
|
|
261
|
-
|
|
262
|
-
Get label of data-channel
|
|
263
|
-
|
|
264
|
-
**sendMessage: (msg: string) => boolean**
|
|
265
|
-
|
|
266
|
-
Send Message as string
|
|
267
|
-
|
|
268
|
-
**sendMessageBinary: (buffer: Buffer) => boolean**
|
|
269
|
-
|
|
270
|
-
Send Message as binary
|
|
271
|
-
|
|
272
|
-
**isOpen: () => boolean**
|
|
273
104
|
|
|
274
|
-
Query data-channel
|
|
275
|
-
|
|
276
|
-
**bufferedAmount: () => number**
|
|
277
|
-
|
|
278
|
-
Get current buffered amount level
|
|
279
|
-
|
|
280
|
-
**maxMessageSize: () => number**
|
|
281
|
-
|
|
282
|
-
Get max message size of the data-channel, that could be sent
|
|
283
|
-
|
|
284
|
-
**setBufferedAmountLowThreshold: (newSize: number) => void**
|
|
285
|
-
|
|
286
|
-
Set buffer level of the `onBufferedAmountLow` callback
|
|
287
|
-
|
|
288
|
-
**onOpen: (cb: () => void) => void**
|
|
289
|
-
|
|
290
|
-
Open callback
|
|
291
|
-
|
|
292
|
-
**onClosed: (cb: () => void) => void**
|
|
293
|
-
|
|
294
|
-
Closed callback
|
|
295
|
-
|
|
296
|
-
**onError: (cb: (err: string) => void) => void**
|
|
297
|
-
|
|
298
|
-
Error callback
|
|
299
|
-
|
|
300
|
-
**onBufferedAmountLow: (cb: () => void) => void**
|
|
301
|
-
|
|
302
|
-
Buffer level low callback
|
|
303
|
-
|
|
304
|
-
**onMessage: (cb: (msg: string | Buffer) => void) => void**
|
|
305
|
-
|
|
306
|
-
New Message callback
|
|
307
105
|
|
|
308
106
|
## Build
|
|
309
107
|
|
|
310
|
-
|
|
311
|
-
* cmake >= V3.14
|
|
312
|
-
* [libdatachannel dependencies](https://github.com/paullouisageneau/libdatachannel/blob/master/README.md#dependencies)
|
|
313
|
-
|
|
314
|
-
### Building from source
|
|
315
|
-
|
|
316
|
-
```sh
|
|
317
|
-
> git clone https://github.com/murat-dogan/node-datachannel.git
|
|
318
|
-
> cd node-datachannel
|
|
319
|
-
> npm i
|
|
320
|
-
```
|
|
108
|
+
Please check [here](/BULDING.md)
|
|
321
109
|
|
|
322
|
-
|
|
323
|
-
```sh
|
|
324
|
-
> npm run install -- -DUSE_GNUTLS=1 # Use GnuTLS instead of OpenSSL (Default False)
|
|
325
|
-
> npm run install -- -DUSE_NICE=1 # Use libnice instead of libjuice (Default False)
|
|
326
|
-
```
|
|
110
|
+
## Examples
|
|
327
111
|
|
|
328
|
-
|
|
329
|
-
```sh
|
|
330
|
-
> npm run test # Unit tests
|
|
331
|
-
> node test/connectivity.js # Connectivity
|
|
332
|
-
```
|
|
112
|
+
Please check [examples](/examples/) folder
|
|
333
113
|
|
|
334
|
-
|
|
114
|
+
## API Docs
|
|
335
115
|
|
|
336
|
-
|
|
116
|
+
Please check [docs](/API.md) page
|
|
337
117
|
|
|
338
118
|
## Thanks
|
|
339
119
|
|
|
340
|
-
|
|
341
120
|
Thanks to [Streamr](https://streamr.network/) for supporting this project by being a Sponsor!
|
|
342
121
|
|
package/lib/index.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ 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;
|
|
@@ -57,12 +59,13 @@ export interface RtcConfig {
|
|
|
57
59
|
iceTransportPolicy?: TransportPolicy;
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
// Lowercase to match the description type string from libdatachannel
|
|
60
63
|
export const enum DescriptionType {
|
|
61
|
-
Unspec = '
|
|
62
|
-
Offer = '
|
|
63
|
-
Answer = '
|
|
64
|
-
Pranswer = '
|
|
65
|
-
Rollback = '
|
|
64
|
+
Unspec = 'unspec',
|
|
65
|
+
Offer = 'offer',
|
|
66
|
+
Answer = 'answer',
|
|
67
|
+
Pranswer = 'pranswer',
|
|
68
|
+
Rollback = 'rollback',
|
|
66
69
|
}
|
|
67
70
|
|
|
68
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;
|
|
@@ -281,13 +282,17 @@ void PeerConnectionWrapper::setLocalDescription(const Napi::CallbackInfo &info)
|
|
|
281
282
|
}
|
|
282
283
|
std::string typeStr = info[0].As<Napi::String>().ToString();
|
|
283
284
|
|
|
284
|
-
|
|
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")
|
|
285
290
|
type = rtc::Description::Type::Answer;
|
|
286
|
-
if (typeStr == "
|
|
291
|
+
else if (typeStr == "offer")
|
|
287
292
|
type = rtc::Description::Type::Offer;
|
|
288
|
-
if (typeStr == "
|
|
293
|
+
else if (typeStr == "pranswer")
|
|
289
294
|
type = rtc::Description::Type::Pranswer;
|
|
290
|
-
if (typeStr == "
|
|
295
|
+
else if (typeStr == "rollback")
|
|
291
296
|
type = rtc::Description::Type::Rollback;
|
|
292
297
|
}
|
|
293
298
|
|