node-datachannel 0.9.2 → 0.10.1
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.yml +75 -82
- package/.github/workflows/build-mac-m1.yml +7 -6
- package/.github/workflows/build-mac-x64.yml +5 -5
- package/API.md +17 -20
- package/CMakeLists.txt +2 -2
- package/README.md +20 -36
- package/build-containers/Dockerfile.alpine +6 -0
- package/build-containers/Dockerfile.debian +7 -0
- package/cmake/toolchain/ci.cmake +23 -0
- package/examples/client-server/package-lock.json +6 -6
- package/lib/index.d.cts +4 -18
- package/lib/index.d.ts +4 -18
- package/package.json +1 -1
- package/polyfill/README.md +0 -4
- package/src/media-rtcpreceivingsession-wrapper.cpp +1 -23
- package/src/media-rtcpreceivingsession-wrapper.h +2 -5
- package/src/peer-connection-wrapper.cpp +6 -70
- package/cmake/toolchain/arm64.cmake +0 -17
- package/cmake/toolchain/armv7.cmake +0 -17
|
@@ -14,98 +14,91 @@ jobs:
|
|
|
14
14
|
runs-on: ubuntu-20.04
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [
|
|
17
|
+
node-version: [16]
|
|
18
|
+
arch: [amd64, arm64, arm]
|
|
19
|
+
platform: [debian, alpine]
|
|
20
|
+
include:
|
|
21
|
+
# Set baselines per platform
|
|
22
|
+
- triple: "alpine-linux-musl"
|
|
23
|
+
platform: alpine
|
|
24
|
+
version: 3.16
|
|
25
|
+
libc: musl
|
|
26
|
+
gcc_install: clang lld
|
|
27
|
+
gcc: clang
|
|
28
|
+
# libc is intentionally not set here, as prebuild-install requires libc to not be set for glibc builds
|
|
29
|
+
- triple: "linux-gnu"
|
|
30
|
+
platform: debian
|
|
31
|
+
version: bullseye
|
|
32
|
+
# Set baselines per architecture
|
|
33
|
+
- triple_arch: x86_64
|
|
34
|
+
node_arch: x64
|
|
35
|
+
arch: amd64
|
|
36
|
+
- triple_arch: armv7
|
|
37
|
+
node_arch: arm
|
|
38
|
+
triple_postfix: eabihf
|
|
39
|
+
arch: arm
|
|
40
|
+
flags: -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -fPIC
|
|
41
|
+
- triple_arch: aarch64
|
|
42
|
+
node_arch: arm64
|
|
43
|
+
arch: arm64
|
|
44
|
+
flags: -march=armv8-a -fPIC
|
|
45
|
+
# Set edge case overrides for specific platform + architecture
|
|
46
|
+
# also define gcc commands for each architecture
|
|
47
|
+
- arch: amd64
|
|
48
|
+
platform: debian
|
|
49
|
+
gcc_install: gcc g++
|
|
50
|
+
gcc: gcc
|
|
51
|
+
- arch: arm64
|
|
52
|
+
platform: debian
|
|
53
|
+
gcc_install: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
|
|
54
|
+
gcc: aarch64-linux-gnu-gcc
|
|
55
|
+
# debian uses the triple `arm-linux-gnueabihf` instead of alpine's `armv7-alpine-linux-musleabihf`
|
|
56
|
+
# because of this, we explicitly override triple_arch for debian arm
|
|
57
|
+
- triple_arch: arm
|
|
58
|
+
arch: arm
|
|
59
|
+
platform: debian
|
|
60
|
+
gcc_install: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
|
|
61
|
+
gcc: arm-linux-gnueabihf-gcc
|
|
18
62
|
|
|
19
63
|
steps:
|
|
20
|
-
- uses: actions/checkout@
|
|
64
|
+
- uses: actions/checkout@v4
|
|
21
65
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
22
|
-
uses: actions/setup-node@
|
|
66
|
+
uses: actions/setup-node@v4
|
|
23
67
|
with:
|
|
24
68
|
node-version: ${{ matrix.node-version }}
|
|
25
|
-
- name:
|
|
26
|
-
run: npm install --
|
|
69
|
+
- name: Install node dependencies
|
|
70
|
+
run: npm install --ignore-scripts
|
|
27
71
|
env:
|
|
28
72
|
CI: true
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
CI: true
|
|
33
|
-
- name: Upload
|
|
34
|
-
run: node_modules/.bin/prebuild -r napi --upload -u ${{ secrets.GITHUB_TOKEN }}
|
|
35
|
-
env:
|
|
36
|
-
CI: true
|
|
37
|
-
|
|
38
|
-
build-linux-armv7:
|
|
39
|
-
runs-on: ubuntu-20.04
|
|
40
|
-
|
|
41
|
-
strategy:
|
|
42
|
-
matrix:
|
|
43
|
-
node-version: [16.x]
|
|
44
|
-
steps:
|
|
45
|
-
- uses: actions/checkout@v2
|
|
46
|
-
- name: Prepare Cross Compile
|
|
47
|
-
run: |
|
|
48
|
-
sudo apt update
|
|
49
|
-
sudo apt install -y g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf
|
|
50
|
-
mkdir sysroot && cd sysroot
|
|
51
|
-
wget https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/ef5c4f84bcafb7a3796d36bb1db7826317dde51c/debian_sid_arm_sysroot.tar.xz
|
|
52
|
-
tar xf debian_sid_arm_sysroot.tar.xz
|
|
53
|
-
echo "ARM_SYSROOT=$(pwd)" >> $GITHUB_ENV
|
|
54
|
-
ls -l
|
|
55
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
56
|
-
uses: actions/setup-node@v1
|
|
73
|
+
- if: matrix.arch != 'amd64'
|
|
74
|
+
name: Set up QEMU
|
|
75
|
+
uses: docker/setup-qemu-action@v3
|
|
57
76
|
with:
|
|
58
|
-
|
|
59
|
-
- name:
|
|
77
|
+
platforms: ${{ matrix.arch }}
|
|
78
|
+
- name: Install system dependencies
|
|
60
79
|
run: |
|
|
61
|
-
|
|
62
|
-
|
|
80
|
+
sudo apt update
|
|
81
|
+
sudo apt install -y podman ninja-build ${{ matrix.gcc_install }}
|
|
82
|
+
- name: List installed libc
|
|
83
|
+
run: apt list --installed | grep libc6-dev
|
|
84
|
+
- name: Build sysroot
|
|
85
|
+
run: sudo podman build --isolation=chroot -t ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }} ./build-containers --file Dockerfile.${{ matrix.platform }} --platform linux/${{ matrix.arch }} --build-arg="version=${{ matrix.version }}" --build-arg="node_version=${{ matrix.node-version }}"
|
|
86
|
+
- name: Mount sysroot
|
|
87
|
+
id: sysroot
|
|
88
|
+
run: echo "sysroot=$(sudo podman image mount ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }})" >> $GITHUB_OUTPUT
|
|
89
|
+
- name: Build
|
|
90
|
+
run: sudo --preserve-env=SYSROOT,TRIPLE,COMPILER_FLAGS,LIBC,GCC,CI,PATH node_modules/.bin/prebuild --arch ${{ matrix.node_arch }} -r napi --backend cmake-js -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/ci.cmake
|
|
63
91
|
env:
|
|
92
|
+
SYSROOT: ${{ steps.sysroot.outputs.sysroot }}
|
|
93
|
+
TRIPLE: ${{ matrix.triple_arch }}-${{ matrix.triple }}${{ matrix.triple_postfix }}
|
|
94
|
+
COMPILER_FLAGS: ${{ matrix.flags }}
|
|
95
|
+
LIBC: ${{ matrix.libc }}
|
|
96
|
+
GCC: ${{ matrix.gcc }}
|
|
64
97
|
CI: true
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
strategy:
|
|
70
|
-
matrix:
|
|
71
|
-
node-version: [16.x]
|
|
72
|
-
steps:
|
|
73
|
-
- uses: actions/checkout@v2
|
|
74
|
-
- name: Prepare Cross Compile
|
|
75
|
-
run: |
|
|
76
|
-
sudo apt update
|
|
77
|
-
sudo apt install -y g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
|
|
78
|
-
mkdir sysroot && cd sysroot
|
|
79
|
-
wget https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/41a6c8dec4c4304d6509e30cbaf9218dffb4438e/debian_bullseye_arm64_sysroot.tar.xz
|
|
80
|
-
tar xf debian_bullseye_arm64_sysroot.tar.xz
|
|
81
|
-
echo "ARM64_SYSROOT=$(pwd)" >> $GITHUB_ENV
|
|
82
|
-
ls -l
|
|
83
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
84
|
-
uses: actions/setup-node@v1
|
|
85
|
-
with:
|
|
86
|
-
node-version: ${{ matrix.node-version }}
|
|
87
|
-
- name: Build & Upload
|
|
88
|
-
run: |
|
|
89
|
-
npm install --ignore-scripts
|
|
90
|
-
node_modules/.bin/prebuild -r napi --backend cmake-js --arch arm64 --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/arm64.cmake
|
|
98
|
+
- name: Test
|
|
99
|
+
run: sudo podman run --rm -v $(pwd):/usr/app/ -e CI=true --platform linux/${{ matrix.arch }} -t ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }} npm run test
|
|
100
|
+
- name: Upload
|
|
101
|
+
run: sudo --preserve-env=CI,LIBC node_modules/.bin/prebuild --arch ${{ matrix.node_arch }} -r napi --upload -u ${{ secrets.GITHUB_TOKEN }}
|
|
91
102
|
env:
|
|
103
|
+
LIBC: ${{ matrix.libc }}
|
|
92
104
|
CI: true
|
|
93
|
-
|
|
94
|
-
# npm-publish:
|
|
95
|
-
# needs: [build-linux, build-linux-armv7, build-linux-arm64]
|
|
96
|
-
# name: npm-publish
|
|
97
|
-
# runs-on: ubuntu-latest
|
|
98
|
-
# steps:
|
|
99
|
-
# - name: Checkout repository
|
|
100
|
-
# uses: actions/checkout@v2
|
|
101
|
-
# - name: Set up Node.js
|
|
102
|
-
# uses: actions/setup-node@v1
|
|
103
|
-
# with:
|
|
104
|
-
# node-version: 16.x
|
|
105
|
-
# registry-url: "https://registry.npmjs.org"
|
|
106
|
-
# - name: Publish
|
|
107
|
-
# run: |
|
|
108
|
-
# npm install
|
|
109
|
-
# npm publish
|
|
110
|
-
# env:
|
|
111
|
-
# NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
|
|
@@ -6,25 +6,26 @@ on:
|
|
|
6
6
|
# tags:
|
|
7
7
|
# - v*
|
|
8
8
|
|
|
9
|
+
|
|
9
10
|
env:
|
|
10
11
|
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
|
11
12
|
|
|
12
13
|
jobs:
|
|
13
14
|
build-macos:
|
|
14
|
-
runs-on: macos-
|
|
15
|
+
runs-on: macos-13
|
|
15
16
|
strategy:
|
|
16
17
|
matrix:
|
|
17
18
|
node-version: [16.x]
|
|
18
19
|
|
|
19
20
|
steps:
|
|
20
|
-
- uses: actions/checkout@
|
|
21
|
+
- uses: actions/checkout@v4
|
|
21
22
|
- name: Install OpenSSL
|
|
22
23
|
run: |
|
|
23
|
-
wget https://mac.r-project.org/bin/darwin20/arm64/openssl-1.1.
|
|
24
|
-
tar -xf openssl-1.1.
|
|
25
|
-
rm -rf openssl-1.1.
|
|
24
|
+
wget https://mac.r-project.org/bin/darwin20/arm64/openssl-1.1.1t-darwin.20-arm64.tar.xz
|
|
25
|
+
tar -xf openssl-1.1.1t-darwin.20-arm64.tar.xz -C /tmp
|
|
26
|
+
rm -rf openssl-1.1.1t-darwin.20-arm64.tar.xz
|
|
26
27
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
27
|
-
uses: actions/setup-node@
|
|
28
|
+
uses: actions/setup-node@v4
|
|
28
29
|
with:
|
|
29
30
|
node-version: ${{ matrix.node-version }}
|
|
30
31
|
- name: Build
|
|
@@ -11,25 +11,25 @@ env:
|
|
|
11
11
|
|
|
12
12
|
jobs:
|
|
13
13
|
build-macos:
|
|
14
|
-
runs-on: macos-
|
|
14
|
+
runs-on: macos-13
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
17
|
node-version: [16.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
|
-
- uses: actions/checkout@
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
21
|
- name: Install OpenSSL
|
|
22
22
|
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew reinstall openssl@1.1
|
|
23
23
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
24
|
-
uses: actions/setup-node@
|
|
24
|
+
uses: actions/setup-node@v4
|
|
25
25
|
with:
|
|
26
26
|
node-version: ${{ matrix.node-version }}
|
|
27
27
|
- name: Build
|
|
28
28
|
run: npm install --build-from-source
|
|
29
29
|
env:
|
|
30
30
|
CI: true
|
|
31
|
-
OPENSSL_ROOT_DIR: /usr/local/opt/openssl
|
|
32
|
-
OPENSSL_LIBRARIES: /usr/local/opt/openssl/lib
|
|
31
|
+
OPENSSL_ROOT_DIR: /usr/local/opt/openssl@1.1
|
|
32
|
+
OPENSSL_LIBRARIES: /usr/local/opt/openssl@1.1/lib
|
|
33
33
|
- name: Test
|
|
34
34
|
run: npm run test
|
|
35
35
|
env:
|
package/API.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# API
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## PeerConnection Class
|
|
4
4
|
|
|
5
5
|
**Constructor**
|
|
6
6
|
|
|
7
7
|
let pc = new PeerConnection(peerName[,options])
|
|
8
|
-
|
|
9
|
-
-
|
|
8
|
+
|
|
9
|
+
- peerName `<string>` Peer name to use for logs etc..
|
|
10
|
+
- options `<Object>` WebRTC Config Options
|
|
11
|
+
|
|
10
12
|
```
|
|
11
13
|
export interface RtcConfig {
|
|
12
14
|
iceServers: (string | IceServer)[];
|
|
@@ -57,6 +59,7 @@ Close Peer Connection & Clear all callbacks
|
|
|
57
59
|
**setRemoteDescription: (sdp: string, type: DescriptionType) => void**
|
|
58
60
|
|
|
59
61
|
Set Remote Description
|
|
62
|
+
|
|
60
63
|
```
|
|
61
64
|
export const enum DescriptionType {
|
|
62
65
|
Unspec = 'Unspec',
|
|
@@ -72,29 +75,21 @@ Add remote candidate info
|
|
|
72
75
|
**createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel**
|
|
73
76
|
|
|
74
77
|
Create new data-channel
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
|
|
79
|
+
- label `<string>` Data channel name
|
|
80
|
+
- config `<Object>` Data channel options
|
|
81
|
+
|
|
77
82
|
```
|
|
78
83
|
export interface DataChannelInitConfig {
|
|
79
84
|
protocol?: string;
|
|
80
85
|
negotiated?: boolean;
|
|
81
86
|
id?: number;
|
|
82
|
-
|
|
83
|
-
maxPacketLifeTime?: number;
|
|
84
|
-
maxRetransmits?: number;
|
|
85
|
-
|
|
86
|
-
// Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
|
|
87
|
-
reliability?: {
|
|
88
|
-
type?: ReliabilityType;
|
|
89
|
-
unordered?: boolean;
|
|
90
|
-
rexmit?: number;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export const enum ReliabilityType {
|
|
95
|
-
Reliable = 0, Rexmit = 1, Timed = 2
|
|
87
|
+
unordered?: boolean; // Reliability
|
|
88
|
+
maxPacketLifeTime?: number; // Reliability
|
|
89
|
+
maxRetransmits?: number; // Reliability
|
|
96
90
|
}
|
|
97
91
|
```
|
|
92
|
+
|
|
98
93
|
**state: () => string**
|
|
99
94
|
|
|
100
95
|
Get current state
|
|
@@ -110,6 +105,7 @@ Get current gathering state
|
|
|
110
105
|
**onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void**
|
|
111
106
|
|
|
112
107
|
Local Description Callback
|
|
108
|
+
|
|
113
109
|
```
|
|
114
110
|
export const enum DescriptionType {
|
|
115
111
|
Unspec = 'Unspec',
|
|
@@ -153,6 +149,7 @@ Get rtt stat
|
|
|
153
149
|
**getSelectedCandidatePair: () => { local: SelectedCandidateInfo, remote: SelectedCandidateInfo }**
|
|
154
150
|
|
|
155
151
|
Get info about selected candidate pair
|
|
152
|
+
|
|
156
153
|
```
|
|
157
154
|
export interface SelectedCandidateInfo {
|
|
158
155
|
address: string;
|
|
@@ -162,7 +159,7 @@ export interface SelectedCandidateInfo {
|
|
|
162
159
|
}
|
|
163
160
|
```
|
|
164
161
|
|
|
165
|
-
##
|
|
162
|
+
## DataChannel Class
|
|
166
163
|
|
|
167
164
|
> You can create a new Datachannel instance by calling `PeerConnection.createDataChannel` function.
|
|
168
165
|
|
package/CMakeLists.txt
CHANGED
|
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
|
|
|
2
2
|
cmake_policy(SET CMP0091 NEW)
|
|
3
3
|
cmake_policy(SET CMP0042 NEW)
|
|
4
4
|
|
|
5
|
-
project(node_datachannel VERSION 0.
|
|
5
|
+
project(node_datachannel VERSION 0.10.1)
|
|
6
6
|
|
|
7
7
|
# -Dnapi_build_version=8
|
|
8
8
|
add_definitions(-DNAPI_VERSION=8)
|
|
@@ -29,7 +29,7 @@ include(FetchContent)
|
|
|
29
29
|
FetchContent_Declare(
|
|
30
30
|
libdatachannel
|
|
31
31
|
GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
|
|
32
|
-
GIT_TAG "v0.21.
|
|
32
|
+
GIT_TAG "v0.21.2"
|
|
33
33
|
)
|
|
34
34
|
|
|
35
35
|
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
|
package/README.md
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# WebRTC For Node.js and Electron
|
|
2
2
|
|
|
3
3
|
   
|
|
4
4
|
|
|
5
|
-
- Easy to use
|
|
6
5
|
- Lightweight
|
|
7
6
|
- No need to deal with WebRTC stack!
|
|
8
|
-
- Small binary sizes
|
|
7
|
+
- Small binary sizes (~8MB for Linux X64)
|
|
9
8
|
- Type infos for Typescript
|
|
10
9
|
|
|
11
|
-
This project is
|
|
12
|
-
|
|
13
|
-
Please check [libdatachannel](https://github.com/paullouisageneau/libdatachannel) for Compatibility & WebRTC details.
|
|
10
|
+
This project is Node.js bindings for [libdatachannel](https://github.com/paullouisageneau/libdatachannel) library.
|
|
14
11
|
|
|
15
12
|
## Install
|
|
16
13
|
|
|
@@ -20,17 +17,13 @@ npm install node-datachannel
|
|
|
20
17
|
|
|
21
18
|
## Supported Platforms
|
|
22
19
|
|
|
23
|
-
`node-datachannel` targets N-API version 8 and supports
|
|
20
|
+
`node-datachannel` targets N-API version 8 and supports Node.js v16 and above. It is tested on Linux, Windows and MacOS. For N-API compatibility please check [here](https://nodejs.org/api/n-api.html#n_api_n_api_version_matrix).
|
|
24
21
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
| Node
|
|
28
|
-
| Node V17 | + | + | + | + | + | + |
|
|
29
|
-
| Node V18 | + | + | + | + | + | + |
|
|
30
|
-
| Node V19 | + | + | + | + | + | + |
|
|
31
|
-
| Node V20 | + | + | + | + | + | + |
|
|
22
|
+
| | Linux [x64,armv7,arm64] (1) | Windows [x86,x64] | Mac [M1,x64] |
|
|
23
|
+
| ------------------------- | :-------------------------: | :---------------: | :----------: |
|
|
24
|
+
| N-API v8 (>= Node.js v16) | + | + | + |
|
|
32
25
|
|
|
33
|
-
1
|
|
26
|
+
**(1)** For Linux musl + libc
|
|
34
27
|
|
|
35
28
|
## Electron
|
|
36
29
|
|
|
@@ -38,6 +31,12 @@ npm install node-datachannel
|
|
|
38
31
|
|
|
39
32
|
Please check [electron demo](/examples/electron-demo)
|
|
40
33
|
|
|
34
|
+
## WebRTC Polyfills
|
|
35
|
+
|
|
36
|
+
WebRTC polyfills to be used for libraries like `simple-peer`.
|
|
37
|
+
|
|
38
|
+
Please check [here](/polyfill)
|
|
39
|
+
|
|
41
40
|
## Example Usage
|
|
42
41
|
|
|
43
42
|
```js
|
|
@@ -51,29 +50,22 @@ let dc2 = null;
|
|
|
51
50
|
|
|
52
51
|
let peer1 = new nodeDataChannel.PeerConnection('Peer1', { iceServers: ['stun:stun.l.google.com:19302'] });
|
|
53
52
|
|
|
54
|
-
// Set Callbacks
|
|
55
53
|
peer1.onLocalDescription((sdp, type) => {
|
|
56
|
-
console.log('Peer1 SDP:', sdp, ' Type:', type);
|
|
57
54
|
peer2.setRemoteDescription(sdp, type);
|
|
58
55
|
});
|
|
59
56
|
peer1.onLocalCandidate((candidate, mid) => {
|
|
60
|
-
console.log('Peer1 Candidate:', candidate);
|
|
61
57
|
peer2.addRemoteCandidate(candidate, mid);
|
|
62
58
|
});
|
|
63
59
|
|
|
64
60
|
let peer2 = new nodeDataChannel.PeerConnection('Peer2', { iceServers: ['stun:stun.l.google.com:19302'] });
|
|
65
61
|
|
|
66
|
-
// Set Callbacks
|
|
67
62
|
peer2.onLocalDescription((sdp, type) => {
|
|
68
|
-
console.log('Peer2 SDP:', sdp, ' Type:', type);
|
|
69
63
|
peer1.setRemoteDescription(sdp, type);
|
|
70
64
|
});
|
|
71
65
|
peer2.onLocalCandidate((candidate, mid) => {
|
|
72
|
-
console.log('Peer2 Candidate:', candidate);
|
|
73
66
|
peer1.addRemoteCandidate(candidate, mid);
|
|
74
67
|
});
|
|
75
68
|
peer2.onDataChannel((dc) => {
|
|
76
|
-
console.log('Peer2 Got DataChannel: ', dc.getLabel());
|
|
77
69
|
dc2 = dc;
|
|
78
70
|
dc2.onMessage((msg) => {
|
|
79
71
|
console.log('Peer2 Received Msg:', msg);
|
|
@@ -90,19 +82,11 @@ dc1.onOpen(() => {
|
|
|
90
82
|
dc1.onMessage((msg) => {
|
|
91
83
|
console.log('Peer1 Received Msg:', msg);
|
|
92
84
|
});
|
|
93
|
-
|
|
94
|
-
setTimeout(() => {
|
|
95
|
-
dc1.close();
|
|
96
|
-
dc2.close();
|
|
97
|
-
peer1.close();
|
|
98
|
-
peer2.close();
|
|
99
|
-
nodeDataChannel.cleanup();
|
|
100
|
-
}, 10 * 1000);
|
|
101
85
|
```
|
|
102
86
|
|
|
103
|
-
##
|
|
87
|
+
## Examples
|
|
104
88
|
|
|
105
|
-
Please check [
|
|
89
|
+
Please check [examples](/examples/) folder
|
|
106
90
|
|
|
107
91
|
## Test
|
|
108
92
|
|
|
@@ -115,14 +99,14 @@ node test/connectivity.js # Connectivity
|
|
|
115
99
|
|
|
116
100
|
Please check [here](/BULDING.md)
|
|
117
101
|
|
|
118
|
-
## Examples
|
|
119
|
-
|
|
120
|
-
Please check [examples](/examples/) folder
|
|
121
|
-
|
|
122
102
|
## API Docs
|
|
123
103
|
|
|
124
104
|
Please check [docs](/API.md) page
|
|
125
105
|
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
Contributions welcome!
|
|
109
|
+
|
|
126
110
|
## Thanks
|
|
127
111
|
|
|
128
112
|
Thanks to [Streamr](https://streamr.network/) for supporting this project by being a Sponsor!
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
set(CMAKE_SYSTEM_NAME Linux)
|
|
2
|
+
set(triple $ENV{TRIPLE})
|
|
3
|
+
|
|
4
|
+
# use clang and lld
|
|
5
|
+
set(CMAKE_C_COMPILER $ENV{GCC})
|
|
6
|
+
set(CMAKE_CXX_COMPILER $ENV{GCC})
|
|
7
|
+
if (CMAKE_C_COMPILER MATCHES clang)
|
|
8
|
+
add_link_options("-fuse-ld=lld")
|
|
9
|
+
endif()
|
|
10
|
+
|
|
11
|
+
set(CMAKE_SYSROOT "$ENV{SYSROOT}")
|
|
12
|
+
message(STATUS "Using sysroot: ${CMAKE_SYSROOT}")
|
|
13
|
+
|
|
14
|
+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
15
|
+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
16
|
+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
17
|
+
|
|
18
|
+
set(CMAKE_C_COMPILER_TARGET ${triple})
|
|
19
|
+
set(CMAKE_CXX_COMPILER_TARGET ${triple})
|
|
20
|
+
message(STATUS "Compiling for: ${triple}")
|
|
21
|
+
|
|
22
|
+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{COMPILER_FLAGS}")
|
|
23
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{COMPILER_FLAGS}")
|
|
@@ -139,9 +139,9 @@
|
|
|
139
139
|
}
|
|
140
140
|
},
|
|
141
141
|
"node_modules/ws": {
|
|
142
|
-
"version": "7.5.
|
|
143
|
-
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.
|
|
144
|
-
"integrity": "sha512
|
|
142
|
+
"version": "7.5.10",
|
|
143
|
+
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
|
144
|
+
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
|
145
145
|
"engines": {
|
|
146
146
|
"node": ">=8.3.0"
|
|
147
147
|
},
|
|
@@ -283,9 +283,9 @@
|
|
|
283
283
|
}
|
|
284
284
|
},
|
|
285
285
|
"ws": {
|
|
286
|
-
"version": "7.5.
|
|
287
|
-
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.
|
|
288
|
-
"integrity": "sha512
|
|
286
|
+
"version": "7.5.10",
|
|
287
|
+
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
|
288
|
+
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
|
289
289
|
"requires": {}
|
|
290
290
|
},
|
|
291
291
|
"y18n": {
|
package/lib/index.d.cts
CHANGED
|
@@ -71,26 +71,13 @@ export enum DescriptionType {
|
|
|
71
71
|
Rollback = 'rollback',
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export const enum ReliabilityType {
|
|
75
|
-
Reliable = 0,
|
|
76
|
-
Rexmit = 1,
|
|
77
|
-
Timed = 2,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
74
|
export interface DataChannelInitConfig {
|
|
81
75
|
protocol?: string;
|
|
82
76
|
negotiated?: boolean;
|
|
83
77
|
id?: number;
|
|
84
|
-
|
|
85
|
-
maxPacketLifeTime?: number;
|
|
86
|
-
maxRetransmits?: number;
|
|
87
|
-
|
|
88
|
-
// Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
|
|
89
|
-
reliability?: {
|
|
90
|
-
type?: ReliabilityType;
|
|
91
|
-
unordered?: boolean;
|
|
92
|
-
rexmit?: number;
|
|
93
|
-
};
|
|
78
|
+
unordered?: boolean; // Reliability
|
|
79
|
+
maxPacketLifeTime?: number; // Reliability
|
|
80
|
+
maxRetransmits?: number; // Reliability
|
|
94
81
|
}
|
|
95
82
|
|
|
96
83
|
export interface SelectedCandidateInfo {
|
|
@@ -113,8 +100,7 @@ export const enum Direction {
|
|
|
113
100
|
}
|
|
114
101
|
|
|
115
102
|
export class RtcpReceivingSession {
|
|
116
|
-
|
|
117
|
-
requestKeyframe(): boolean;
|
|
103
|
+
//
|
|
118
104
|
}
|
|
119
105
|
|
|
120
106
|
export class Audio {
|
package/lib/index.d.ts
CHANGED
|
@@ -71,26 +71,13 @@ export enum DescriptionType {
|
|
|
71
71
|
Rollback = 'rollback',
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export const enum ReliabilityType {
|
|
75
|
-
Reliable = 0,
|
|
76
|
-
Rexmit = 1,
|
|
77
|
-
Timed = 2,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
74
|
export interface DataChannelInitConfig {
|
|
81
75
|
protocol?: string;
|
|
82
76
|
negotiated?: boolean;
|
|
83
77
|
id?: number;
|
|
84
|
-
|
|
85
|
-
maxPacketLifeTime?: number;
|
|
86
|
-
maxRetransmits?: number;
|
|
87
|
-
|
|
88
|
-
// Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
|
|
89
|
-
reliability?: {
|
|
90
|
-
type?: ReliabilityType;
|
|
91
|
-
unordered?: boolean;
|
|
92
|
-
rexmit?: number;
|
|
93
|
-
};
|
|
78
|
+
unordered?: boolean; // Reliability
|
|
79
|
+
maxPacketLifeTime?: number; // Reliability
|
|
80
|
+
maxRetransmits?: number; // Reliability
|
|
94
81
|
}
|
|
95
82
|
|
|
96
83
|
export interface SelectedCandidateInfo {
|
|
@@ -113,8 +100,7 @@ export const enum Direction {
|
|
|
113
100
|
}
|
|
114
101
|
|
|
115
102
|
export class RtcpReceivingSession {
|
|
116
|
-
|
|
117
|
-
requestKeyframe(): boolean;
|
|
103
|
+
//
|
|
118
104
|
}
|
|
119
105
|
|
|
120
106
|
export class Audio {
|
package/package.json
CHANGED
package/polyfill/README.md
CHANGED
|
@@ -11,8 +11,7 @@ Napi::Object RtcpReceivingSessionWrapper::Init(Napi::Env env, Napi::Object expor
|
|
|
11
11
|
env,
|
|
12
12
|
"RtcpReceivingSession",
|
|
13
13
|
{
|
|
14
|
-
|
|
15
|
-
Napi::ObjectWrap<RtcpReceivingSessionWrapper>::InstanceMethod("requestKeyframe", &RtcpReceivingSessionWrapper::requestKeyframe),
|
|
14
|
+
// Instance Methods
|
|
16
15
|
});
|
|
17
16
|
|
|
18
17
|
constructor = Napi::Persistent(func);
|
|
@@ -39,24 +38,3 @@ std::shared_ptr<rtc::RtcpReceivingSession> RtcpReceivingSessionWrapper::getSessi
|
|
|
39
38
|
{
|
|
40
39
|
return mSessionPtr;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
void RtcpReceivingSessionWrapper::requestBitrate(const Napi::CallbackInfo &info)
|
|
44
|
-
{
|
|
45
|
-
Napi::Env env = info.Env();
|
|
46
|
-
int length = info.Length();
|
|
47
|
-
|
|
48
|
-
if (length < 1 || !info[0].IsNumber())
|
|
49
|
-
{
|
|
50
|
-
Napi::TypeError::New(env, "We expect (Number) as param").ThrowAsJavaScriptException();
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
unsigned int bitrate = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
|
|
55
|
-
mSessionPtr->requestBitrate(bitrate);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
Napi::Value RtcpReceivingSessionWrapper::requestKeyframe(const Napi::CallbackInfo &info)
|
|
59
|
-
{
|
|
60
|
-
Napi::Env env = info.Env();
|
|
61
|
-
return Napi::Boolean::New(env, mSessionPtr->requestKeyframe());
|
|
62
|
-
}
|
|
@@ -22,15 +22,12 @@ public:
|
|
|
22
22
|
std::shared_ptr<rtc::RtcpReceivingSession> getSessionInstance();
|
|
23
23
|
|
|
24
24
|
// Functions
|
|
25
|
-
void requestBitrate(const Napi::CallbackInfo &info);
|
|
26
|
-
Napi::Value requestKeyframe(const Napi::CallbackInfo &info);
|
|
27
25
|
|
|
28
26
|
// Callbacks
|
|
29
|
-
|
|
30
27
|
|
|
31
28
|
private:
|
|
32
|
-
static std::unordered_set<RtcpReceivingSessionWrapper*> instances;
|
|
29
|
+
static std::unordered_set<RtcpReceivingSessionWrapper *> instances;
|
|
33
30
|
std::shared_ptr<rtc::RtcpReceivingSession> mSessionPtr = nullptr;
|
|
34
31
|
};
|
|
35
32
|
|
|
36
|
-
#endif // MEDIA_RTCPRECEIVINGSESSION_WRAPPER_H
|
|
33
|
+
#endif // MEDIA_RTCPRECEIVINGSESSION_WRAPPER_H
|
|
@@ -249,7 +249,7 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
|
|
|
249
249
|
PLOG_DEBUG << "Peer Connection created";
|
|
250
250
|
|
|
251
251
|
// State change callback must be set to trigger cleanup on close
|
|
252
|
-
mOnStateChangeCallback = std::make_unique<ThreadSafeCallback>(Napi::Function::New(info.Env(), [](const Napi::CallbackInfo&){}));
|
|
252
|
+
mOnStateChangeCallback = std::make_unique<ThreadSafeCallback>(Napi::Function::New(info.Env(), [](const Napi::CallbackInfo &) {}));
|
|
253
253
|
|
|
254
254
|
instances.insert(this);
|
|
255
255
|
}
|
|
@@ -503,81 +503,17 @@ Napi::Value PeerConnectionWrapper::createDataChannel(const Napi::CallbackInfo &i
|
|
|
503
503
|
init.id = uint16_t(initConfig.Get("id").As<Napi::Number>().Uint32Value());
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
-
//
|
|
507
|
-
if (!initConfig.Get("
|
|
506
|
+
// Reliability.unordered parameter
|
|
507
|
+
if (!initConfig.Get("unordered").IsUndefined())
|
|
508
508
|
{
|
|
509
|
-
if (!initConfig.Get("
|
|
509
|
+
if (!initConfig.Get("unordered").IsBoolean())
|
|
510
510
|
{
|
|
511
|
-
Napi::TypeError::New(env, "Wrong DataChannel Init Config (
|
|
511
|
+
Napi::TypeError::New(env, "Wrong DataChannel Init Config (unordered)").ThrowAsJavaScriptException();
|
|
512
512
|
return info.Env().Null();
|
|
513
513
|
}
|
|
514
|
-
|
|
515
|
-
Napi::Object reliability = initConfig.Get("reliability").As<Napi::Object>();
|
|
516
|
-
if (!reliability.Get("type").IsUndefined())
|
|
517
|
-
{
|
|
518
|
-
if (!reliability.Get("type").IsNumber())
|
|
519
|
-
{
|
|
520
|
-
Napi::TypeError::New(env, "Wrong Reliability Config (type)").ThrowAsJavaScriptException();
|
|
521
|
-
return info.Env().Null();
|
|
522
|
-
}
|
|
523
|
-
switch (reliability.Get("type").As<Napi::Number>().Uint32Value())
|
|
524
|
-
{
|
|
525
|
-
case 0:
|
|
526
|
-
init.reliability.type = rtc::Reliability::Type::Reliable;
|
|
527
|
-
break;
|
|
528
|
-
case 1:
|
|
529
|
-
init.reliability.type = rtc::Reliability::Type::Rexmit;
|
|
530
|
-
break;
|
|
531
|
-
case 2:
|
|
532
|
-
init.reliability.type = rtc::Reliability::Type::Timed;
|
|
533
|
-
break;
|
|
534
|
-
default:
|
|
535
|
-
Napi::TypeError::New(env, "Unknown DataChannel Reliability Type").ThrowAsJavaScriptException();
|
|
536
|
-
return info.Env().Null();
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
if (!reliability.Get("unordered").IsUndefined())
|
|
541
|
-
{
|
|
542
|
-
if (!reliability.Get("unordered").IsBoolean())
|
|
543
|
-
{
|
|
544
|
-
Napi::TypeError::New(env, "Wrong reliability Config (unordered)").ThrowAsJavaScriptException();
|
|
545
|
-
return info.Env().Null();
|
|
546
|
-
}
|
|
547
|
-
init.reliability.unordered = reliability.Get("unordered").As<Napi::Boolean>();
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
if (!reliability.Get("rexmit").IsUndefined())
|
|
551
|
-
{
|
|
552
|
-
if (!reliability.Get("rexmit").IsNumber())
|
|
553
|
-
{
|
|
554
|
-
Napi::TypeError::New(env, "Wrong Reliability Config (rexmit)").ThrowAsJavaScriptException();
|
|
555
|
-
return info.Env().Null();
|
|
556
|
-
}
|
|
557
|
-
switch (reliability.Get("type").As<Napi::Number>().Uint32Value())
|
|
558
|
-
{
|
|
559
|
-
case 1:
|
|
560
|
-
init.reliability.rexmit = int(reliability.Get("rexmit").As<Napi::Number>().ToNumber().Uint32Value());
|
|
561
|
-
break;
|
|
562
|
-
case 2:
|
|
563
|
-
init.reliability.rexmit = std::chrono::milliseconds(reliability.Get("rexmit").As<Napi::Number>().Int32Value());
|
|
564
|
-
break;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
514
|
+
init.reliability.unordered = !initConfig.Get("unordered").As<Napi::Boolean>();
|
|
567
515
|
}
|
|
568
516
|
|
|
569
|
-
// Reliability parameters
|
|
570
|
-
if (!initConfig.Get("ordered").IsUndefined())
|
|
571
|
-
{
|
|
572
|
-
if (!initConfig.Get("ordered").IsBoolean())
|
|
573
|
-
{
|
|
574
|
-
Napi::TypeError::New(env, "Wrong DataChannel Init Config (ordered)").ThrowAsJavaScriptException();
|
|
575
|
-
return info.Env().Null();
|
|
576
|
-
}
|
|
577
|
-
init.reliability.unordered = !initConfig.Get("ordered").As<Napi::Boolean>();
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
517
|
if (!initConfig.Get("maxPacketLifeTime").IsUndefined() && !initConfig.Get("maxPacketLifeTime").IsNull() &&
|
|
582
518
|
!initConfig.Get("maxRetransmits").IsUndefined() && !initConfig.Get("maxRetransmits").IsNull())
|
|
583
519
|
{
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
set(CMAKE_SYSTEM_NAME Linux)
|
|
2
|
-
set(TOOLCHAIN_PREFIX aarch64-linux-gnu)
|
|
3
|
-
|
|
4
|
-
# cross compilers to use for C and C++
|
|
5
|
-
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
|
6
|
-
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
|
7
|
-
|
|
8
|
-
# Needed sysroot
|
|
9
|
-
# https://github.com/webrtc-uwp/chromium-build/blob/master/linux/sysroot_scripts/sysroots.json
|
|
10
|
-
set(CMAKE_SYSROOT "$ENV{ARM64_SYSROOT}")
|
|
11
|
-
|
|
12
|
-
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
13
|
-
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
14
|
-
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
15
|
-
|
|
16
|
-
set(CMAKE_C_FLAGS "-march=armv8-a -fPIC -Wno-error=format-truncation" CACHE STRING "Compiler Flags")
|
|
17
|
-
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Compiler Flags")
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
set(CMAKE_SYSTEM_NAME Linux)
|
|
2
|
-
set(TOOLCHAIN_PREFIX arm-linux-gnueabihf)
|
|
3
|
-
|
|
4
|
-
# cross compilers to use for C and C++
|
|
5
|
-
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
|
6
|
-
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
|
7
|
-
|
|
8
|
-
# Needed sysroot
|
|
9
|
-
# https://github.com/webrtc-uwp/chromium-build/blob/master/linux/sysroot_scripts/sysroots.json
|
|
10
|
-
set(CMAKE_SYSROOT "$ENV{ARM_SYSROOT}")
|
|
11
|
-
|
|
12
|
-
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
13
|
-
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
14
|
-
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
15
|
-
|
|
16
|
-
set(CMAKE_C_FLAGS "-march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -fPIC -Wno-error=format-truncation" CACHE STRING "Compiler Flags")
|
|
17
|
-
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Compiler Flags")
|