node-datachannel 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +25 -25
- package/.prettierignore +4 -0
- package/.prettierrc +1 -0
- package/API.md +4 -4
- package/BULDING.md +11 -2
- package/CMakeLists.txt +37 -13
- package/README.md +22 -18
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/datachannel-stream.cjs +13 -13
- package/dist/cjs/lib/datachannel-stream.cjs.map +1 -1
- package/dist/cjs/lib/index.cjs +1 -3
- package/dist/cjs/lib/index.cjs.map +1 -1
- package/dist/cjs/lib/websocket-server.cjs.map +1 -1
- package/dist/cjs/lib/websocket.cjs.map +1 -1
- package/dist/cjs/polyfill/Events.cjs +52 -3
- package/dist/cjs/polyfill/Events.cjs.map +1 -1
- package/dist/cjs/polyfill/Exception.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCCertificate.cjs +5 -2
- package/dist/cjs/polyfill/RTCCertificate.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCDataChannel.cjs +27 -19
- package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs +6 -5
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCError.cjs +9 -2
- package/dist/cjs/polyfill/RTCError.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCIceCandidate.cjs +13 -8
- package/dist/cjs/polyfill/RTCIceCandidate.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCIceTransport.cjs +26 -16
- package/dist/cjs/polyfill/RTCIceTransport.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCPeerConnection.cjs +80 -70
- package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCSctpTransport.cjs +9 -11
- package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCSessionDescription.cjs +10 -2
- package/dist/cjs/polyfill/RTCSessionDescription.cjs.map +1 -1
- package/dist/cjs/polyfill/index.cjs.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/datachannel-stream.mjs.map +1 -1
- package/dist/esm/lib/index.mjs +1 -3
- package/dist/esm/lib/index.mjs.map +1 -1
- package/dist/esm/lib/websocket-server.mjs.map +1 -1
- package/dist/esm/lib/websocket.mjs.map +1 -1
- package/dist/esm/polyfill/Events.mjs +52 -4
- package/dist/esm/polyfill/Events.mjs.map +1 -1
- package/dist/esm/polyfill/Exception.mjs.map +1 -1
- package/dist/esm/polyfill/RTCCertificate.mjs +5 -2
- package/dist/esm/polyfill/RTCCertificate.mjs.map +1 -1
- package/dist/esm/polyfill/RTCDataChannel.mjs +27 -19
- package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -1
- package/dist/esm/polyfill/RTCDtlsTransport.mjs +6 -5
- package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -1
- package/dist/esm/polyfill/RTCError.mjs +9 -2
- package/dist/esm/polyfill/RTCError.mjs.map +1 -1
- package/dist/esm/polyfill/RTCIceCandidate.mjs +13 -8
- package/dist/esm/polyfill/RTCIceCandidate.mjs.map +1 -1
- package/dist/esm/polyfill/RTCIceTransport.mjs +26 -17
- package/dist/esm/polyfill/RTCIceTransport.mjs.map +1 -1
- package/dist/esm/polyfill/RTCPeerConnection.mjs +80 -70
- package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
- package/dist/esm/polyfill/RTCSctpTransport.mjs +9 -11
- package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -1
- package/dist/esm/polyfill/RTCSessionDescription.mjs +10 -2
- package/dist/esm/polyfill/RTCSessionDescription.mjs.map +1 -1
- package/dist/esm/polyfill/index.mjs.map +1 -1
- package/dist/types/lib/index.d.ts +5 -2
- package/dist/types/lib/types.d.ts +6 -6
- package/dist/types/polyfill/Events.d.ts +3 -3
- package/dist/types/polyfill/RTCCertificate.d.ts +1 -0
- package/dist/types/polyfill/RTCDataChannel.d.ts +6 -6
- package/dist/types/polyfill/RTCDtlsTransport.d.ts +4 -6
- package/dist/types/polyfill/RTCError.d.ts +1 -0
- package/dist/types/polyfill/RTCIceCandidate.d.ts +1 -1
- package/dist/types/polyfill/RTCIceTransport.d.ts +16 -10
- package/dist/types/polyfill/RTCPeerConnection.d.ts +29 -22
- package/dist/types/polyfill/RTCSctpTransport.d.ts +2 -4
- package/dist/types/polyfill/RTCSessionDescription.d.ts +1 -0
- package/jest.config.ts +8 -8
- package/package.json +114 -112
- package/rollup.config.mjs +1 -1
- package/src/cpp/data-channel-wrapper.cpp +11 -0
- package/src/cpp/main.cpp +14 -0
- package/src/cpp/peer-connection-wrapper.cpp +9 -1
- package/src/cpp/peer-connection-wrapper.h +5 -1
- package/src/cpp/rtc-wrapper.cpp +18 -0
- package/src/index.ts +0 -1
- package/src/lib/datachannel-stream.ts +83 -84
- package/src/lib/index.ts +165 -139
- package/src/lib/types.ts +97 -72
- package/src/lib/websocket-server.ts +25 -25
- package/src/lib/websocket.ts +19 -19
- package/src/polyfill/Events.ts +65 -19
- package/src/polyfill/Exception.ts +24 -24
- package/src/polyfill/README.md +8 -8
- package/src/polyfill/RTCCertificate.ts +16 -12
- package/src/polyfill/RTCDataChannel.ts +198 -192
- package/src/polyfill/RTCDtlsTransport.ts +38 -39
- package/src/polyfill/RTCError.ts +63 -56
- package/src/polyfill/RTCIceCandidate.ts +120 -116
- package/src/polyfill/RTCIceTransport.ts +71 -64
- package/src/polyfill/RTCPeerConnection.ts +436 -420
- package/src/polyfill/RTCSctpTransport.ts +43 -47
- package/src/polyfill/RTCSessionDescription.ts +26 -17
- package/src/polyfill/index.ts +22 -22
package/package.json
CHANGED
|
@@ -1,117 +1,119 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
"./polyfill": {
|
|
26
|
-
"types": "./dist/types/polyfill/index.d.ts",
|
|
27
|
-
"require": "./dist/cjs/polyfill/index.cjs",
|
|
28
|
-
"import": "./dist/esm/polyfill/index.mjs",
|
|
29
|
-
"default": "./dist/polyfill/esm/index.mjs"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"engines": {
|
|
33
|
-
"node": ">=18.20.0"
|
|
34
|
-
},
|
|
35
|
-
"scripts": {
|
|
36
|
-
"install": "prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)",
|
|
37
|
-
"install:nice": "npm run clean && npm install --ignore-scripts --production=false && cmake-js build --CDUSE_NICE=1",
|
|
38
|
-
"install:gnu": "npm run clean && npm install --ignore-scripts --production=false && cmake-js build --CDUSE_GNUTLS=1",
|
|
39
|
-
"build": "npm run compile && npm run build:tsc",
|
|
40
|
-
"compile": "cmake-js build",
|
|
41
|
-
"compile:debug": "cmake-js build -D",
|
|
42
|
-
"build:tsc": "rimraf dist && rollup -c",
|
|
43
|
-
"build:tsc:watch": "rollup -c -w",
|
|
44
|
-
"clean": "rimraf dist build",
|
|
45
|
-
"lint": "eslint . --ext .ts --ext .mts",
|
|
46
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
47
|
-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
48
|
-
"test:wpt": "npm run run:wpt:server & (sleep 8 && (npm run run:wpt:test | tee test/wpt-tests/last-test-results.md) )",
|
|
49
|
-
"wpt:server": "cd test/wpt-tests/wpt && ./wpt serve",
|
|
50
|
-
"wpt:test": "ts-node test/wpt-tests/index.ts",
|
|
51
|
-
"_prebuild": "prebuild -r napi --backend cmake-js",
|
|
52
|
-
"prepack": "npm run build:tsc"
|
|
53
|
-
},
|
|
54
|
-
"binary": {
|
|
55
|
-
"napi_versions": [
|
|
56
|
-
8
|
|
57
|
-
]
|
|
58
|
-
},
|
|
59
|
-
"repository": {
|
|
60
|
-
"type": "git",
|
|
61
|
-
"url": "git+https://github.com/murat-dogan/node-datachannel.git"
|
|
62
|
-
},
|
|
63
|
-
"keywords": [
|
|
64
|
-
"libdatachannel",
|
|
65
|
-
"webrtc",
|
|
66
|
-
"p2p",
|
|
67
|
-
"peer-to-peer",
|
|
68
|
-
"datachannel",
|
|
69
|
-
"data channel",
|
|
70
|
-
"websocket"
|
|
71
|
-
],
|
|
72
|
-
"contributors": [
|
|
73
|
-
{
|
|
74
|
-
"name": "Murat Doğan",
|
|
75
|
-
"url": "https://github.com/murat-dogan"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"name": "Paul-Louis Ageneau",
|
|
79
|
-
"url": "https://github.com/paullouisageneau"
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
"license": "MPL 2.0",
|
|
83
|
-
"bugs": {
|
|
84
|
-
"url": "https://github.com/murat-dogan/node-datachannel/issues"
|
|
2
|
+
"name": "node-datachannel",
|
|
3
|
+
"version": "0.28.0",
|
|
4
|
+
"description": "WebRTC For Node.js and Electron. libdatachannel node bindings.",
|
|
5
|
+
"main": "./dist/cjs/lib/index.cjs",
|
|
6
|
+
"module": "./dist/esm/lib/index.mjs",
|
|
7
|
+
"types": "./dist/types/lib/index.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
"*": {
|
|
10
|
+
"*": [
|
|
11
|
+
"dist/types/lib/index.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"polyfill": [
|
|
14
|
+
"dist/types/polyfill/index.d.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/types/lib/index.d.ts",
|
|
21
|
+
"require": "./dist/cjs/lib/index.cjs",
|
|
22
|
+
"import": "./dist/esm/lib/index.mjs",
|
|
23
|
+
"default": "./dist/lib/esm/index.mjs"
|
|
85
24
|
},
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
25
|
+
"./polyfill": {
|
|
26
|
+
"types": "./dist/types/polyfill/index.d.ts",
|
|
27
|
+
"require": "./dist/cjs/polyfill/index.cjs",
|
|
28
|
+
"import": "./dist/esm/polyfill/index.mjs",
|
|
29
|
+
"default": "./dist/polyfill/esm/index.mjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.20.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"install": "prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)",
|
|
37
|
+
"install:nice": "npm run clean && npm install --ignore-scripts --production=false && cmake-js configure --CDUSE_NICE=1 && cmake-js build",
|
|
38
|
+
"install:gnu": "npm run clean && npm install --ignore-scripts --production=false && cmake-js configure --CDUSE_GNUTLS=1 && cmake-js build",
|
|
39
|
+
"build": "npm run compile && npm run build:tsc",
|
|
40
|
+
"compile": "cmake-js build",
|
|
41
|
+
"build:debug": "npm run compile:debug && npm run build:tsc",
|
|
42
|
+
"compile:debug": "cmake-js configure -D && cmake-js build -D",
|
|
43
|
+
"build:tsc": "rimraf dist && rollup -c",
|
|
44
|
+
"build:tsc:watch": "rollup -c -w",
|
|
45
|
+
"clean": "rimraf dist build",
|
|
46
|
+
"lint": "eslint . --ext .ts --ext .mts",
|
|
47
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
48
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
49
|
+
"test:wpt": "npm run run:wpt:server & (sleep 8 && (npm run run:wpt:test | tee test/wpt-tests/last-test-results.md) )",
|
|
50
|
+
"wpt:server": "cd test/wpt-tests/wpt && ./wpt serve",
|
|
51
|
+
"wpt:test": "ts-node test/wpt-tests/index.ts",
|
|
52
|
+
"_prebuild": "prebuild -r napi --backend cmake-js",
|
|
53
|
+
"prepack": "npm run build:tsc"
|
|
54
|
+
},
|
|
55
|
+
"binary": {
|
|
56
|
+
"napi_versions": [
|
|
57
|
+
8
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "git+https://github.com/murat-dogan/node-datachannel.git"
|
|
63
|
+
},
|
|
64
|
+
"keywords": [
|
|
65
|
+
"libdatachannel",
|
|
66
|
+
"webrtc",
|
|
67
|
+
"p2p",
|
|
68
|
+
"peer-to-peer",
|
|
69
|
+
"datachannel",
|
|
70
|
+
"data channel",
|
|
71
|
+
"websocket"
|
|
72
|
+
],
|
|
73
|
+
"contributors": [
|
|
74
|
+
{
|
|
75
|
+
"name": "Murat Doğan",
|
|
76
|
+
"url": "https://github.com/murat-dogan"
|
|
113
77
|
},
|
|
114
|
-
|
|
115
|
-
|
|
78
|
+
{
|
|
79
|
+
"name": "Paul-Louis Ageneau",
|
|
80
|
+
"url": "https://github.com/paullouisageneau"
|
|
116
81
|
}
|
|
82
|
+
],
|
|
83
|
+
"license": "MPL 2.0",
|
|
84
|
+
"bugs": {
|
|
85
|
+
"url": "https://github.com/murat-dogan/node-datachannel/issues"
|
|
86
|
+
},
|
|
87
|
+
"homepage": "https://github.com/murat-dogan/node-datachannel#readme",
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"@rollup/plugin-esm-shim": "^0.1.7",
|
|
90
|
+
"@rollup/plugin-replace": "^6.0.1",
|
|
91
|
+
"@types/jest": "^29.5.12",
|
|
92
|
+
"@types/node": "^20.6.1",
|
|
93
|
+
"@types/webrtc": "^0.0.46",
|
|
94
|
+
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
|
95
|
+
"@typescript-eslint/parser": "^7.17.0",
|
|
96
|
+
"cmake-js": "^7.3.0",
|
|
97
|
+
"eslint": "^8.57.0",
|
|
98
|
+
"eslint-config-prettier": "^9.1.0",
|
|
99
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
100
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
101
|
+
"jest": "^29.7.0",
|
|
102
|
+
"jsdom": "^24.1.1",
|
|
103
|
+
"node-addon-api": "^7.0.0",
|
|
104
|
+
"prebuild": "^13.0.1",
|
|
105
|
+
"prettier": "^3.3.3",
|
|
106
|
+
"puppeteer": "^22.14.0",
|
|
107
|
+
"rimraf": "^5.0.9",
|
|
108
|
+
"rollup": "^4.22.5",
|
|
109
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
110
|
+
"rollup-plugin-esbuild": "^6.1.1",
|
|
111
|
+
"ts-api-utils": "^1.3.0",
|
|
112
|
+
"ts-jest": "^29.2.3",
|
|
113
|
+
"ts-node": "^10.9.2",
|
|
114
|
+
"typescript": "5.4"
|
|
115
|
+
},
|
|
116
|
+
"dependencies": {
|
|
117
|
+
"prebuild-install": "^7.1.3"
|
|
118
|
+
}
|
|
117
119
|
}
|
package/rollup.config.mjs
CHANGED
|
@@ -103,6 +103,17 @@ void DataChannelWrapper::doCleanup()
|
|
|
103
103
|
{
|
|
104
104
|
PLOG_DEBUG << "doCleanup() called";
|
|
105
105
|
mOnClosedCallback.reset();
|
|
106
|
+
|
|
107
|
+
// For close there are 3 cases:
|
|
108
|
+
// 1. Close was called from JS
|
|
109
|
+
// 2. Close was called from RTC
|
|
110
|
+
// 3. Close was not called from JS or RTC (we are destroying the object)
|
|
111
|
+
// This could be coming from rtc (case 2)
|
|
112
|
+
mDataChannelPtr.reset();
|
|
113
|
+
mOnOpenCallback.reset();
|
|
114
|
+
mOnErrorCallback.reset();
|
|
115
|
+
mOnBufferedAmountLowCallback.reset();
|
|
116
|
+
mOnMessageCallback.reset();
|
|
106
117
|
instances.erase(this);
|
|
107
118
|
}
|
|
108
119
|
|
package/src/cpp/main.cpp
CHANGED
|
@@ -2,24 +2,38 @@
|
|
|
2
2
|
#include "rtc-wrapper.h"
|
|
3
3
|
#include "peer-connection-wrapper.h"
|
|
4
4
|
#include "data-channel-wrapper.h"
|
|
5
|
+
|
|
6
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
5
7
|
#include "media-rtcpreceivingsession-wrapper.h"
|
|
6
8
|
#include "media-track-wrapper.h"
|
|
7
9
|
#include "media-video-wrapper.h"
|
|
8
10
|
#include "media-audio-wrapper.h"
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#if RTC_ENABLE_WEBSOCKET == 1
|
|
9
14
|
#include "web-socket-wrapper.h"
|
|
10
15
|
#include "web-socket-server-wrapper.h"
|
|
16
|
+
#endif
|
|
11
17
|
|
|
12
18
|
Napi::Object InitAll(Napi::Env env, Napi::Object exports)
|
|
13
19
|
{
|
|
14
20
|
RtcWrapper::Init(env, exports);
|
|
21
|
+
|
|
22
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
15
23
|
RtcpReceivingSessionWrapper::Init(env, exports);
|
|
16
24
|
TrackWrapper::Init(env, exports);
|
|
17
25
|
VideoWrapper::Init(env, exports);
|
|
18
26
|
AudioWrapper::Init(env, exports);
|
|
27
|
+
#endif
|
|
28
|
+
|
|
19
29
|
DataChannelWrapper::Init(env, exports);
|
|
20
30
|
PeerConnectionWrapper::Init(env, exports);
|
|
31
|
+
|
|
32
|
+
#if RTC_ENABLE_WEBSOCKET == 1
|
|
21
33
|
WebSocketWrapper::Init(env, exports);
|
|
22
34
|
WebSocketServerWrapper::Init(env, exports);
|
|
35
|
+
#endif
|
|
36
|
+
|
|
23
37
|
return exports;
|
|
24
38
|
}
|
|
25
39
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#include "peer-connection-wrapper.h"
|
|
2
2
|
#include "data-channel-wrapper.h"
|
|
3
|
+
|
|
4
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
3
5
|
#include "media-track-wrapper.h"
|
|
4
6
|
#include "media-video-wrapper.h"
|
|
5
7
|
#include "media-audio-wrapper.h"
|
|
8
|
+
#endif
|
|
6
9
|
|
|
7
10
|
#include "plog/Log.h"
|
|
8
11
|
|
|
@@ -43,7 +46,11 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
|
|
|
43
46
|
InstanceMethod("remoteDescription", &PeerConnectionWrapper::remoteDescription),
|
|
44
47
|
InstanceMethod("addRemoteCandidate", &PeerConnectionWrapper::addRemoteCandidate),
|
|
45
48
|
InstanceMethod("createDataChannel", &PeerConnectionWrapper::createDataChannel),
|
|
49
|
+
|
|
50
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
46
51
|
InstanceMethod("addTrack", &PeerConnectionWrapper::addTrack),
|
|
52
|
+
InstanceMethod("onTrack", &PeerConnectionWrapper::onTrack),
|
|
53
|
+
#endif
|
|
47
54
|
InstanceMethod("hasMedia", &PeerConnectionWrapper::hasMedia),
|
|
48
55
|
InstanceMethod("state", &PeerConnectionWrapper::state),
|
|
49
56
|
InstanceMethod("iceState", &PeerConnectionWrapper::iceState),
|
|
@@ -56,7 +63,6 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
|
|
|
56
63
|
InstanceMethod("onSignalingStateChange", &PeerConnectionWrapper::onSignalingStateChange),
|
|
57
64
|
InstanceMethod("onGatheringStateChange", &PeerConnectionWrapper::onGatheringStateChange),
|
|
58
65
|
InstanceMethod("onDataChannel", &PeerConnectionWrapper::onDataChannel),
|
|
59
|
-
InstanceMethod("onTrack", &PeerConnectionWrapper::onTrack),
|
|
60
66
|
InstanceMethod("bytesSent", &PeerConnectionWrapper::bytesSent),
|
|
61
67
|
InstanceMethod("bytesReceived", &PeerConnectionWrapper::bytesReceived),
|
|
62
68
|
InstanceMethod("rtt", &PeerConnectionWrapper::rtt),
|
|
@@ -1049,6 +1055,7 @@ std::string PeerConnectionWrapper::candidateTransportTypeToString(const rtc::Can
|
|
|
1049
1055
|
}
|
|
1050
1056
|
}
|
|
1051
1057
|
|
|
1058
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
1052
1059
|
Napi::Value PeerConnectionWrapper::addTrack(const Napi::CallbackInfo &info)
|
|
1053
1060
|
{
|
|
1054
1061
|
PLOG_DEBUG << "addTrack() called";
|
|
@@ -1132,6 +1139,7 @@ void PeerConnectionWrapper::onTrack(const Napi::CallbackInfo &info)
|
|
|
1132
1139
|
args = {instance};
|
|
1133
1140
|
}); });
|
|
1134
1141
|
}
|
|
1142
|
+
#endif
|
|
1135
1143
|
|
|
1136
1144
|
Napi::Value PeerConnectionWrapper::hasMedia(const Napi::CallbackInfo &info)
|
|
1137
1145
|
{
|
|
@@ -27,7 +27,12 @@ public:
|
|
|
27
27
|
Napi::Value remoteDescription(const Napi::CallbackInfo &info);
|
|
28
28
|
void addRemoteCandidate(const Napi::CallbackInfo &info);
|
|
29
29
|
Napi::Value createDataChannel(const Napi::CallbackInfo &info);
|
|
30
|
+
|
|
31
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
30
32
|
Napi::Value addTrack(const Napi::CallbackInfo &info);
|
|
33
|
+
void onTrack(const Napi::CallbackInfo &info);
|
|
34
|
+
#endif
|
|
35
|
+
|
|
31
36
|
Napi::Value hasMedia(const Napi::CallbackInfo &info);
|
|
32
37
|
Napi::Value state(const Napi::CallbackInfo &info);
|
|
33
38
|
Napi::Value iceState(const Napi::CallbackInfo &info);
|
|
@@ -42,7 +47,6 @@ public:
|
|
|
42
47
|
void onSignalingStateChange(const Napi::CallbackInfo &info);
|
|
43
48
|
void onGatheringStateChange(const Napi::CallbackInfo &info);
|
|
44
49
|
void onDataChannel(const Napi::CallbackInfo &info);
|
|
45
|
-
void onTrack(const Napi::CallbackInfo &info);
|
|
46
50
|
|
|
47
51
|
// Stats
|
|
48
52
|
Napi::Value bytesSent(const Napi::CallbackInfo &info);
|
package/src/cpp/rtc-wrapper.cpp
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
#include "rtc-wrapper.h"
|
|
2
2
|
#include "peer-connection-wrapper.h"
|
|
3
3
|
#include "data-channel-wrapper.h"
|
|
4
|
+
|
|
5
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
4
6
|
#include "media-track-wrapper.h"
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
#if RTC_ENABLE_WEBSOCKET == 1
|
|
5
10
|
#include "web-socket-wrapper.h"
|
|
6
11
|
#include "web-socket-server-wrapper.h"
|
|
12
|
+
#endif
|
|
7
13
|
|
|
8
14
|
#include "plog/Log.h"
|
|
9
15
|
|
|
@@ -118,9 +124,15 @@ void RtcWrapper::cleanup(const Napi::CallbackInfo &info)
|
|
|
118
124
|
{
|
|
119
125
|
PeerConnectionWrapper::CloseAll();
|
|
120
126
|
DataChannelWrapper::CloseAll();
|
|
127
|
+
|
|
128
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
121
129
|
TrackWrapper::CloseAll();
|
|
130
|
+
#endif
|
|
131
|
+
|
|
132
|
+
#if RTC_ENABLE_WEBSOCKET == 1
|
|
122
133
|
WebSocketWrapper::CloseAll();
|
|
123
134
|
WebSocketServerWrapper::StopAll();
|
|
135
|
+
#endif
|
|
124
136
|
|
|
125
137
|
const auto timeout = std::chrono::seconds(10);
|
|
126
138
|
if (rtc::Cleanup().wait_for(std::chrono::seconds(timeout)) == std::future_status::timeout)
|
|
@@ -129,8 +141,14 @@ void RtcWrapper::cleanup(const Napi::CallbackInfo &info)
|
|
|
129
141
|
// Cleanup the instances
|
|
130
142
|
PeerConnectionWrapper::CleanupAll();
|
|
131
143
|
DataChannelWrapper::CleanupAll();
|
|
144
|
+
|
|
145
|
+
#if RTC_ENABLE_MEDIA == 1
|
|
132
146
|
TrackWrapper::CleanupAll();
|
|
147
|
+
#endif
|
|
148
|
+
|
|
149
|
+
#if RTC_ENABLE_WEBSOCKET == 1
|
|
133
150
|
WebSocketWrapper::CleanupAll();
|
|
151
|
+
#endif
|
|
134
152
|
|
|
135
153
|
if (logCallback)
|
|
136
154
|
logCallback.reset();
|
package/src/index.ts
CHANGED
|
@@ -10,92 +10,91 @@ import * as stream from 'stream';
|
|
|
10
10
|
* the protocol level, and is preserved here throughout.
|
|
11
11
|
*/
|
|
12
12
|
export default class DataChannelStream extends stream.Duplex {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
rawChannel.onOpen(() => this.uncork());
|
|
48
|
-
}
|
|
13
|
+
private _rawChannel: any;
|
|
14
|
+
private _readActive: boolean;
|
|
15
|
+
|
|
16
|
+
constructor(rawChannel: any, streamOptions?: Omit<stream.DuplexOptions, 'objectMode'>) {
|
|
17
|
+
super({
|
|
18
|
+
allowHalfOpen: false, // Default to autoclose on end().
|
|
19
|
+
...streamOptions,
|
|
20
|
+
objectMode: true, // Preserve the string/buffer distinction (WebRTC treats them differently)
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
this._rawChannel = rawChannel;
|
|
24
|
+
this._readActive = true;
|
|
25
|
+
|
|
26
|
+
rawChannel.onMessage((msg: any) => {
|
|
27
|
+
if (!this._readActive) return; // If the buffer is full, drop messages.
|
|
28
|
+
|
|
29
|
+
// If the push is rejected, we pause reading until the next call to _read().
|
|
30
|
+
this._readActive = this.push(msg);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// When the DataChannel closes, the readable & writable ends close
|
|
34
|
+
rawChannel.onClosed(() => {
|
|
35
|
+
this.push(null);
|
|
36
|
+
this.destroy();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
rawChannel.onError((errMsg: string) => {
|
|
40
|
+
this.destroy(new Error(`DataChannel error: ${errMsg}`));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Buffer all writes until the DataChannel opens
|
|
44
|
+
if (!rawChannel.isOpen()) {
|
|
45
|
+
this.cork();
|
|
46
|
+
rawChannel.onOpen(() => this.uncork());
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (sentOk) {
|
|
73
|
-
callback(null);
|
|
74
|
-
} else {
|
|
75
|
-
callback(new Error('Failed to write to DataChannel'));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
_final(callback): void {
|
|
80
|
-
if (!this.allowHalfOpen) this.destroy();
|
|
81
|
-
callback(null);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
_destroy(maybeErr, callback): void {
|
|
85
|
-
// When the stream is destroyed, we close the DataChannel.
|
|
86
|
-
this._rawChannel.close();
|
|
87
|
-
callback(maybeErr);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
get label(): string {
|
|
91
|
-
return this._rawChannel.getLabel();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
get id(): number {
|
|
95
|
-
return this._rawChannel.getId();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_read(): void {
|
|
51
|
+
// Stop dropping messages, if the buffer filling up meant we were doing so before.
|
|
52
|
+
this._readActive = true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_write(chunk, _encoding, callback): void {
|
|
56
|
+
let sentOk;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
if (Buffer.isBuffer(chunk)) {
|
|
60
|
+
sentOk = this._rawChannel.sendMessageBinary(chunk);
|
|
61
|
+
} else if (typeof chunk === 'string') {
|
|
62
|
+
sentOk = this._rawChannel.sendMessage(chunk);
|
|
63
|
+
} else {
|
|
64
|
+
const typeName = chunk.constructor.name || typeof chunk;
|
|
65
|
+
throw new Error(`Cannot write ${typeName} to DataChannel stream`);
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
return callback(err);
|
|
96
69
|
}
|
|
97
70
|
|
|
98
|
-
|
|
99
|
-
|
|
71
|
+
if (sentOk) {
|
|
72
|
+
callback(null);
|
|
73
|
+
} else {
|
|
74
|
+
callback(new Error('Failed to write to DataChannel'));
|
|
100
75
|
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_final(callback): void {
|
|
79
|
+
if (!this.allowHalfOpen) this.destroy();
|
|
80
|
+
callback(null);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_destroy(maybeErr, callback): void {
|
|
84
|
+
// When the stream is destroyed, we close the DataChannel.
|
|
85
|
+
this._rawChannel.close();
|
|
86
|
+
callback(maybeErr);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get label(): string {
|
|
90
|
+
return this._rawChannel.getLabel();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get id(): number {
|
|
94
|
+
return this._rawChannel.getId();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get protocol(): string {
|
|
98
|
+
return this._rawChannel.getProtocol();
|
|
99
|
+
}
|
|
101
100
|
}
|