node-datachannel 0.2.4 → 0.3.2
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/.editorconfig +12 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +8 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/build-linux.yml +3 -3
- package/.github/workflows/build-mac.yml +1 -1
- package/.github/workflows/build-win.yml +4 -4
- package/.github/workflows/lint.yml +22 -0
- package/.prettierrc.js +7 -0
- package/CMakeLists.txt +8 -2
- package/README.md +4 -4
- package/examples/client-server/client-benchmark.js +43 -32
- package/examples/client-server/client-periodic.js +30 -14
- package/examples/client-server/client.js +6 -5
- package/examples/client-server/package-lock.json +183 -44
- package/examples/client-server/signaling-server.js +3 -5
- package/examples/media/media.js +9 -9
- package/lib/datachannel-stream.js +23 -12
- package/lib/index.d.ts +113 -116
- package/lib/index.js +3 -2
- package/node_modules/detect-libc/package.json +1 -0
- package/node_modules/lru-cache/package.json +1 -2
- package/node_modules/minimist/index.js +6 -2
- package/node_modules/minimist/package.json +10 -11
- package/node_modules/minimist/readme.markdown +4 -1
- package/node_modules/minimist/test/proto.js +16 -0
- package/node_modules/node-abi/node_modules/semver/README.md +3 -1
- package/node_modules/node-abi/node_modules/semver/bin/semver.js +19 -9
- package/node_modules/node-abi/node_modules/semver/classes/comparator.js +3 -2
- package/node_modules/node-abi/node_modules/semver/classes/index.js +1 -1
- package/node_modules/node-abi/node_modules/semver/classes/range.js +31 -22
- package/node_modules/node-abi/node_modules/semver/classes/semver.js +1 -1
- package/node_modules/node-abi/node_modules/semver/functions/cmp.js +8 -4
- package/node_modules/node-abi/node_modules/semver/functions/coerce.js +3 -2
- package/node_modules/node-abi/node_modules/semver/functions/inc.js +4 -1
- package/node_modules/node-abi/node_modules/semver/functions/parse.js +1 -1
- package/node_modules/node-abi/node_modules/semver/internal/constants.js +2 -2
- package/node_modules/node-abi/node_modules/semver/internal/identifiers.js +1 -1
- package/node_modules/node-abi/node_modules/semver/internal/parse-options.js +3 -3
- package/node_modules/node-abi/node_modules/semver/internal/re.js +3 -3
- package/node_modules/node-abi/node_modules/semver/package.json +51 -18
- package/node_modules/node-abi/node_modules/semver/ranges/min-version.js +2 -1
- package/node_modules/node-abi/node_modules/semver/ranges/outside.js +1 -1
- package/node_modules/node-abi/node_modules/semver/ranges/simplify.js +15 -12
- package/node_modules/node-abi/node_modules/semver/ranges/subset.js +53 -31
- package/node_modules/node-abi/package.json +1 -0
- package/node_modules/npmlog/node_modules/are-we-there-yet/package.json +10 -10
- package/node_modules/npmlog/package.json +1 -1
- package/node_modules/tar-stream/node_modules/bl/.travis.yml +4 -3
- package/node_modules/tar-stream/node_modules/bl/BufferList.js +1 -1
- package/node_modules/tar-stream/node_modules/bl/package.json +10 -10
- package/node_modules/tar-stream/node_modules/bl/test/test.js +20 -2
- package/node_modules/wide-align/LICENSE +0 -0
- package/node_modules/wide-align/README.md +0 -0
- package/node_modules/wide-align/align.js +0 -0
- package/node_modules/wide-align/package.json +14 -14
- package/package.json +12 -4
- package/src/data-channel-wrapper.cpp +90 -40
- package/src/data-channel-wrapper.h +2 -0
- package/src/media-audio-wrapper.cpp +5 -5
- package/src/media-track-wrapper.cpp +96 -38
- package/src/media-track-wrapper.h +1 -0
- package/src/media-video-wrapper.cpp +5 -5
- package/src/peer-connection-wrapper.cpp +111 -54
- package/test/connectivity.js +22 -21
- package/test/test.js +25 -33
- package/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -111
|
@@ -1,26 +1,192 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "client",
|
|
3
3
|
"version": "1.0.0",
|
|
4
|
-
"lockfileVersion":
|
|
4
|
+
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "client",
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"ws": "^7.5.3",
|
|
13
|
+
"yargs": "^16.2.0"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"node_modules/ansi-regex": {
|
|
17
|
+
"version": "5.0.0",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=8"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"node_modules/ansi-styles": {
|
|
24
|
+
"version": "4.3.0",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"color-convert": "^2.0.1"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=8"
|
|
31
|
+
},
|
|
32
|
+
"funding": {
|
|
33
|
+
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"node_modules/cliui": {
|
|
37
|
+
"version": "7.0.4",
|
|
38
|
+
"license": "ISC",
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"string-width": "^4.2.0",
|
|
41
|
+
"strip-ansi": "^6.0.0",
|
|
42
|
+
"wrap-ansi": "^7.0.0"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"node_modules/color-convert": {
|
|
46
|
+
"version": "2.0.1",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"color-name": "~1.1.4"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=7.0.0"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"node_modules/color-name": {
|
|
56
|
+
"version": "1.1.4",
|
|
57
|
+
"license": "MIT"
|
|
58
|
+
},
|
|
59
|
+
"node_modules/emoji-regex": {
|
|
60
|
+
"version": "8.0.0",
|
|
61
|
+
"license": "MIT"
|
|
62
|
+
},
|
|
63
|
+
"node_modules/escalade": {
|
|
64
|
+
"version": "3.1.1",
|
|
65
|
+
"license": "MIT",
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=6"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"node_modules/get-caller-file": {
|
|
71
|
+
"version": "2.0.5",
|
|
72
|
+
"license": "ISC",
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": "6.* || 8.* || >= 10.*"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"node_modules/is-fullwidth-code-point": {
|
|
78
|
+
"version": "3.0.0",
|
|
79
|
+
"license": "MIT",
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=8"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"node_modules/require-directory": {
|
|
85
|
+
"version": "2.1.1",
|
|
86
|
+
"license": "MIT",
|
|
87
|
+
"engines": {
|
|
88
|
+
"node": ">=0.10.0"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"node_modules/string-width": {
|
|
92
|
+
"version": "4.2.2",
|
|
93
|
+
"license": "MIT",
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"emoji-regex": "^8.0.0",
|
|
96
|
+
"is-fullwidth-code-point": "^3.0.0",
|
|
97
|
+
"strip-ansi": "^6.0.0"
|
|
98
|
+
},
|
|
99
|
+
"engines": {
|
|
100
|
+
"node": ">=8"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"node_modules/strip-ansi": {
|
|
104
|
+
"version": "6.0.0",
|
|
105
|
+
"license": "MIT",
|
|
106
|
+
"dependencies": {
|
|
107
|
+
"ansi-regex": "^5.0.0"
|
|
108
|
+
},
|
|
109
|
+
"engines": {
|
|
110
|
+
"node": ">=8"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"node_modules/wrap-ansi": {
|
|
114
|
+
"version": "7.0.0",
|
|
115
|
+
"license": "MIT",
|
|
116
|
+
"dependencies": {
|
|
117
|
+
"ansi-styles": "^4.0.0",
|
|
118
|
+
"string-width": "^4.1.0",
|
|
119
|
+
"strip-ansi": "^6.0.0"
|
|
120
|
+
},
|
|
121
|
+
"engines": {
|
|
122
|
+
"node": ">=10"
|
|
123
|
+
},
|
|
124
|
+
"funding": {
|
|
125
|
+
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"node_modules/ws": {
|
|
129
|
+
"version": "7.5.3",
|
|
130
|
+
"license": "MIT",
|
|
131
|
+
"engines": {
|
|
132
|
+
"node": ">=8.3.0"
|
|
133
|
+
},
|
|
134
|
+
"peerDependencies": {
|
|
135
|
+
"bufferutil": "^4.0.1",
|
|
136
|
+
"utf-8-validate": "^5.0.2"
|
|
137
|
+
},
|
|
138
|
+
"peerDependenciesMeta": {
|
|
139
|
+
"bufferutil": {
|
|
140
|
+
"optional": true
|
|
141
|
+
},
|
|
142
|
+
"utf-8-validate": {
|
|
143
|
+
"optional": true
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"node_modules/y18n": {
|
|
148
|
+
"version": "5.0.8",
|
|
149
|
+
"license": "ISC",
|
|
150
|
+
"engines": {
|
|
151
|
+
"node": ">=10"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"node_modules/yargs": {
|
|
155
|
+
"version": "16.2.0",
|
|
156
|
+
"license": "MIT",
|
|
157
|
+
"dependencies": {
|
|
158
|
+
"cliui": "^7.0.2",
|
|
159
|
+
"escalade": "^3.1.1",
|
|
160
|
+
"get-caller-file": "^2.0.5",
|
|
161
|
+
"require-directory": "^2.1.1",
|
|
162
|
+
"string-width": "^4.2.0",
|
|
163
|
+
"y18n": "^5.0.5",
|
|
164
|
+
"yargs-parser": "^20.2.2"
|
|
165
|
+
},
|
|
166
|
+
"engines": {
|
|
167
|
+
"node": ">=10"
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
"node_modules/yargs-parser": {
|
|
171
|
+
"version": "20.2.7",
|
|
172
|
+
"license": "ISC",
|
|
173
|
+
"engines": {
|
|
174
|
+
"node": ">=10"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
6
178
|
"dependencies": {
|
|
7
179
|
"ansi-regex": {
|
|
8
|
-
"version": "5.0.0"
|
|
9
|
-
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
|
10
|
-
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
|
|
180
|
+
"version": "5.0.0"
|
|
11
181
|
},
|
|
12
182
|
"ansi-styles": {
|
|
13
183
|
"version": "4.3.0",
|
|
14
|
-
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
|
15
|
-
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
|
16
184
|
"requires": {
|
|
17
185
|
"color-convert": "^2.0.1"
|
|
18
186
|
}
|
|
19
187
|
},
|
|
20
188
|
"cliui": {
|
|
21
189
|
"version": "7.0.4",
|
|
22
|
-
"resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz",
|
|
23
|
-
"integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==",
|
|
24
190
|
"requires": {
|
|
25
191
|
"string-width": "^4.2.0",
|
|
26
192
|
"strip-ansi": "^6.0.0",
|
|
@@ -29,46 +195,30 @@
|
|
|
29
195
|
},
|
|
30
196
|
"color-convert": {
|
|
31
197
|
"version": "2.0.1",
|
|
32
|
-
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
|
33
|
-
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
|
34
198
|
"requires": {
|
|
35
199
|
"color-name": "~1.1.4"
|
|
36
200
|
}
|
|
37
201
|
},
|
|
38
202
|
"color-name": {
|
|
39
|
-
"version": "1.1.4"
|
|
40
|
-
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
|
41
|
-
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
|
203
|
+
"version": "1.1.4"
|
|
42
204
|
},
|
|
43
205
|
"emoji-regex": {
|
|
44
|
-
"version": "8.0.0"
|
|
45
|
-
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
|
46
|
-
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="
|
|
206
|
+
"version": "8.0.0"
|
|
47
207
|
},
|
|
48
208
|
"escalade": {
|
|
49
|
-
"version": "3.1.1"
|
|
50
|
-
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
|
|
51
|
-
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw=="
|
|
209
|
+
"version": "3.1.1"
|
|
52
210
|
},
|
|
53
211
|
"get-caller-file": {
|
|
54
|
-
"version": "2.0.5"
|
|
55
|
-
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
|
56
|
-
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="
|
|
212
|
+
"version": "2.0.5"
|
|
57
213
|
},
|
|
58
214
|
"is-fullwidth-code-point": {
|
|
59
|
-
"version": "3.0.0"
|
|
60
|
-
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
|
61
|
-
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="
|
|
215
|
+
"version": "3.0.0"
|
|
62
216
|
},
|
|
63
217
|
"require-directory": {
|
|
64
|
-
"version": "2.1.1"
|
|
65
|
-
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
|
66
|
-
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I="
|
|
218
|
+
"version": "2.1.1"
|
|
67
219
|
},
|
|
68
220
|
"string-width": {
|
|
69
221
|
"version": "4.2.2",
|
|
70
|
-
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz",
|
|
71
|
-
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
|
|
72
222
|
"requires": {
|
|
73
223
|
"emoji-regex": "^8.0.0",
|
|
74
224
|
"is-fullwidth-code-point": "^3.0.0",
|
|
@@ -77,16 +227,12 @@
|
|
|
77
227
|
},
|
|
78
228
|
"strip-ansi": {
|
|
79
229
|
"version": "6.0.0",
|
|
80
|
-
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
|
81
|
-
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
|
|
82
230
|
"requires": {
|
|
83
231
|
"ansi-regex": "^5.0.0"
|
|
84
232
|
}
|
|
85
233
|
},
|
|
86
234
|
"wrap-ansi": {
|
|
87
235
|
"version": "7.0.0",
|
|
88
|
-
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
|
89
|
-
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
|
90
236
|
"requires": {
|
|
91
237
|
"ansi-styles": "^4.0.0",
|
|
92
238
|
"string-width": "^4.1.0",
|
|
@@ -95,18 +241,13 @@
|
|
|
95
241
|
},
|
|
96
242
|
"ws": {
|
|
97
243
|
"version": "7.5.3",
|
|
98
|
-
"
|
|
99
|
-
"integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg=="
|
|
244
|
+
"requires": {}
|
|
100
245
|
},
|
|
101
246
|
"y18n": {
|
|
102
|
-
"version": "5.0.8"
|
|
103
|
-
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
|
104
|
-
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="
|
|
247
|
+
"version": "5.0.8"
|
|
105
248
|
},
|
|
106
249
|
"yargs": {
|
|
107
250
|
"version": "16.2.0",
|
|
108
|
-
"resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
|
|
109
|
-
"integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==",
|
|
110
251
|
"requires": {
|
|
111
252
|
"cliui": "^7.0.2",
|
|
112
253
|
"escalade": "^3.1.1",
|
|
@@ -118,9 +259,7 @@
|
|
|
118
259
|
}
|
|
119
260
|
},
|
|
120
261
|
"yargs-parser": {
|
|
121
|
-
"version": "20.2.7"
|
|
122
|
-
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.7.tgz",
|
|
123
|
-
"integrity": "sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw=="
|
|
262
|
+
"version": "20.2.7"
|
|
124
263
|
}
|
|
125
264
|
}
|
|
126
265
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
1
2
|
const WebSocket = require('ws');
|
|
2
3
|
|
|
3
4
|
const clients = {};
|
|
@@ -5,7 +6,7 @@ const clients = {};
|
|
|
5
6
|
const wss = new WebSocket.Server({ port: 8000 });
|
|
6
7
|
|
|
7
8
|
wss.on('connection', (ws, req) => {
|
|
8
|
-
const id = req.url.replace('/', '')
|
|
9
|
+
const id = req.url.replace('/', '');
|
|
9
10
|
console.log(`New Connection from ${id}`);
|
|
10
11
|
|
|
11
12
|
clients[id] = ws;
|
|
@@ -15,12 +16,10 @@ wss.on('connection', (ws, req) => {
|
|
|
15
16
|
let peerWs = clients[peerId];
|
|
16
17
|
|
|
17
18
|
console.log(`Message from ${id} to ${peerId} : ${buffer}`);
|
|
18
|
-
if (!peerWs)
|
|
19
|
-
return console.error(`Can not find peer with ID ${peerId}`);
|
|
19
|
+
if (!peerWs) return console.error(`Can not find peer with ID ${peerId}`);
|
|
20
20
|
|
|
21
21
|
msg.id = id;
|
|
22
22
|
peerWs.send(JSON.stringify(msg));
|
|
23
|
-
|
|
24
23
|
});
|
|
25
24
|
|
|
26
25
|
ws.on('close', () => {
|
|
@@ -28,4 +27,3 @@ wss.on('connection', (ws, req) => {
|
|
|
28
27
|
delete clients[id];
|
|
29
28
|
});
|
|
30
29
|
});
|
|
31
|
-
|
package/examples/media/media.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
1
2
|
const nodeDataChannel = require('../../lib/index');
|
|
2
|
-
const readline = require(
|
|
3
|
+
const readline = require('readline');
|
|
3
4
|
var dgram = require('dgram');
|
|
4
5
|
|
|
5
6
|
var client = dgram.createSocket('udp4');
|
|
@@ -7,7 +8,7 @@ var client = dgram.createSocket('udp4');
|
|
|
7
8
|
// Read Line Interface
|
|
8
9
|
const rl = readline.createInterface({
|
|
9
10
|
input: process.stdin,
|
|
10
|
-
output: process.stdout
|
|
11
|
+
output: process.stdout,
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
// Init Logger
|
|
@@ -21,7 +22,7 @@ peerConnection.onStateChange((state) => {
|
|
|
21
22
|
peerConnection.onGatheringStateChange((state) => {
|
|
22
23
|
// console.log('GatheringState: ', state);
|
|
23
24
|
|
|
24
|
-
if(state == 'complete'){
|
|
25
|
+
if (state == 'complete') {
|
|
25
26
|
let desc = peerConnection.localDescription();
|
|
26
27
|
console.log('');
|
|
27
28
|
console.log('## Please copy the offer below to the web page:');
|
|
@@ -31,14 +32,13 @@ peerConnection.onGatheringStateChange((state) => {
|
|
|
31
32
|
rl.question('## Please copy/paste the answer provided by the browser: \n', (sdp) => {
|
|
32
33
|
let sdpObj = JSON.parse(sdp);
|
|
33
34
|
peerConnection.setRemoteDescription(sdpObj.sdp, sdpObj.type);
|
|
34
|
-
console.log(track.isOpen())
|
|
35
|
+
console.log(track.isOpen());
|
|
35
36
|
rl.close();
|
|
36
|
-
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
let video = new nodeDataChannel.Video('video','RecvOnly');
|
|
41
|
+
let video = new nodeDataChannel.Video('video', 'RecvOnly');
|
|
42
42
|
video.addH264Codec(96);
|
|
43
43
|
video.setBitrate(3000);
|
|
44
44
|
|
|
@@ -46,9 +46,9 @@ let track = peerConnection.addTrack(video);
|
|
|
46
46
|
let session = new nodeDataChannel.RtcpReceivingSession();
|
|
47
47
|
|
|
48
48
|
track.setMediaHandler(session);
|
|
49
|
-
track.onMessage((msg)=>{
|
|
50
|
-
client.send(msg,5000,'127.0.0.1',(err,n)=>{
|
|
51
|
-
if(err) console.log(err,n);
|
|
49
|
+
track.onMessage((msg) => {
|
|
50
|
+
client.send(msg, 5000, '127.0.0.1', (err, n) => {
|
|
51
|
+
if (err) console.log(err, n);
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1
2
|
const stream = require('stream');
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -9,12 +10,11 @@ const stream = require('stream');
|
|
|
9
10
|
* the protocol level, and is preserved here throughout.
|
|
10
11
|
*/
|
|
11
12
|
module.exports = class DataChannelStream extends stream.Duplex {
|
|
12
|
-
|
|
13
13
|
constructor(rawChannel, streamOptions) {
|
|
14
14
|
super({
|
|
15
15
|
allowHalfOpen: false, // Default to autoclose on end().
|
|
16
16
|
...streamOptions,
|
|
17
|
-
objectMode: true // Preserve the string/buffer distinction (WebRTC treats them differently)
|
|
17
|
+
objectMode: true, // Preserve the string/buffer distinction (WebRTC treats them differently)
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
this._rawChannel = rawChannel;
|
|
@@ -51,20 +51,24 @@ module.exports = class DataChannelStream extends stream.Duplex {
|
|
|
51
51
|
|
|
52
52
|
_write(chunk, encoding, callback) {
|
|
53
53
|
let sentOk;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
if (Buffer.isBuffer(chunk)) {
|
|
57
|
+
sentOk = this._rawChannel.sendMessageBinary(chunk);
|
|
58
|
+
} else if (typeof chunk === 'string') {
|
|
59
|
+
sentOk = this._rawChannel.sendMessage(chunk);
|
|
60
|
+
} else {
|
|
61
|
+
const typeName = chunk.constructor.name || typeof chunk;
|
|
62
|
+
throw new Error(`Cannot write ${typeName} to DataChannel stream`);
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
return callback(err);
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
if (sentOk) {
|
|
65
69
|
callback(null);
|
|
66
70
|
} else {
|
|
67
|
-
callback(new Error(
|
|
71
|
+
callback(new Error('Failed to write to DataChannel'));
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
|
|
@@ -83,4 +87,11 @@ module.exports = class DataChannelStream extends stream.Duplex {
|
|
|
83
87
|
return this._rawChannel.getLabel();
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
|
|
90
|
+
get id() {
|
|
91
|
+
return this._rawChannel.getId();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get protocol() {
|
|
95
|
+
return this._rawChannel.getProtocol();
|
|
96
|
+
}
|
|
97
|
+
};
|