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,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
|
-
"are-we-there-yet@1.1.
|
|
4
|
+
"are-we-there-yet@1.1.7",
|
|
5
5
|
"/home/runner/work/node-datachannel/node-datachannel"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
|
-
"_from": "are-we-there-yet@1.1.
|
|
9
|
-
"_id": "are-we-there-yet@1.1.
|
|
8
|
+
"_from": "are-we-there-yet@1.1.7",
|
|
9
|
+
"_id": "are-we-there-yet@1.1.7",
|
|
10
10
|
"_inBundle": false,
|
|
11
|
-
"_integrity": "sha512-
|
|
11
|
+
"_integrity": "sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==",
|
|
12
12
|
"_location": "/npmlog/are-we-there-yet",
|
|
13
13
|
"_phantomChildren": {},
|
|
14
14
|
"_requested": {
|
|
15
15
|
"type": "version",
|
|
16
16
|
"registry": true,
|
|
17
|
-
"raw": "are-we-there-yet@1.1.
|
|
17
|
+
"raw": "are-we-there-yet@1.1.7",
|
|
18
18
|
"name": "are-we-there-yet",
|
|
19
19
|
"escapedName": "are-we-there-yet",
|
|
20
|
-
"rawSpec": "1.1.
|
|
20
|
+
"rawSpec": "1.1.7",
|
|
21
21
|
"saveSpec": null,
|
|
22
|
-
"fetchSpec": "1.1.
|
|
22
|
+
"fetchSpec": "1.1.7"
|
|
23
23
|
},
|
|
24
24
|
"_requiredBy": [
|
|
25
25
|
"/npmlog"
|
|
26
26
|
],
|
|
27
|
-
"_resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.
|
|
28
|
-
"_spec": "1.1.
|
|
27
|
+
"_resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz",
|
|
28
|
+
"_spec": "1.1.7",
|
|
29
29
|
"_where": "/home/runner/work/node-datachannel/node-datachannel",
|
|
30
30
|
"author": {
|
|
31
31
|
"name": "Rebecca Turner",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"scripts": {
|
|
63
63
|
"test": "standard && tap test/*.js"
|
|
64
64
|
},
|
|
65
|
-
"version": "1.1.
|
|
65
|
+
"version": "1.1.7"
|
|
66
66
|
}
|
|
@@ -373,7 +373,7 @@ BufferList.prototype._match = function (offset, search) {
|
|
|
373
373
|
return this.slice(offset, offset + byteLength)[m](0, byteLength)
|
|
374
374
|
}
|
|
375
375
|
} else {
|
|
376
|
-
BufferList.prototype[m] = function (offset) {
|
|
376
|
+
BufferList.prototype[m] = function (offset = 0) {
|
|
377
377
|
return this.slice(offset, offset + methods[m])[m](0)
|
|
378
378
|
}
|
|
379
379
|
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
|
-
"bl@4.0
|
|
4
|
+
"bl@4.1.0",
|
|
5
5
|
"/home/runner/work/node-datachannel/node-datachannel"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
|
-
"_from": "bl@4.0
|
|
9
|
-
"_id": "bl@4.0
|
|
8
|
+
"_from": "bl@4.1.0",
|
|
9
|
+
"_id": "bl@4.1.0",
|
|
10
10
|
"_inBundle": false,
|
|
11
|
-
"_integrity": "sha512-
|
|
11
|
+
"_integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==",
|
|
12
12
|
"_location": "/tar-stream/bl",
|
|
13
13
|
"_phantomChildren": {},
|
|
14
14
|
"_requested": {
|
|
15
15
|
"type": "version",
|
|
16
16
|
"registry": true,
|
|
17
|
-
"raw": "bl@4.0
|
|
17
|
+
"raw": "bl@4.1.0",
|
|
18
18
|
"name": "bl",
|
|
19
19
|
"escapedName": "bl",
|
|
20
|
-
"rawSpec": "4.0
|
|
20
|
+
"rawSpec": "4.1.0",
|
|
21
21
|
"saveSpec": null,
|
|
22
|
-
"fetchSpec": "4.0
|
|
22
|
+
"fetchSpec": "4.1.0"
|
|
23
23
|
},
|
|
24
24
|
"_requiredBy": [
|
|
25
25
|
"/tar-stream"
|
|
26
26
|
],
|
|
27
|
-
"_resolved": "https://registry.npmjs.org/bl/-/bl-4.0.
|
|
28
|
-
"_spec": "4.0
|
|
27
|
+
"_resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
|
|
28
|
+
"_spec": "4.1.0",
|
|
29
29
|
"_where": "/home/runner/work/node-datachannel/node-datachannel",
|
|
30
30
|
"authors": [
|
|
31
31
|
"Rod Vagg <rod@vagg.org> (https://github.com/rvagg)",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"lint": "standard *.js test/*.js",
|
|
65
65
|
"test": "npm run lint && node test/test.js | faucet"
|
|
66
66
|
},
|
|
67
|
-
"version": "4.0
|
|
67
|
+
"version": "4.1.0"
|
|
68
68
|
}
|
|
@@ -265,6 +265,7 @@ tape('test readUInt8 / readInt8', function (t) {
|
|
|
265
265
|
const buf3 = Buffer.alloc(3)
|
|
266
266
|
const bl = new BufferList()
|
|
267
267
|
|
|
268
|
+
buf1[0] = 0x1
|
|
268
269
|
buf2[1] = 0x3
|
|
269
270
|
buf2[2] = 0x4
|
|
270
271
|
buf3[0] = 0x23
|
|
@@ -274,6 +275,7 @@ tape('test readUInt8 / readInt8', function (t) {
|
|
|
274
275
|
bl.append(buf2)
|
|
275
276
|
bl.append(buf3)
|
|
276
277
|
|
|
278
|
+
t.equal(bl.readUInt8(), 0x1)
|
|
277
279
|
t.equal(bl.readUInt8(2), 0x3)
|
|
278
280
|
t.equal(bl.readInt8(2), 0x3)
|
|
279
281
|
t.equal(bl.readUInt8(3), 0x4)
|
|
@@ -292,6 +294,7 @@ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t
|
|
|
292
294
|
const buf3 = Buffer.alloc(3)
|
|
293
295
|
const bl = new BufferList()
|
|
294
296
|
|
|
297
|
+
buf1[0] = 0x1
|
|
295
298
|
buf2[1] = 0x3
|
|
296
299
|
buf2[2] = 0x4
|
|
297
300
|
buf3[0] = 0x23
|
|
@@ -301,6 +304,8 @@ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t
|
|
|
301
304
|
bl.append(buf2)
|
|
302
305
|
bl.append(buf3)
|
|
303
306
|
|
|
307
|
+
t.equal(bl.readUInt16BE(), 0x0100)
|
|
308
|
+
t.equal(bl.readUInt16LE(), 0x0001)
|
|
304
309
|
t.equal(bl.readUInt16BE(2), 0x0304)
|
|
305
310
|
t.equal(bl.readUInt16LE(2), 0x0403)
|
|
306
311
|
t.equal(bl.readInt16BE(2), 0x0304)
|
|
@@ -323,6 +328,7 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
|
|
|
323
328
|
const buf3 = Buffer.alloc(3)
|
|
324
329
|
const bl = new BufferList()
|
|
325
330
|
|
|
331
|
+
buf1[0] = 0x1
|
|
326
332
|
buf2[1] = 0x3
|
|
327
333
|
buf2[2] = 0x4
|
|
328
334
|
buf3[0] = 0x23
|
|
@@ -332,6 +338,8 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
|
|
|
332
338
|
bl.append(buf2)
|
|
333
339
|
bl.append(buf3)
|
|
334
340
|
|
|
341
|
+
t.equal(bl.readUInt32BE(), 0x01000304)
|
|
342
|
+
t.equal(bl.readUInt32LE(), 0x04030001)
|
|
335
343
|
t.equal(bl.readUInt32BE(2), 0x03042342)
|
|
336
344
|
t.equal(bl.readUInt32LE(2), 0x42230403)
|
|
337
345
|
t.equal(bl.readInt32BE(2), 0x03042342)
|
|
@@ -391,6 +399,7 @@ tape('test readFloatLE / readFloatBE', function (t) {
|
|
|
391
399
|
const buf3 = Buffer.alloc(3)
|
|
392
400
|
const bl = new BufferList()
|
|
393
401
|
|
|
402
|
+
buf1[0] = 0x01
|
|
394
403
|
buf2[1] = 0x00
|
|
395
404
|
buf2[2] = 0x00
|
|
396
405
|
buf3[0] = 0x80
|
|
@@ -400,7 +409,11 @@ tape('test readFloatLE / readFloatBE', function (t) {
|
|
|
400
409
|
bl.append(buf2)
|
|
401
410
|
bl.append(buf3)
|
|
402
411
|
|
|
403
|
-
|
|
412
|
+
const canonical = Buffer.concat([buf1, buf2, buf3])
|
|
413
|
+
t.equal(bl.readFloatLE(), canonical.readFloatLE())
|
|
414
|
+
t.equal(bl.readFloatBE(), canonical.readFloatBE())
|
|
415
|
+
t.equal(bl.readFloatLE(2), canonical.readFloatLE(2))
|
|
416
|
+
t.equal(bl.readFloatBE(2), canonical.readFloatBE(2))
|
|
404
417
|
|
|
405
418
|
t.end()
|
|
406
419
|
})
|
|
@@ -411,6 +424,7 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
|
|
|
411
424
|
const buf3 = Buffer.alloc(10)
|
|
412
425
|
const bl = new BufferList()
|
|
413
426
|
|
|
427
|
+
buf1[0] = 0x01
|
|
414
428
|
buf2[1] = 0x55
|
|
415
429
|
buf2[2] = 0x55
|
|
416
430
|
buf3[0] = 0x55
|
|
@@ -424,7 +438,11 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
|
|
|
424
438
|
bl.append(buf2)
|
|
425
439
|
bl.append(buf3)
|
|
426
440
|
|
|
427
|
-
|
|
441
|
+
const canonical = Buffer.concat([buf1, buf2, buf3])
|
|
442
|
+
t.equal(bl.readDoubleBE(), canonical.readDoubleBE())
|
|
443
|
+
t.equal(bl.readDoubleLE(), canonical.readDoubleLE())
|
|
444
|
+
t.equal(bl.readDoubleBE(2), canonical.readDoubleBE(2))
|
|
445
|
+
t.equal(bl.readDoubleLE(2), canonical.readDoubleLE(2))
|
|
428
446
|
|
|
429
447
|
t.end()
|
|
430
448
|
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
+
"//": "But not version 5 of string-width, as that's ESM only",
|
|
2
3
|
"_args": [
|
|
3
4
|
[
|
|
4
|
-
"wide-align@1.1.
|
|
5
|
+
"wide-align@1.1.5",
|
|
5
6
|
"/home/runner/work/node-datachannel/node-datachannel"
|
|
6
7
|
]
|
|
7
8
|
],
|
|
8
|
-
"_from": "wide-align@1.1.
|
|
9
|
-
"_id": "wide-align@1.1.
|
|
9
|
+
"_from": "wide-align@1.1.5",
|
|
10
|
+
"_id": "wide-align@1.1.5",
|
|
10
11
|
"_inBundle": false,
|
|
11
|
-
"_integrity": "sha512-
|
|
12
|
+
"_integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==",
|
|
12
13
|
"_location": "/wide-align",
|
|
13
14
|
"_phantomChildren": {},
|
|
14
15
|
"_requested": {
|
|
15
16
|
"type": "version",
|
|
16
17
|
"registry": true,
|
|
17
|
-
"raw": "wide-align@1.1.
|
|
18
|
+
"raw": "wide-align@1.1.5",
|
|
18
19
|
"name": "wide-align",
|
|
19
20
|
"escapedName": "wide-align",
|
|
20
|
-
"rawSpec": "1.1.
|
|
21
|
+
"rawSpec": "1.1.5",
|
|
21
22
|
"saveSpec": null,
|
|
22
|
-
"fetchSpec": "1.1.
|
|
23
|
+
"fetchSpec": "1.1.5"
|
|
23
24
|
},
|
|
24
25
|
"_requiredBy": [
|
|
25
26
|
"/npmlog/gauge"
|
|
26
27
|
],
|
|
27
|
-
"_resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.
|
|
28
|
-
"_spec": "1.1.
|
|
28
|
+
"_resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz",
|
|
29
|
+
"_spec": "1.1.5",
|
|
29
30
|
"_where": "/home/runner/work/node-datachannel/node-datachannel",
|
|
30
31
|
"author": {
|
|
31
32
|
"name": "Rebecca Turner",
|
|
@@ -36,11 +37,11 @@
|
|
|
36
37
|
"url": "https://github.com/iarna/wide-align/issues"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"string-width": "^1.0.2 || 2"
|
|
40
|
+
"string-width": "^1.0.2 || 2 || 3 || 4"
|
|
40
41
|
},
|
|
41
42
|
"description": "A wide-character aware text alignment function for use on the console or with fixed width fonts.",
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"tap": "
|
|
44
|
+
"tap": "*"
|
|
44
45
|
},
|
|
45
46
|
"files": [
|
|
46
47
|
"align.js"
|
|
@@ -62,8 +63,7 @@
|
|
|
62
63
|
"url": "git+https://github.com/iarna/wide-align.git"
|
|
63
64
|
},
|
|
64
65
|
"scripts": {
|
|
65
|
-
"test": "tap --coverage test/*.js"
|
|
66
|
-
"version": "perl -pi -e 's/^( \"version\": $ENV{npm_config_node_version}\").*?\",/$1abc\",/' package-lock.json ; git add package-lock.json"
|
|
66
|
+
"test": "tap --coverage test/*.js"
|
|
67
67
|
},
|
|
68
|
-
"version": "1.1.
|
|
68
|
+
"version": "1.1.5"
|
|
69
69
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-datachannel",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "libdatachannel node bindings",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"build": "cmake-js build",
|
|
16
16
|
"_prebuild": "prebuild --backend cmake-js",
|
|
17
17
|
"clean": "cmake-js clean",
|
|
18
|
+
"lint": "eslint lib/**/* test/**/*",
|
|
18
19
|
"test": "jest"
|
|
19
20
|
},
|
|
20
21
|
"repository": {
|
|
@@ -46,18 +47,25 @@
|
|
|
46
47
|
},
|
|
47
48
|
"homepage": "https://github.com/murat-dogan/node-datachannel#readme",
|
|
48
49
|
"devDependencies": {
|
|
50
|
+
"@types/node": "^17.0.23",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
52
|
+
"@typescript-eslint/parser": "^5.18.0",
|
|
49
53
|
"cmake-js": "^6.3.0",
|
|
54
|
+
"eslint": "^8.12.0",
|
|
55
|
+
"eslint-config-prettier": "^8.5.0",
|
|
56
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
50
57
|
"jest": "^27.5.1",
|
|
51
58
|
"nan": "^2.15.0",
|
|
52
59
|
"napi-thread-safe-callback-cancellable": "^0.0.7",
|
|
53
|
-
"node-addon-api": "^4.
|
|
54
|
-
"prebuild": "^11.0.3"
|
|
60
|
+
"node-addon-api": "^4.3.0",
|
|
61
|
+
"prebuild": "^11.0.3",
|
|
62
|
+
"prettier": "^2.6.2",
|
|
63
|
+
"typescript": "^4.6.3"
|
|
55
64
|
},
|
|
56
65
|
"bundledDependencies": [
|
|
57
66
|
"prebuild-install"
|
|
58
67
|
],
|
|
59
68
|
"dependencies": {
|
|
60
|
-
"@types/node": "^17.0.21",
|
|
61
69
|
"prebuild-install": "^7.0.1"
|
|
62
70
|
}
|
|
63
71
|
}
|
|
@@ -20,6 +20,8 @@ Napi::Object DataChannelWrapper::Init(Napi::Env env, Napi::Object exports)
|
|
|
20
20
|
{
|
|
21
21
|
InstanceMethod("close", &DataChannelWrapper::close),
|
|
22
22
|
InstanceMethod("getLabel", &DataChannelWrapper::getLabel),
|
|
23
|
+
InstanceMethod("getId", &DataChannelWrapper::getId),
|
|
24
|
+
InstanceMethod("getProtocol", &DataChannelWrapper::getProtocol),
|
|
23
25
|
InstanceMethod("sendMessage", &DataChannelWrapper::sendMessage),
|
|
24
26
|
InstanceMethod("sendMessageBinary", &DataChannelWrapper::sendMessageBinary),
|
|
25
27
|
InstanceMethod("isOpen", &DataChannelWrapper::isOpen),
|
|
@@ -54,27 +56,27 @@ DataChannelWrapper::~DataChannelWrapper()
|
|
|
54
56
|
|
|
55
57
|
void DataChannelWrapper::doClose()
|
|
56
58
|
{
|
|
57
|
-
instances.erase(this);
|
|
58
|
-
|
|
59
59
|
if (mDataChannelPtr)
|
|
60
60
|
{
|
|
61
61
|
try
|
|
62
62
|
{
|
|
63
|
-
mOnOpenCallback.reset();
|
|
64
|
-
mOnClosedCallback.reset();
|
|
65
|
-
mOnErrorCallback.reset();
|
|
66
|
-
mOnBufferedAmountLowCallback.reset();
|
|
67
|
-
mOnMessageCallback.reset();
|
|
68
|
-
|
|
69
63
|
mDataChannelPtr->close();
|
|
70
64
|
mDataChannelPtr.reset();
|
|
71
65
|
}
|
|
72
66
|
catch (std::exception &ex)
|
|
73
67
|
{
|
|
74
|
-
std::
|
|
68
|
+
std::cerr << std::string("libdatachannel error while closing data channel: ") + ex.what() << std::endl;
|
|
75
69
|
return;
|
|
76
70
|
}
|
|
77
71
|
}
|
|
72
|
+
|
|
73
|
+
mOnOpenCallback.reset();
|
|
74
|
+
mOnClosedCallback.reset();
|
|
75
|
+
mOnErrorCallback.reset();
|
|
76
|
+
mOnBufferedAmountLowCallback.reset();
|
|
77
|
+
mOnMessageCallback.reset();
|
|
78
|
+
|
|
79
|
+
instances.erase(this);
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
void DataChannelWrapper::close(const Napi::CallbackInfo &info)
|
|
@@ -86,18 +88,40 @@ Napi::Value DataChannelWrapper::getLabel(const Napi::CallbackInfo &info)
|
|
|
86
88
|
{
|
|
87
89
|
if (!mDataChannelPtr)
|
|
88
90
|
{
|
|
89
|
-
Napi::Error::New(info.Env(), "
|
|
91
|
+
Napi::Error::New(info.Env(), "getLabel() called on destroyed channel").ThrowAsJavaScriptException();
|
|
90
92
|
return info.Env().Null();
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
return Napi::String::New(info.Env(), mDataChannelPtr->label());
|
|
94
96
|
}
|
|
95
97
|
|
|
98
|
+
Napi::Value DataChannelWrapper::getId(const Napi::CallbackInfo &info)
|
|
99
|
+
{
|
|
100
|
+
if (!mDataChannelPtr)
|
|
101
|
+
{
|
|
102
|
+
Napi::Error::New(info.Env(), "getId() called on destroyed channel").ThrowAsJavaScriptException();
|
|
103
|
+
return info.Env().Null();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return Napi::Number::New(info.Env(), mDataChannelPtr->id());
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
Napi::Value DataChannelWrapper::getProtocol(const Napi::CallbackInfo &info)
|
|
110
|
+
{
|
|
111
|
+
if (!mDataChannelPtr)
|
|
112
|
+
{
|
|
113
|
+
Napi::Error::New(info.Env(), "getProtocol() called on destroyed channel").ThrowAsJavaScriptException();
|
|
114
|
+
return info.Env().Null();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return Napi::String::New(info.Env(), mDataChannelPtr->protocol());
|
|
118
|
+
}
|
|
119
|
+
|
|
96
120
|
Napi::Value DataChannelWrapper::sendMessage(const Napi::CallbackInfo &info)
|
|
97
121
|
{
|
|
98
122
|
if (!mDataChannelPtr)
|
|
99
123
|
{
|
|
100
|
-
Napi::Error::New(info.Env(), "
|
|
124
|
+
Napi::Error::New(info.Env(), "sendMessage() called on destroyed channel").ThrowAsJavaScriptException();
|
|
101
125
|
return info.Env().Null();
|
|
102
126
|
}
|
|
103
127
|
|
|
@@ -117,7 +141,7 @@ Napi::Value DataChannelWrapper::sendMessage(const Napi::CallbackInfo &info)
|
|
|
117
141
|
}
|
|
118
142
|
catch (std::exception &ex)
|
|
119
143
|
{
|
|
120
|
-
Napi::Error::New(env, std::string("libdatachannel error while sending
|
|
144
|
+
Napi::Error::New(env, std::string("libdatachannel error while sending data channel message: ") + ex.what()).ThrowAsJavaScriptException();
|
|
121
145
|
return Napi::Boolean::New(info.Env(), false);
|
|
122
146
|
}
|
|
123
147
|
}
|
|
@@ -126,7 +150,7 @@ Napi::Value DataChannelWrapper::sendMessageBinary(const Napi::CallbackInfo &info
|
|
|
126
150
|
{
|
|
127
151
|
if (!mDataChannelPtr)
|
|
128
152
|
{
|
|
129
|
-
Napi::Error::New(info.Env(), "
|
|
153
|
+
Napi::Error::New(info.Env(), "sendMessagBinary() called on destroyed channel").ThrowAsJavaScriptException();
|
|
130
154
|
return info.Env().Null();
|
|
131
155
|
}
|
|
132
156
|
|
|
@@ -146,7 +170,7 @@ Napi::Value DataChannelWrapper::sendMessageBinary(const Napi::CallbackInfo &info
|
|
|
146
170
|
}
|
|
147
171
|
catch (std::exception &ex)
|
|
148
172
|
{
|
|
149
|
-
Napi::Error::New(env, std::string("libdatachannel error while sending
|
|
173
|
+
Napi::Error::New(env, std::string("libdatachannel error while sending data channel message: ") + ex.what()).ThrowAsJavaScriptException();
|
|
150
174
|
return Napi::Boolean::New(info.Env(), false);
|
|
151
175
|
}
|
|
152
176
|
}
|
|
@@ -154,6 +178,7 @@ Napi::Value DataChannelWrapper::sendMessageBinary(const Napi::CallbackInfo &info
|
|
|
154
178
|
Napi::Value DataChannelWrapper::isOpen(const Napi::CallbackInfo &info)
|
|
155
179
|
{
|
|
156
180
|
Napi::Env env = info.Env();
|
|
181
|
+
|
|
157
182
|
if (!mDataChannelPtr)
|
|
158
183
|
{
|
|
159
184
|
return Napi::Boolean::New(info.Env(), false);
|
|
@@ -165,7 +190,7 @@ Napi::Value DataChannelWrapper::isOpen(const Napi::CallbackInfo &info)
|
|
|
165
190
|
}
|
|
166
191
|
catch (std::exception &ex)
|
|
167
192
|
{
|
|
168
|
-
Napi::Error::New(env, std::string("libdatachannel error
|
|
193
|
+
Napi::Error::New(env, std::string("libdatachannel error: ") + ex.what()).ThrowAsJavaScriptException();
|
|
169
194
|
return Napi::Boolean::New(info.Env(), false);
|
|
170
195
|
}
|
|
171
196
|
}
|
|
@@ -173,6 +198,7 @@ Napi::Value DataChannelWrapper::isOpen(const Napi::CallbackInfo &info)
|
|
|
173
198
|
Napi::Value DataChannelWrapper::bufferedAmount(const Napi::CallbackInfo &info)
|
|
174
199
|
{
|
|
175
200
|
Napi::Env env = info.Env();
|
|
201
|
+
|
|
176
202
|
if (!mDataChannelPtr)
|
|
177
203
|
{
|
|
178
204
|
return Napi::Number::New(info.Env(), 0);
|
|
@@ -184,7 +210,7 @@ Napi::Value DataChannelWrapper::bufferedAmount(const Napi::CallbackInfo &info)
|
|
|
184
210
|
}
|
|
185
211
|
catch (std::exception &ex)
|
|
186
212
|
{
|
|
187
|
-
Napi::Error::New(env, std::string("libdatachannel error
|
|
213
|
+
Napi::Error::New(env, std::string("libdatachannel error: ") + ex.what()).ThrowAsJavaScriptException();
|
|
188
214
|
return Napi::Number::New(info.Env(), 0);
|
|
189
215
|
}
|
|
190
216
|
}
|
|
@@ -192,6 +218,7 @@ Napi::Value DataChannelWrapper::bufferedAmount(const Napi::CallbackInfo &info)
|
|
|
192
218
|
Napi::Value DataChannelWrapper::maxMessageSize(const Napi::CallbackInfo &info)
|
|
193
219
|
{
|
|
194
220
|
Napi::Env env = info.Env();
|
|
221
|
+
|
|
195
222
|
if (!mDataChannelPtr)
|
|
196
223
|
{
|
|
197
224
|
return Napi::Number::New(info.Env(), 0);
|
|
@@ -203,7 +230,7 @@ Napi::Value DataChannelWrapper::maxMessageSize(const Napi::CallbackInfo &info)
|
|
|
203
230
|
}
|
|
204
231
|
catch (std::exception &ex)
|
|
205
232
|
{
|
|
206
|
-
Napi::Error::New(env, std::string("libdatachannel error
|
|
233
|
+
Napi::Error::New(env, std::string("libdatachannel error: ") + ex.what()).ThrowAsJavaScriptException();
|
|
207
234
|
return Napi::Number::New(info.Env(), 0);
|
|
208
235
|
}
|
|
209
236
|
}
|
|
@@ -212,7 +239,7 @@ void DataChannelWrapper::setBufferedAmountLowThreshold(const Napi::CallbackInfo
|
|
|
212
239
|
{
|
|
213
240
|
if (!mDataChannelPtr)
|
|
214
241
|
{
|
|
215
|
-
Napi::Error::New(info.Env(), "
|
|
242
|
+
Napi::Error::New(info.Env(), "setBufferedAmountLowThreshold() called on destroyed channel").ThrowAsJavaScriptException();
|
|
216
243
|
return;
|
|
217
244
|
}
|
|
218
245
|
|
|
@@ -231,13 +258,19 @@ void DataChannelWrapper::setBufferedAmountLowThreshold(const Napi::CallbackInfo
|
|
|
231
258
|
}
|
|
232
259
|
catch (std::exception &ex)
|
|
233
260
|
{
|
|
234
|
-
Napi::Error::New(env, std::string("libdatachannel error
|
|
261
|
+
Napi::Error::New(env, std::string("libdatachannel error: ") + ex.what()).ThrowAsJavaScriptException();
|
|
235
262
|
return;
|
|
236
263
|
}
|
|
237
264
|
}
|
|
238
265
|
|
|
239
266
|
void DataChannelWrapper::onOpen(const Napi::CallbackInfo &info)
|
|
240
267
|
{
|
|
268
|
+
if (!mDataChannelPtr)
|
|
269
|
+
{
|
|
270
|
+
Napi::Error::New(info.Env(), "onOpen() called on destroyed channel").ThrowAsJavaScriptException();
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
241
274
|
Napi::Env env = info.Env();
|
|
242
275
|
int length = info.Length();
|
|
243
276
|
|
|
@@ -250,11 +283,10 @@ void DataChannelWrapper::onOpen(const Napi::CallbackInfo &info)
|
|
|
250
283
|
// Callback
|
|
251
284
|
mOnOpenCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
252
285
|
|
|
253
|
-
mDataChannelPtr->onOpen([&]()
|
|
254
|
-
{
|
|
286
|
+
mDataChannelPtr->onOpen([&]() {
|
|
255
287
|
if (mOnOpenCallback)
|
|
256
288
|
mOnOpenCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
|
|
257
|
-
// Check the
|
|
289
|
+
// Check the data channel is not closed
|
|
258
290
|
if(instances.find(this) == instances.end())
|
|
259
291
|
throw ThreadSafeCallback::CancelException();
|
|
260
292
|
|
|
@@ -266,6 +298,12 @@ void DataChannelWrapper::onOpen(const Napi::CallbackInfo &info)
|
|
|
266
298
|
|
|
267
299
|
void DataChannelWrapper::onClosed(const Napi::CallbackInfo &info)
|
|
268
300
|
{
|
|
301
|
+
if (!mDataChannelPtr)
|
|
302
|
+
{
|
|
303
|
+
Napi::Error::New(info.Env(), "onClosed() called on destroyed channel").ThrowAsJavaScriptException();
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
269
307
|
Napi::Env env = info.Env();
|
|
270
308
|
int length = info.Length();
|
|
271
309
|
|
|
@@ -278,13 +316,10 @@ void DataChannelWrapper::onClosed(const Napi::CallbackInfo &info)
|
|
|
278
316
|
// Callback
|
|
279
317
|
mOnClosedCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
280
318
|
|
|
281
|
-
mDataChannelPtr->onClosed([&]()
|
|
282
|
-
{
|
|
319
|
+
mDataChannelPtr->onClosed([&]() {
|
|
283
320
|
if (mOnClosedCallback)
|
|
284
321
|
mOnClosedCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
|
|
285
|
-
//
|
|
286
|
-
if(instances.find(this) == instances.end())
|
|
287
|
-
throw ThreadSafeCallback::CancelException();
|
|
322
|
+
// Do not check if the data channel has been closed here
|
|
288
323
|
|
|
289
324
|
// This will run in main thread and needs to construct the
|
|
290
325
|
// arguments for the call
|
|
@@ -294,6 +329,12 @@ void DataChannelWrapper::onClosed(const Napi::CallbackInfo &info)
|
|
|
294
329
|
|
|
295
330
|
void DataChannelWrapper::onError(const Napi::CallbackInfo &info)
|
|
296
331
|
{
|
|
332
|
+
if (!mDataChannelPtr)
|
|
333
|
+
{
|
|
334
|
+
Napi::Error::New(info.Env(), "onError() called on destroyed channel").ThrowAsJavaScriptException();
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
297
338
|
Napi::Env env = info.Env();
|
|
298
339
|
int length = info.Length();
|
|
299
340
|
|
|
@@ -306,11 +347,10 @@ void DataChannelWrapper::onError(const Napi::CallbackInfo &info)
|
|
|
306
347
|
// Callback
|
|
307
348
|
mOnErrorCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
308
349
|
|
|
309
|
-
mDataChannelPtr->onError([&](
|
|
310
|
-
{
|
|
350
|
+
mDataChannelPtr->onError([&](std::string error) {
|
|
311
351
|
if (mOnErrorCallback)
|
|
312
|
-
mOnErrorCallback->call([this, error](Napi::Env env, std::vector<napi_value> &args) {
|
|
313
|
-
// Check the
|
|
352
|
+
mOnErrorCallback->call([this, error = std::move(error)](Napi::Env env, std::vector<napi_value> &args) {
|
|
353
|
+
// Check the data channel is not closed
|
|
314
354
|
if(instances.find(this) == instances.end())
|
|
315
355
|
throw ThreadSafeCallback::CancelException();
|
|
316
356
|
|
|
@@ -322,6 +362,12 @@ void DataChannelWrapper::onError(const Napi::CallbackInfo &info)
|
|
|
322
362
|
|
|
323
363
|
void DataChannelWrapper::onBufferedAmountLow(const Napi::CallbackInfo &info)
|
|
324
364
|
{
|
|
365
|
+
if (!mDataChannelPtr)
|
|
366
|
+
{
|
|
367
|
+
Napi::Error::New(info.Env(), "onBufferedAmountLow() called on destroyed channel").ThrowAsJavaScriptException();
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
325
371
|
Napi::Env env = info.Env();
|
|
326
372
|
int length = info.Length();
|
|
327
373
|
|
|
@@ -334,11 +380,10 @@ void DataChannelWrapper::onBufferedAmountLow(const Napi::CallbackInfo &info)
|
|
|
334
380
|
// Callback
|
|
335
381
|
mOnBufferedAmountLowCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
336
382
|
|
|
337
|
-
mDataChannelPtr->onBufferedAmountLow([&]()
|
|
338
|
-
{
|
|
383
|
+
mDataChannelPtr->onBufferedAmountLow([&]() {
|
|
339
384
|
if (mOnBufferedAmountLowCallback)
|
|
340
385
|
mOnBufferedAmountLowCallback->call([this](Napi::Env env, std::vector<napi_value> &args) {
|
|
341
|
-
// Check the
|
|
386
|
+
// Check the data channel is not closed
|
|
342
387
|
if(instances.find(this) == instances.end())
|
|
343
388
|
throw ThreadSafeCallback::CancelException();
|
|
344
389
|
|
|
@@ -350,6 +395,12 @@ void DataChannelWrapper::onBufferedAmountLow(const Napi::CallbackInfo &info)
|
|
|
350
395
|
|
|
351
396
|
void DataChannelWrapper::onMessage(const Napi::CallbackInfo &info)
|
|
352
397
|
{
|
|
398
|
+
if (!mDataChannelPtr)
|
|
399
|
+
{
|
|
400
|
+
Napi::Error::New(info.Env(), "onMessage() called on destroyed channel").ThrowAsJavaScriptException();
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
353
404
|
Napi::Env env = info.Env();
|
|
354
405
|
int length = info.Length();
|
|
355
406
|
|
|
@@ -362,24 +413,23 @@ void DataChannelWrapper::onMessage(const Napi::CallbackInfo &info)
|
|
|
362
413
|
// Callback
|
|
363
414
|
mOnMessageCallback = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
|
364
415
|
|
|
365
|
-
mDataChannelPtr->onMessage([&](
|
|
366
|
-
{
|
|
416
|
+
mDataChannelPtr->onMessage([&](std::variant<rtc::binary, std::string> message) {
|
|
367
417
|
if (mOnMessageCallback)
|
|
368
|
-
mOnMessageCallback->call([this, message](Napi::Env env, std::vector<napi_value> &args) {
|
|
369
|
-
// Check the
|
|
418
|
+
mOnMessageCallback->call([this, message = std::move(message)](Napi::Env env, std::vector<napi_value> &args) {
|
|
419
|
+
// Check the data channel is not closed
|
|
370
420
|
if(instances.find(this) == instances.end())
|
|
371
421
|
throw ThreadSafeCallback::CancelException();
|
|
372
422
|
|
|
373
423
|
// This will run in main thread and needs to construct the
|
|
374
424
|
// arguments for the call
|
|
375
|
-
Napi::Object payload = Napi::Object::New(env);
|
|
376
425
|
if (std::holds_alternative<std::string>(message))
|
|
377
426
|
{
|
|
378
427
|
args = {Napi::String::New(env, std::get<std::string>(message))};
|
|
379
428
|
}
|
|
380
429
|
else
|
|
381
430
|
{
|
|
382
|
-
|
|
431
|
+
auto bin = std::get<rtc::binary>(std::move(message));
|
|
432
|
+
args = {Napi::Buffer<std::byte>::Copy(env, bin.data(), bin.size())};
|
|
383
433
|
}
|
|
384
434
|
}); });
|
|
385
435
|
}
|