@lng2004/node-datachannel 0.31.0-20251228
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/.clang-format +17 -0
- package/.editorconfig +12 -0
- package/.eslintignore +8 -0
- package/.eslintrc.json +27 -0
- package/.gitmodules +3 -0
- package/.prettierignore +7 -0
- package/.prettierrc +13 -0
- package/API.md +247 -0
- package/BULDING.md +33 -0
- package/CMakeLists.txt +134 -0
- package/LICENSE +373 -0
- package/README.md +130 -0
- package/dist/cjs/index.cjs +11 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/lib/datachannel-stream.cjs +101 -0
- package/dist/cjs/lib/datachannel-stream.cjs.map +1 -0
- package/dist/cjs/lib/index.cjs +88 -0
- package/dist/cjs/lib/index.cjs.map +1 -0
- package/dist/cjs/lib/node-datachannel.cjs +8 -0
- package/dist/cjs/lib/node-datachannel.cjs.map +1 -0
- package/dist/cjs/lib/websocket-server.cjs +45 -0
- package/dist/cjs/lib/websocket-server.cjs.map +1 -0
- package/dist/cjs/lib/websocket.cjs +8 -0
- package/dist/cjs/lib/websocket.cjs.map +1 -0
- package/dist/cjs/polyfill/Events.cjs +86 -0
- package/dist/cjs/polyfill/Events.cjs.map +1 -0
- package/dist/cjs/polyfill/Exception.cjs +34 -0
- package/dist/cjs/polyfill/Exception.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCCertificate.cjs +34 -0
- package/dist/cjs/polyfill/RTCCertificate.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCDataChannel.cjs +214 -0
- package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs +53 -0
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCError.cjs +83 -0
- package/dist/cjs/polyfill/RTCError.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCIceCandidate.cjs +132 -0
- package/dist/cjs/polyfill/RTCIceCandidate.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCIceTransport.cjs +94 -0
- package/dist/cjs/polyfill/RTCIceTransport.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCPeerConnection.cjs +434 -0
- package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCSctpTransport.cjs +59 -0
- package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCSessionDescription.cjs +45 -0
- package/dist/cjs/polyfill/RTCSessionDescription.cjs.map +1 -0
- package/dist/cjs/polyfill/index.cjs +42 -0
- package/dist/cjs/polyfill/index.cjs.map +1 -0
- package/dist/esm/index.mjs +8 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/lib/datachannel-stream.mjs +78 -0
- package/dist/esm/lib/datachannel-stream.mjs.map +1 -0
- package/dist/esm/lib/index.mjs +62 -0
- package/dist/esm/lib/index.mjs.map +1 -0
- package/dist/esm/lib/node-datachannel.mjs +12 -0
- package/dist/esm/lib/node-datachannel.mjs.map +1 -0
- package/dist/esm/lib/websocket-server.mjs +43 -0
- package/dist/esm/lib/websocket-server.mjs.map +1 -0
- package/dist/esm/lib/websocket.mjs +6 -0
- package/dist/esm/lib/websocket.mjs.map +1 -0
- package/dist/esm/polyfill/Events.mjs +82 -0
- package/dist/esm/polyfill/Events.mjs.map +1 -0
- package/dist/esm/polyfill/Exception.mjs +28 -0
- package/dist/esm/polyfill/Exception.mjs.map +1 -0
- package/dist/esm/polyfill/RTCCertificate.mjs +30 -0
- package/dist/esm/polyfill/RTCCertificate.mjs.map +1 -0
- package/dist/esm/polyfill/RTCDataChannel.mjs +210 -0
- package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -0
- package/dist/esm/polyfill/RTCDtlsTransport.mjs +49 -0
- package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -0
- package/dist/esm/polyfill/RTCError.mjs +79 -0
- package/dist/esm/polyfill/RTCError.mjs.map +1 -0
- package/dist/esm/polyfill/RTCIceCandidate.mjs +128 -0
- package/dist/esm/polyfill/RTCIceCandidate.mjs.map +1 -0
- package/dist/esm/polyfill/RTCIceTransport.mjs +89 -0
- package/dist/esm/polyfill/RTCIceTransport.mjs.map +1 -0
- package/dist/esm/polyfill/RTCPeerConnection.mjs +430 -0
- package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -0
- package/dist/esm/polyfill/RTCSctpTransport.mjs +55 -0
- package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -0
- package/dist/esm/polyfill/RTCSessionDescription.mjs +41 -0
- package/dist/esm/polyfill/RTCSessionDescription.mjs.map +1 -0
- package/dist/esm/polyfill/index.mjs +27 -0
- package/dist/esm/polyfill/index.mjs.map +1 -0
- package/dist/types/lib/datachannel-stream.d.ts +24 -0
- package/dist/types/lib/index.d.ts +235 -0
- package/dist/types/lib/types.d.ts +118 -0
- package/dist/types/lib/websocket-server.d.ts +13 -0
- package/dist/types/lib/websocket.d.ts +25 -0
- package/dist/types/polyfill/Events.d.ts +15 -0
- package/dist/types/polyfill/RTCCertificate.d.ts +9 -0
- package/dist/types/polyfill/RTCDataChannel.d.ts +29 -0
- package/dist/types/polyfill/RTCDtlsTransport.d.ts +15 -0
- package/dist/types/polyfill/RTCError.d.ts +17 -0
- package/dist/types/polyfill/RTCIceCandidate.d.ts +21 -0
- package/dist/types/polyfill/RTCIceTransport.d.ts +30 -0
- package/dist/types/polyfill/RTCPeerConnection.d.ts +64 -0
- package/dist/types/polyfill/RTCSctpTransport.d.ts +15 -0
- package/dist/types/polyfill/RTCSessionDescription.d.ts +10 -0
- package/dist/types/polyfill/index.d.ts +26 -0
- package/jest.config.ts +14 -0
- package/package.json +121 -0
- package/rollup.config.mjs +72 -0
- package/src/cpp/data-channel-wrapper.cpp +530 -0
- package/src/cpp/data-channel-wrapper.h +63 -0
- package/src/cpp/ice-udp-mux-listener-wrapper.cpp +157 -0
- package/src/cpp/ice-udp-mux-listener-wrapper.h +43 -0
- package/src/cpp/main.cpp +58 -0
- package/src/cpp/media-audio-wrapper.cpp +457 -0
- package/src/cpp/media-audio-wrapper.h +52 -0
- package/src/cpp/media-av1packetization.cpp +24 -0
- package/src/cpp/media-av1packetization.h +11 -0
- package/src/cpp/media-av1rtppacketizer-wrapper.cpp +126 -0
- package/src/cpp/media-av1rtppacketizer-wrapper.h +29 -0
- package/src/cpp/media-direction.cpp +43 -0
- package/src/cpp/media-direction.h +10 -0
- package/src/cpp/media-h264rtppacketizer-wrapper.cpp +126 -0
- package/src/cpp/media-h264rtppacketizer-wrapper.h +30 -0
- package/src/cpp/media-h265rtppacketizer-wrapper.cpp +126 -0
- package/src/cpp/media-h265rtppacketizer-wrapper.h +30 -0
- package/src/cpp/media-h26xseparator.cpp +32 -0
- package/src/cpp/media-h26xseparator.h +11 -0
- package/src/cpp/media-mediahandler-helper.cpp +31 -0
- package/src/cpp/media-mediahandler-helper.h +11 -0
- package/src/cpp/media-pacinghandler-wrapper.cpp +79 -0
- package/src/cpp/media-pacinghandler-wrapper.h +28 -0
- package/src/cpp/media-rtcpnackresponder-wrapper.cpp +68 -0
- package/src/cpp/media-rtcpnackresponder-wrapper.h +28 -0
- package/src/cpp/media-rtcpreceivingsession-wrapper.cpp +57 -0
- package/src/cpp/media-rtcpreceivingsession-wrapper.h +28 -0
- package/src/cpp/media-rtcpsrreporter-wrapper.cpp +93 -0
- package/src/cpp/media-rtcpsrreporter-wrapper.h +30 -0
- package/src/cpp/media-rtppacketizationconfig-wrapper.cpp +167 -0
- package/src/cpp/media-rtppacketizationconfig-wrapper.h +35 -0
- package/src/cpp/media-rtppacketizer-wrapper.cpp +95 -0
- package/src/cpp/media-rtppacketizer-wrapper.h +30 -0
- package/src/cpp/media-track-wrapper.cpp +458 -0
- package/src/cpp/media-track-wrapper.h +61 -0
- package/src/cpp/media-video-wrapper.cpp +526 -0
- package/src/cpp/media-video-wrapper.h +56 -0
- package/src/cpp/peer-connection-wrapper.cpp +1298 -0
- package/src/cpp/peer-connection-wrapper.h +89 -0
- package/src/cpp/rtc-wrapper.cpp +205 -0
- package/src/cpp/rtc-wrapper.h +24 -0
- package/src/cpp/thread-safe-callback.cpp +57 -0
- package/src/cpp/thread-safe-callback.h +47 -0
- package/src/cpp/web-socket-server-wrapper.cpp +275 -0
- package/src/cpp/web-socket-server-wrapper.h +41 -0
- package/src/cpp/web-socket-wrapper.cpp +796 -0
- package/src/cpp/web-socket-wrapper.h +63 -0
- package/src/index.ts +9 -0
- package/src/lib/datachannel-stream.ts +100 -0
- package/src/lib/index.ts +283 -0
- package/src/lib/node-datachannel.ts +3 -0
- package/src/lib/types.ts +168 -0
- package/src/lib/websocket-server.ts +37 -0
- package/src/lib/websocket.ts +26 -0
- package/src/polyfill/Events.ts +82 -0
- package/src/polyfill/Exception.ts +37 -0
- package/src/polyfill/README.md +41 -0
- package/src/polyfill/RTCCertificate.ts +21 -0
- package/src/polyfill/RTCDataChannel.ts +225 -0
- package/src/polyfill/RTCDtlsTransport.ts +46 -0
- package/src/polyfill/RTCError.ts +78 -0
- package/src/polyfill/RTCIceCandidate.ts +128 -0
- package/src/polyfill/RTCIceTransport.ts +90 -0
- package/src/polyfill/RTCPeerConnection.ts +527 -0
- package/src/polyfill/RTCSctpTransport.ts +51 -0
- package/src/polyfill/RTCSessionDescription.ts +41 -0
- package/src/polyfill/index.ts +38 -0
- package/tsconfig.json +21 -0
package/.clang-format
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
BasedOnStyle: LLVM
|
|
2
|
+
|
|
3
|
+
# Indentation
|
|
4
|
+
NamespaceIndentation: All
|
|
5
|
+
|
|
6
|
+
# Braces
|
|
7
|
+
BreakBeforeBraces: Allman
|
|
8
|
+
|
|
9
|
+
#include
|
|
10
|
+
SortIncludes: false
|
|
11
|
+
|
|
12
|
+
# Line Length
|
|
13
|
+
ColumnLimit: 120
|
|
14
|
+
|
|
15
|
+
# Line Breaks
|
|
16
|
+
AlwaysBreakTemplateDeclarations: true
|
|
17
|
+
LambdaBodyIndentation: OuterScope
|
package/.editorconfig
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
|
2
|
+
# coding styles between different editors and IDEs
|
|
3
|
+
# http://editorconfig.org
|
|
4
|
+
|
|
5
|
+
root = true
|
|
6
|
+
|
|
7
|
+
[*]
|
|
8
|
+
indent_style = space
|
|
9
|
+
end_of_line = lf
|
|
10
|
+
charset = utf-8
|
|
11
|
+
trim_trailing_whitespace = true
|
|
12
|
+
insert_final_newline = true
|
package/.eslintignore
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": false,
|
|
4
|
+
"es6": true,
|
|
5
|
+
"node": true
|
|
6
|
+
},
|
|
7
|
+
"parser": "@typescript-eslint/parser",
|
|
8
|
+
"parserOptions": {
|
|
9
|
+
"project": "tsconfig.json",
|
|
10
|
+
"sourceType": "module",
|
|
11
|
+
"ecmaVersion": 2020
|
|
12
|
+
},
|
|
13
|
+
"plugins": ["@typescript-eslint", "jest"],
|
|
14
|
+
"extends": [
|
|
15
|
+
"eslint:recommended",
|
|
16
|
+
"plugin:@typescript-eslint/recommended",
|
|
17
|
+
"plugin:jest/recommended",
|
|
18
|
+
"prettier"
|
|
19
|
+
],
|
|
20
|
+
"rules": {
|
|
21
|
+
// The following rule is enabled only to supplement the inline suppression
|
|
22
|
+
// examples, and because it is not a recommended rule, you should either
|
|
23
|
+
// disable it, or understand what it enforces.
|
|
24
|
+
// https://typescript-eslint.io/rules/explicit-function-return-type/
|
|
25
|
+
"@typescript-eslint/explicit-function-return-type": "warn"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/.gitmodules
ADDED
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/API.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# API
|
|
2
|
+
|
|
3
|
+
## PeerConnection Class
|
|
4
|
+
|
|
5
|
+
**Constructor**
|
|
6
|
+
|
|
7
|
+
let pc = new PeerConnection(peerName[,options])
|
|
8
|
+
|
|
9
|
+
- peerName `<string>` Peer name to use for logs etc..
|
|
10
|
+
- options `<Object>` WebRTC Config Options
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
export interface RtcConfig {
|
|
14
|
+
iceServers: (string | IceServer)[];
|
|
15
|
+
proxyServer?: ProxyServer;
|
|
16
|
+
bindAddress?: string;
|
|
17
|
+
enableIceTcp?: boolean;
|
|
18
|
+
enableIceUdpMux?: boolean;
|
|
19
|
+
disableAutoNegotiation?: boolean;
|
|
20
|
+
disableFingerprintVerification?: boolean;
|
|
21
|
+
disableAutoGathering?: boolean;
|
|
22
|
+
forceMediaTransport?: boolean;
|
|
23
|
+
portRangeBegin?: number;
|
|
24
|
+
portRangeEnd?: number;
|
|
25
|
+
maxMessageSize?: number;
|
|
26
|
+
mtu?: number;
|
|
27
|
+
iceTransportPolicy?: TransportPolicy;
|
|
28
|
+
disableFingerprintVerification?: boolean;
|
|
29
|
+
certificatePemFile?: string;
|
|
30
|
+
keyPemFile?: string;
|
|
31
|
+
keyPemPass?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const enum RelayType {
|
|
35
|
+
TurnUdp = 'TurnUdp',
|
|
36
|
+
TurnTcp = 'TurnTcp',
|
|
37
|
+
TurnTls = 'TurnTls'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface IceServer {
|
|
41
|
+
hostname: string;
|
|
42
|
+
port: number;
|
|
43
|
+
username?: string;
|
|
44
|
+
password?: string;
|
|
45
|
+
relayType?: RelayType;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type TransportPolicy = 'all' | 'relay';
|
|
49
|
+
|
|
50
|
+
"iceServers" option is an array of stun/turn server urls
|
|
51
|
+
Examples;
|
|
52
|
+
STUN Server Example : stun:stun.l.google.com:19302
|
|
53
|
+
TURN Server Example : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
|
|
54
|
+
TURN Server Example (TCP) : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT?transport=tcp
|
|
55
|
+
TURN Server Example (TLS) : turns:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**close: () => void**
|
|
60
|
+
|
|
61
|
+
Close Peer Connection
|
|
62
|
+
|
|
63
|
+
**destroy: () => void**
|
|
64
|
+
|
|
65
|
+
Close Peer Connection & Clear all callbacks
|
|
66
|
+
|
|
67
|
+
**setRemoteDescription: (sdp: string, type: DescriptionType) => void**
|
|
68
|
+
|
|
69
|
+
Set Remote Description
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
export const enum DescriptionType {
|
|
73
|
+
Unspec = 'Unspec',
|
|
74
|
+
Offer = 'Offer',
|
|
75
|
+
Answer = 'Answer'
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**setLocalDescription: (sdp: string, init?: LocalDescriptionInit) => void**
|
|
80
|
+
|
|
81
|
+
Set Local Description and optionally the ICE ufrag/pwd to use. These should not
|
|
82
|
+
be set as they will be generated automatically as per the spec.
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
export interface LocalDescriptionInit {
|
|
86
|
+
iceUfrag?: string;
|
|
87
|
+
icePwd?: string;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**remoteFingerprint: () => CertificateFingerprint**
|
|
92
|
+
|
|
93
|
+
Returns the certificate fingerprint used by the remote peer
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
export interface CertificateFingerprint {
|
|
97
|
+
value: string;
|
|
98
|
+
algorithm: 'sha-1' | 'sha-224' | 'sha-256' | 'sha-384' | 'sha-512' | 'md5' | 'md2';
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**addRemoteCandidate: (candidate: string, mid: string) => void**
|
|
103
|
+
|
|
104
|
+
Add remote candidate info
|
|
105
|
+
|
|
106
|
+
**createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel**
|
|
107
|
+
|
|
108
|
+
Create new data-channel
|
|
109
|
+
|
|
110
|
+
- label `<string>` Data channel name
|
|
111
|
+
- config `<Object>` Data channel options
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
export interface DataChannelInitConfig {
|
|
115
|
+
protocol?: string;
|
|
116
|
+
negotiated?: boolean;
|
|
117
|
+
id?: number;
|
|
118
|
+
unordered?: boolean; // Reliability
|
|
119
|
+
maxPacketLifeTime?: number; // Reliability
|
|
120
|
+
maxRetransmits?: number; // Reliability
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**state: () => string**
|
|
125
|
+
|
|
126
|
+
Get current state
|
|
127
|
+
|
|
128
|
+
**signalingState: () => string**
|
|
129
|
+
|
|
130
|
+
Get current signaling state
|
|
131
|
+
|
|
132
|
+
**gatheringState: () => string**
|
|
133
|
+
|
|
134
|
+
Get current gathering state
|
|
135
|
+
|
|
136
|
+
**onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void**
|
|
137
|
+
|
|
138
|
+
Local Description Callback
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
export const enum DescriptionType {
|
|
142
|
+
Unspec = 'Unspec',
|
|
143
|
+
Offer = 'Offer',
|
|
144
|
+
Answer = 'Answer'
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**onLocalCandidate: (cb: (candidate: string, mid: string) => void) => void**
|
|
149
|
+
|
|
150
|
+
Local Candidate Callback
|
|
151
|
+
|
|
152
|
+
**onStateChange: (cb: (state: string) => void) => void**
|
|
153
|
+
|
|
154
|
+
State Change Callback
|
|
155
|
+
|
|
156
|
+
**onSignalingStateChange: (state: (sdp: string) => void) => void**
|
|
157
|
+
|
|
158
|
+
Signaling State Change Callback
|
|
159
|
+
|
|
160
|
+
**onGatheringStateChange: (state: (sdp: string) => void) => void**
|
|
161
|
+
|
|
162
|
+
Gathering State Change Callback
|
|
163
|
+
|
|
164
|
+
**onDataChannel: (cb: (dc: DataChannel) => void) => void**
|
|
165
|
+
|
|
166
|
+
New Data Channel Callback
|
|
167
|
+
|
|
168
|
+
**bytesSent: () => number**
|
|
169
|
+
|
|
170
|
+
Get bytes sent stat
|
|
171
|
+
|
|
172
|
+
**bytesReceived: () => number**
|
|
173
|
+
|
|
174
|
+
Get bytes received stat
|
|
175
|
+
|
|
176
|
+
**rtt: () => number**
|
|
177
|
+
|
|
178
|
+
Get rtt stat
|
|
179
|
+
|
|
180
|
+
**getSelectedCandidatePair: () => { local: SelectedCandidateInfo, remote: SelectedCandidateInfo }**
|
|
181
|
+
|
|
182
|
+
Get info about selected candidate pair
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
export interface SelectedCandidateInfo {
|
|
186
|
+
address: string;
|
|
187
|
+
port: number;
|
|
188
|
+
type: string;
|
|
189
|
+
transportType: string;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## DataChannel Class
|
|
194
|
+
|
|
195
|
+
> You can create a new Datachannel instance by calling `PeerConnection.createDataChannel` function.
|
|
196
|
+
|
|
197
|
+
**close: () => void**
|
|
198
|
+
|
|
199
|
+
Close data channel
|
|
200
|
+
|
|
201
|
+
**getLabel: () => string**
|
|
202
|
+
|
|
203
|
+
Get label of data-channel
|
|
204
|
+
|
|
205
|
+
**sendMessage: (msg: string) => boolean**
|
|
206
|
+
|
|
207
|
+
Send Message as string
|
|
208
|
+
|
|
209
|
+
**sendMessageBinary: (buffer: Buffer) => boolean**
|
|
210
|
+
|
|
211
|
+
Send Message as binary
|
|
212
|
+
|
|
213
|
+
**isOpen: () => boolean**
|
|
214
|
+
|
|
215
|
+
Query data-channel
|
|
216
|
+
|
|
217
|
+
**bufferedAmount: () => number**
|
|
218
|
+
|
|
219
|
+
Get current buffered amount level
|
|
220
|
+
|
|
221
|
+
**maxMessageSize: () => number**
|
|
222
|
+
|
|
223
|
+
Get max message size of the data-channel, that could be sent
|
|
224
|
+
|
|
225
|
+
**setBufferedAmountLowThreshold: (newSize: number) => void**
|
|
226
|
+
|
|
227
|
+
Set buffer level of the `onBufferedAmountLow` callback
|
|
228
|
+
|
|
229
|
+
**onOpen: (cb: () => void) => void**
|
|
230
|
+
|
|
231
|
+
Open callback
|
|
232
|
+
|
|
233
|
+
**onClosed: (cb: () => void) => void**
|
|
234
|
+
|
|
235
|
+
Closed callback
|
|
236
|
+
|
|
237
|
+
**onError: (cb: (err: string) => void) => void**
|
|
238
|
+
|
|
239
|
+
Error callback
|
|
240
|
+
|
|
241
|
+
**onBufferedAmountLow: (cb: () => void) => void**
|
|
242
|
+
|
|
243
|
+
Buffer level low callback
|
|
244
|
+
|
|
245
|
+
**onMessage: (cb: (msg: string | Buffer) => void) => void**
|
|
246
|
+
|
|
247
|
+
New Message callback
|
package/BULDING.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Build
|
|
2
|
+
|
|
3
|
+
## Requirements
|
|
4
|
+
|
|
5
|
+
- cmake >= V3.21
|
|
6
|
+
- [libdatachannel dependencies](https://github.com/paullouisageneau/libdatachannel/blob/master/README.md#dependencies)
|
|
7
|
+
|
|
8
|
+
## Building from source
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
> git clone https://github.com/murat-dogan/node-datachannel.git
|
|
12
|
+
> cd node-datachannel
|
|
13
|
+
> npm i
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Other Options
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
# Use GnuTLS instead of OpenSSL (Default False)
|
|
20
|
+
> npm run install-gnu-tls
|
|
21
|
+
|
|
22
|
+
# Use libnice instead of libjuice (Default False)
|
|
23
|
+
# libnice-dev packet should be installed. (eg. sudo apt install libnice-dev)
|
|
24
|
+
> npm run install-nice
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Compile without Media and Websocket
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npx cmake-js clean
|
|
31
|
+
npx cmake-js configure --CDNO_MEDIA=ON --CDNO_WEBSOCKET=ON
|
|
32
|
+
npx cmake-js build
|
|
33
|
+
```
|
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.15)
|
|
2
|
+
cmake_policy(SET CMP0091 NEW)
|
|
3
|
+
cmake_policy(SET CMP0042 NEW)
|
|
4
|
+
|
|
5
|
+
project(node_datachannel VERSION 0.31.0)
|
|
6
|
+
|
|
7
|
+
# compile_commands.json
|
|
8
|
+
# -----------------------------------
|
|
9
|
+
set(CMAKE_EXPORT_COMPILE_COMMANDS True)
|
|
10
|
+
|
|
11
|
+
# -Dnapi_build_version=8
|
|
12
|
+
add_definitions(-DNAPI_VERSION=8)
|
|
13
|
+
|
|
14
|
+
include_directories(${CMAKE_JS_INC})
|
|
15
|
+
|
|
16
|
+
if(WIN32)
|
|
17
|
+
set(OPENSSL_MSVC_STATIC_RT TRUE)
|
|
18
|
+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
19
|
+
endif()
|
|
20
|
+
|
|
21
|
+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
|
|
22
|
+
set(CMAKE_C_FLAGS "-Wno-error=unused-but-set-variable -Wno-error=strict-prototypes")
|
|
23
|
+
endif()
|
|
24
|
+
|
|
25
|
+
# Add -frtti only for Linux and macOS
|
|
26
|
+
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
|
27
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
|
|
28
|
+
endif()
|
|
29
|
+
|
|
30
|
+
set(OPENSSL_USE_STATIC_LIBS TRUE)
|
|
31
|
+
find_package(OpenSSL REQUIRED)
|
|
32
|
+
|
|
33
|
+
include(FetchContent)
|
|
34
|
+
|
|
35
|
+
# Fetch libdatachannel
|
|
36
|
+
FetchContent_Declare(
|
|
37
|
+
libdatachannel
|
|
38
|
+
GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
|
|
39
|
+
GIT_TAG "v0.24.0"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
|
|
43
|
+
option(NO_WEBSOCKET "Disable WebSocket support in libdatachannel" OFF)
|
|
44
|
+
|
|
45
|
+
set(FETCHCONTENT_QUIET OFF)
|
|
46
|
+
FetchContent_GetProperties(libdatachannel)
|
|
47
|
+
|
|
48
|
+
if(NOT libdatachannel)
|
|
49
|
+
FetchContent_Populate(libdatachannel)
|
|
50
|
+
add_subdirectory(${libdatachannel_SOURCE_DIR} ${libdatachannel_BINARY_DIR} EXCLUDE_FROM_ALL)
|
|
51
|
+
endif()
|
|
52
|
+
|
|
53
|
+
# Create Source File List
|
|
54
|
+
set(SRC_FILES
|
|
55
|
+
src/cpp/rtc-wrapper.cpp
|
|
56
|
+
src/cpp/data-channel-wrapper.cpp
|
|
57
|
+
src/cpp/ice-udp-mux-listener-wrapper.cpp
|
|
58
|
+
src/cpp/peer-connection-wrapper.cpp
|
|
59
|
+
src/cpp/thread-safe-callback.cpp
|
|
60
|
+
src/cpp/main.cpp
|
|
61
|
+
${CMAKE_JS_SRC}
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
if(NOT NO_MEDIA)
|
|
65
|
+
list(APPEND SRC_FILES
|
|
66
|
+
src/cpp/media-av1packetization.cpp
|
|
67
|
+
src/cpp/media-av1rtppacketizer-wrapper.cpp
|
|
68
|
+
src/cpp/media-direction.cpp
|
|
69
|
+
src/cpp/media-h26xseparator.cpp
|
|
70
|
+
src/cpp/media-h264rtppacketizer-wrapper.cpp
|
|
71
|
+
src/cpp/media-h265rtppacketizer-wrapper.cpp
|
|
72
|
+
src/cpp/media-mediahandler-helper.cpp
|
|
73
|
+
src/cpp/media-pacinghandler-wrapper.cpp
|
|
74
|
+
src/cpp/media-rtcpnackresponder-wrapper.cpp
|
|
75
|
+
src/cpp/media-rtcpreceivingsession-wrapper.cpp
|
|
76
|
+
src/cpp/media-rtcpsrreporter-wrapper.cpp
|
|
77
|
+
src/cpp/media-rtppacketizationconfig-wrapper.cpp
|
|
78
|
+
src/cpp/media-rtppacketizer-wrapper.cpp
|
|
79
|
+
src/cpp/media-track-wrapper.cpp
|
|
80
|
+
src/cpp/media-audio-wrapper.cpp
|
|
81
|
+
src/cpp/media-video-wrapper.cpp
|
|
82
|
+
)
|
|
83
|
+
endif()
|
|
84
|
+
|
|
85
|
+
if(NOT NO_WEBSOCKET)
|
|
86
|
+
list(APPEND SRC_FILES
|
|
87
|
+
src/cpp/web-socket-wrapper.cpp
|
|
88
|
+
src/cpp/web-socket-server-wrapper.cpp
|
|
89
|
+
)
|
|
90
|
+
endif()
|
|
91
|
+
|
|
92
|
+
add_library(${PROJECT_NAME} SHARED ${SRC_FILES})
|
|
93
|
+
|
|
94
|
+
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
|
|
95
|
+
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
|
|
96
|
+
|
|
97
|
+
# Set the output directory for all build types
|
|
98
|
+
# set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
99
|
+
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/binary
|
|
100
|
+
# LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/binary
|
|
101
|
+
# ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/binary
|
|
102
|
+
# )
|
|
103
|
+
|
|
104
|
+
target_include_directories(${PROJECT_NAME} PRIVATE
|
|
105
|
+
${CMAKE_SOURCE_DIR}/node_modules/node-addon-api
|
|
106
|
+
${CMAKE_BINARY_DIR}/_deps/libdatachannel-src/include
|
|
107
|
+
${CMAKE_BINARY_DIR}/_deps/libdatachannel-src/deps/plog
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
set(LINK_LIBRARIES
|
|
111
|
+
${CMAKE_JS_LIB}
|
|
112
|
+
datachannel-static
|
|
113
|
+
plog::plog
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
if(APPLE)
|
|
117
|
+
#
|
|
118
|
+
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
|
|
119
|
+
list(APPEND LINK_LIBRARIES -static-libgcc)
|
|
120
|
+
elseif(UNIX)
|
|
121
|
+
list(APPEND LINK_LIBRARIES -static-libgcc -static-libstdc++)
|
|
122
|
+
endif()
|
|
123
|
+
|
|
124
|
+
if(WIN32)
|
|
125
|
+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
|
|
126
|
+
list(APPEND LINK_LIBRARIES crypt32.lib)
|
|
127
|
+
endif()
|
|
128
|
+
|
|
129
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE ${LINK_LIBRARIES})
|
|
130
|
+
|
|
131
|
+
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
|
|
132
|
+
# Generate node.lib
|
|
133
|
+
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
|
|
134
|
+
endif()
|