node-datachannel 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +12 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +8 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/build-linux.yml +5 -3
- package/.github/workflows/build-mac.yml +1 -1
- package/.github/workflows/build-win.yml +4 -4
- package/.prettierrc.js +7 -0
- package/CMakeLists.txt +8 -2
- package/README.md +4 -4
- package/lib/datachannel-stream.js +97 -0
- package/lib/index.d.ts +62 -55
- package/lib/index.js +5 -2
- package/node_modules/decompress-response/index.d.ts +14 -21
- package/node_modules/decompress-response/index.js +34 -16
- package/node_modules/decompress-response/license +1 -1
- package/node_modules/decompress-response/package.json +23 -17
- package/node_modules/decompress-response/readme.md +2 -6
- package/node_modules/detect-libc/README.md +124 -42
- package/node_modules/detect-libc/index.d.ts +11 -0
- package/node_modules/detect-libc/lib/detect-libc.js +166 -80
- package/node_modules/detect-libc/lib/process.js +16 -0
- package/node_modules/detect-libc/package.json +20 -19
- package/node_modules/{semver → lru-cache}/LICENSE +0 -0
- package/node_modules/lru-cache/README.md +166 -0
- package/node_modules/lru-cache/index.js +334 -0
- package/node_modules/lru-cache/node_modules/yallist/LICENSE +15 -0
- package/node_modules/lru-cache/node_modules/yallist/README.md +204 -0
- package/node_modules/lru-cache/node_modules/yallist/iterator.js +8 -0
- package/node_modules/lru-cache/node_modules/yallist/package.json +65 -0
- package/node_modules/lru-cache/node_modules/yallist/yallist.js +426 -0
- package/node_modules/lru-cache/package.json +75 -0
- package/node_modules/mimic-response/index.d.ts +2 -2
- package/node_modules/mimic-response/index.js +41 -2
- package/node_modules/mimic-response/package.json +17 -17
- package/node_modules/mimic-response/readme.md +22 -1
- package/node_modules/minimist/index.js +6 -2
- package/node_modules/minimist/package.json +10 -10
- package/node_modules/minimist/readme.markdown +4 -1
- package/node_modules/minimist/test/proto.js +16 -0
- package/node_modules/node-abi/.circleci/config.yml +63 -0
- package/node_modules/node-abi/.releaserc.json +9 -0
- package/node_modules/node-abi/abi_registry.json +45 -3
- package/node_modules/node-abi/index.js +5 -2
- package/node_modules/node-abi/node_modules/semver/CHANGELOG.md +111 -0
- package/node_modules/node-abi/node_modules/semver/LICENSE +15 -0
- package/node_modules/{semver → node-abi/node_modules/semver}/README.md +180 -26
- package/node_modules/node-abi/node_modules/semver/bin/semver.js +173 -0
- package/node_modules/node-abi/node_modules/semver/classes/comparator.js +135 -0
- package/node_modules/node-abi/node_modules/semver/classes/index.js +5 -0
- package/node_modules/node-abi/node_modules/semver/classes/range.js +510 -0
- package/node_modules/node-abi/node_modules/semver/classes/semver.js +287 -0
- package/node_modules/node-abi/node_modules/semver/functions/clean.js +6 -0
- package/node_modules/node-abi/node_modules/semver/functions/cmp.js +48 -0
- package/node_modules/node-abi/node_modules/semver/functions/coerce.js +51 -0
- package/node_modules/node-abi/node_modules/semver/functions/compare-build.js +7 -0
- package/node_modules/node-abi/node_modules/semver/functions/compare-loose.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/compare.js +5 -0
- package/node_modules/node-abi/node_modules/semver/functions/diff.js +23 -0
- package/node_modules/node-abi/node_modules/semver/functions/eq.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/gt.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/gte.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/inc.js +15 -0
- package/node_modules/node-abi/node_modules/semver/functions/lt.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/lte.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/major.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/minor.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/neq.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/parse.js +33 -0
- package/node_modules/node-abi/node_modules/semver/functions/patch.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/prerelease.js +6 -0
- package/node_modules/node-abi/node_modules/semver/functions/rcompare.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/rsort.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/satisfies.js +10 -0
- package/node_modules/node-abi/node_modules/semver/functions/sort.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/valid.js +6 -0
- package/node_modules/node-abi/node_modules/semver/index.js +48 -0
- package/node_modules/node-abi/node_modules/semver/internal/constants.js +17 -0
- package/node_modules/node-abi/node_modules/semver/internal/debug.js +9 -0
- package/node_modules/node-abi/node_modules/semver/internal/identifiers.js +23 -0
- package/node_modules/node-abi/node_modules/semver/internal/parse-options.js +11 -0
- package/node_modules/node-abi/node_modules/semver/internal/re.js +182 -0
- package/node_modules/{semver → node-abi/node_modules/semver}/package.json +32 -23
- package/node_modules/node-abi/node_modules/semver/preload.js +2 -0
- package/node_modules/{semver → node-abi/node_modules/semver}/range.bnf +0 -0
- package/node_modules/node-abi/node_modules/semver/ranges/gtr.js +4 -0
- package/node_modules/node-abi/node_modules/semver/ranges/intersects.js +7 -0
- package/node_modules/node-abi/node_modules/semver/ranges/ltr.js +4 -0
- package/node_modules/node-abi/node_modules/semver/ranges/max-satisfying.js +25 -0
- package/node_modules/node-abi/node_modules/semver/ranges/min-satisfying.js +24 -0
- package/node_modules/node-abi/node_modules/semver/ranges/min-version.js +60 -0
- package/node_modules/node-abi/node_modules/semver/ranges/outside.js +80 -0
- package/node_modules/node-abi/node_modules/semver/ranges/simplify.js +44 -0
- package/node_modules/node-abi/node_modules/semver/ranges/subset.js +222 -0
- package/node_modules/node-abi/node_modules/semver/ranges/to-comparators.js +8 -0
- package/node_modules/node-abi/node_modules/semver/ranges/valid.js +11 -0
- package/node_modules/node-abi/package.json +21 -17
- package/node_modules/node-abi/test/index.js +7 -15
- package/node_modules/prebuild-install/CHANGELOG.md +24 -7
- package/node_modules/prebuild-install/README.md +24 -4
- package/node_modules/prebuild-install/asset.js +10 -10
- package/node_modules/prebuild-install/bin.js +13 -13
- package/node_modules/prebuild-install/download.js +22 -22
- package/node_modules/prebuild-install/log.js +4 -4
- package/node_modules/prebuild-install/package.json +18 -19
- package/node_modules/prebuild-install/proxy.js +10 -10
- package/node_modules/prebuild-install/rc.js +12 -12
- package/node_modules/prebuild-install/util.js +14 -14
- package/node_modules/simple-get/.github/dependabot.yml +15 -0
- package/node_modules/simple-get/.github/workflows/ci.yml +23 -0
- package/node_modules/simple-get/README.md +17 -3
- package/node_modules/simple-get/index.js +9 -0
- package/node_modules/simple-get/package.json +27 -13
- package/package.json +15 -6
- package/src/data-channel-wrapper.cpp +56 -22
- package/src/data-channel-wrapper.h +3 -0
- package/src/media-audio-wrapper.cpp +5 -5
- package/src/media-track-wrapper.cpp +40 -21
- package/src/media-track-wrapper.h +2 -0
- package/src/media-video-wrapper.cpp +5 -5
- package/src/peer-connection-wrapper.cpp +48 -27
- package/src/peer-connection-wrapper.h +2 -0
- package/test/connectivity.js +6 -6
- package/test/test.js +46 -1
- package/node_modules/detect-libc/.npmignore +0 -7
- package/node_modules/detect-libc/bin/detect-libc.js +0 -18
- package/node_modules/node-abi/.travis.yml +0 -17
- package/node_modules/semver/CHANGELOG.md +0 -39
- package/node_modules/semver/bin/semver +0 -160
- package/node_modules/semver/semver.js +0 -1483
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.js
ADDED
|
@@ -14,7 +14,7 @@ jobs:
|
|
|
14
14
|
runs-on: ubuntu-20.04
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x]
|
|
17
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
20
|
- uses: actions/checkout@v2
|
|
@@ -40,11 +40,12 @@ jobs:
|
|
|
40
40
|
|
|
41
41
|
strategy:
|
|
42
42
|
matrix:
|
|
43
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x]
|
|
43
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
44
44
|
steps:
|
|
45
45
|
- uses: actions/checkout@v2
|
|
46
46
|
- name: Prepare Cross Compile
|
|
47
47
|
run: |
|
|
48
|
+
sudo apt update
|
|
48
49
|
sudo apt install -y g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf
|
|
49
50
|
mkdir sysroot && cd sysroot
|
|
50
51
|
wget https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/ef5c4f84bcafb7a3796d36bb1db7826317dde51c/debian_sid_arm_sysroot.tar.xz
|
|
@@ -67,11 +68,12 @@ jobs:
|
|
|
67
68
|
|
|
68
69
|
strategy:
|
|
69
70
|
matrix:
|
|
70
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x]
|
|
71
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
71
72
|
steps:
|
|
72
73
|
- uses: actions/checkout@v2
|
|
73
74
|
- name: Prepare Cross Compile
|
|
74
75
|
run: |
|
|
76
|
+
sudo apt update
|
|
75
77
|
sudo apt install -y g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
|
|
76
78
|
mkdir sysroot && cd sysroot
|
|
77
79
|
wget https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/953c2471bc7e71a788309f6c2d2003e8b703305d/debian_sid_arm64_sysroot.tar.xz
|
|
@@ -11,10 +11,10 @@ env:
|
|
|
11
11
|
|
|
12
12
|
jobs:
|
|
13
13
|
build-windows-x64:
|
|
14
|
-
runs-on: windows-
|
|
14
|
+
runs-on: windows-2019
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x]
|
|
17
|
+
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
20
|
- uses: actions/checkout@v2
|
|
@@ -39,10 +39,10 @@ jobs:
|
|
|
39
39
|
CI: true
|
|
40
40
|
|
|
41
41
|
build-windows-x86:
|
|
42
|
-
runs-on: windows-
|
|
42
|
+
runs-on: windows-2019
|
|
43
43
|
strategy:
|
|
44
44
|
matrix:
|
|
45
|
-
node_version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x]
|
|
45
|
+
node_version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
|
|
46
46
|
node_arch:
|
|
47
47
|
- x86
|
|
48
48
|
steps:
|
package/.prettierrc.js
ADDED
package/CMakeLists.txt
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
cmake_minimum_required(VERSION 3.15)
|
|
2
2
|
cmake_policy(SET CMP0091 NEW)
|
|
3
|
-
project(node_datachannel VERSION 0.
|
|
3
|
+
project(node_datachannel VERSION 0.3.1)
|
|
4
|
+
|
|
5
|
+
# Workaround for https://github.com/murat-dogan/node-datachannel/issues/65
|
|
6
|
+
if( NODE_RUNTIMEVERSION VERSION_GREATER_EQUAL "17.0.0")
|
|
7
|
+
add_compile_definitions(OPENSSL_API_COMPAT=0x10100001L)
|
|
8
|
+
add_compile_definitions(OPENSSL_CONFIGURED_API=0x30000000L)
|
|
9
|
+
endif()
|
|
4
10
|
|
|
5
11
|
include_directories(${CMAKE_JS_INC})
|
|
6
12
|
|
|
@@ -27,7 +33,7 @@ include(FetchContent)
|
|
|
27
33
|
FetchContent_Declare(
|
|
28
34
|
libdatachannel
|
|
29
35
|
GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
|
|
30
|
-
GIT_TAG "v0.
|
|
36
|
+
GIT_TAG "v0.17.1"
|
|
31
37
|
)
|
|
32
38
|
|
|
33
39
|
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
|
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@ export const enum RelayType {
|
|
|
118
118
|
|
|
119
119
|
export interface IceServer {
|
|
120
120
|
hostname: string;
|
|
121
|
-
port:
|
|
121
|
+
port: number;
|
|
122
122
|
username?: string;
|
|
123
123
|
password?: string;
|
|
124
124
|
relayType?: RelayType;
|
|
@@ -271,15 +271,15 @@ Send Message as binary
|
|
|
271
271
|
|
|
272
272
|
Query data-channel
|
|
273
273
|
|
|
274
|
-
**bufferedAmount: () =>
|
|
274
|
+
**bufferedAmount: () => number**
|
|
275
275
|
|
|
276
276
|
Get current buffered amount level
|
|
277
277
|
|
|
278
|
-
**maxMessageSize: () =>
|
|
278
|
+
**maxMessageSize: () => number**
|
|
279
279
|
|
|
280
280
|
Get max message size of the data-channel, that could be sent
|
|
281
281
|
|
|
282
|
-
**setBufferedAmountLowThreshold: (newSize:
|
|
282
|
+
**setBufferedAmountLowThreshold: (newSize: number) => void**
|
|
283
283
|
|
|
284
284
|
Set buffer level of the `onBufferedAmountLow` callback
|
|
285
285
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const stream = require('stream');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Turns a node-datachannel DataChannel into a real Node.js stream, complete with buffering,
|
|
6
|
+
* backpressure (up to a point - if the buffer fills up, messages are dropped), and
|
|
7
|
+
* support for piping data elsewhere.
|
|
8
|
+
*
|
|
9
|
+
* Read & written data may be either UTF-8 strings or Buffers - this difference exists at
|
|
10
|
+
* the protocol level, and is preserved here throughout.
|
|
11
|
+
*/
|
|
12
|
+
module.exports = class DataChannelStream extends stream.Duplex {
|
|
13
|
+
constructor(rawChannel, streamOptions) {
|
|
14
|
+
super({
|
|
15
|
+
allowHalfOpen: false, // Default to autoclose on end().
|
|
16
|
+
...streamOptions,
|
|
17
|
+
objectMode: true, // Preserve the string/buffer distinction (WebRTC treats them differently)
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
this._rawChannel = rawChannel;
|
|
21
|
+
this._readActive = true;
|
|
22
|
+
|
|
23
|
+
rawChannel.onMessage((msg) => {
|
|
24
|
+
if (!this._readActive) return; // If the buffer is full, drop messages.
|
|
25
|
+
|
|
26
|
+
// If the push is rejected, we pause reading until the next call to _read().
|
|
27
|
+
this._readActive = this.push(msg);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// When the DataChannel closes, the readable & writable ends close
|
|
31
|
+
rawChannel.onClosed(() => {
|
|
32
|
+
this.push(null);
|
|
33
|
+
this.destroy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
rawChannel.onError((errMsg) => {
|
|
37
|
+
this.destroy(new Error(`DataChannel error: ${errMsg}`));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Buffer all writes until the DataChannel opens
|
|
41
|
+
if (!rawChannel.isOpen()) {
|
|
42
|
+
this.cork();
|
|
43
|
+
rawChannel.onOpen(() => this.uncork());
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_read() {
|
|
48
|
+
// Stop dropping messages, if the buffer filling up meant we were doing so before.
|
|
49
|
+
this._readActive = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_write(chunk, encoding, callback) {
|
|
53
|
+
let sentOk;
|
|
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);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (sentOk) {
|
|
69
|
+
callback(null);
|
|
70
|
+
} else {
|
|
71
|
+
callback(new Error('Failed to write to DataChannel'));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_final(callback) {
|
|
76
|
+
if (!this.allowHalfOpen) this.destroy();
|
|
77
|
+
callback(null);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_destroy(maybeErr, callback) {
|
|
81
|
+
// When the stream is destroyed, we close the DataChannel.
|
|
82
|
+
this._rawChannel.close();
|
|
83
|
+
callback(maybeErr);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get label() {
|
|
87
|
+
return this._rawChannel.getLabel();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get id() {
|
|
91
|
+
return this._rawChannel.getId();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get protocol() {
|
|
95
|
+
return this._rawChannel.getProtocol();
|
|
96
|
+
}
|
|
97
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import * as stream from 'stream';
|
|
2
|
+
|
|
1
3
|
export as namespace NodeDataChannel;
|
|
2
4
|
|
|
3
5
|
// Enum in d.ts is tricky
|
|
4
|
-
export type LogLevel =
|
|
6
|
+
export type LogLevel = 'Verbose' | 'Debug' | 'Info' | 'Warning' | 'Error' | 'Fatal';
|
|
5
7
|
|
|
6
8
|
// SCTP Settings
|
|
7
9
|
export interface SctpSettings {
|
|
@@ -20,11 +22,11 @@ export function cleanup(): void;
|
|
|
20
22
|
export function setSctpSettings(settings: SctpSettings): void;
|
|
21
23
|
|
|
22
24
|
// Proxy Server
|
|
23
|
-
export type ProxyServerType = '
|
|
25
|
+
export type ProxyServerType = 'Socks5' | 'Http';
|
|
24
26
|
export interface ProxyServer {
|
|
25
27
|
type: ProxyServerType;
|
|
26
28
|
ip: string;
|
|
27
|
-
port:
|
|
29
|
+
port: number;
|
|
28
30
|
username?: string;
|
|
29
31
|
password?: string;
|
|
30
32
|
}
|
|
@@ -32,12 +34,12 @@ export interface ProxyServer {
|
|
|
32
34
|
export const enum RelayType {
|
|
33
35
|
TurnUdp = 'TurnUdp',
|
|
34
36
|
TurnTcp = 'TurnTcp',
|
|
35
|
-
TurnTls = 'TurnTls'
|
|
37
|
+
TurnTls = 'TurnTls',
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export interface IceServer {
|
|
39
41
|
hostname: string;
|
|
40
|
-
port:
|
|
42
|
+
port: number;
|
|
41
43
|
username?: string;
|
|
42
44
|
password?: string;
|
|
43
45
|
relayType?: RelayType;
|
|
@@ -59,11 +61,13 @@ export const enum DescriptionType {
|
|
|
59
61
|
Offer = 'Offer',
|
|
60
62
|
Answer = 'Answer',
|
|
61
63
|
Pranswer = 'Pranswer',
|
|
62
|
-
Rollback = 'Rollback'
|
|
64
|
+
Rollback = 'Rollback',
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
export const enum ReliabilityType {
|
|
66
|
-
Reliable = 0,
|
|
68
|
+
Reliable = 0,
|
|
69
|
+
Rexmit = 1,
|
|
70
|
+
Timed = 2,
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
export interface DataChannelInitConfig {
|
|
@@ -79,7 +83,7 @@ export interface DataChannelInitConfig {
|
|
|
79
83
|
type?: ReliabilityType;
|
|
80
84
|
unordered?: boolean;
|
|
81
85
|
rexmit?: number;
|
|
82
|
-
}
|
|
86
|
+
};
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
export interface SelectedCandidateInfo {
|
|
@@ -95,62 +99,62 @@ export const enum Direction {
|
|
|
95
99
|
RecvOnly = 'RecvOnly',
|
|
96
100
|
SendRecv = 'SendRecv',
|
|
97
101
|
Inactive = 'Inactive',
|
|
98
|
-
Unknown = 'Unknown'
|
|
102
|
+
Unknown = 'Unknown',
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
export class RtcpReceivingSession {
|
|
102
|
-
requestBitrate: (bitRate:
|
|
106
|
+
requestBitrate: (bitRate: number) => void;
|
|
103
107
|
requestKeyframe: () => boolean;
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
export class Audio {
|
|
107
111
|
constructor(mid: string, dir: Direction);
|
|
108
|
-
addAudioCodec: (payloadType:
|
|
109
|
-
addOpusCodec: (payloadType:
|
|
112
|
+
addAudioCodec: (payloadType: number, codec: string, profile?: string) => void;
|
|
113
|
+
addOpusCodec: (payloadType: number, profile?: string) => string;
|
|
110
114
|
|
|
111
115
|
direction: () => Direction;
|
|
112
|
-
generateSdp: (eol: string, addr: string, port:
|
|
116
|
+
generateSdp: (eol: string, addr: string, port: number) => string;
|
|
113
117
|
mid: () => string;
|
|
114
118
|
setDirection: (dir: Direction) => void;
|
|
115
119
|
description: () => string;
|
|
116
120
|
removeFormat: (fmt: string) => void;
|
|
117
|
-
addSSRC: (ssrc:
|
|
118
|
-
removeSSRC: (ssrc:
|
|
119
|
-
replaceSSRC: (oldSsrc:
|
|
120
|
-
hasSSRC: (ssrc:
|
|
121
|
-
getSSRCs: () =>
|
|
122
|
-
getCNameForSsrc: (ssrc:
|
|
123
|
-
setBitrate: (bitRate:
|
|
124
|
-
getBitrate: () =>
|
|
125
|
-
hasPayloadType: (payloadType:
|
|
126
|
-
addRTXCodec: (payloadType:
|
|
121
|
+
addSSRC: (ssrc: number, name?: string, msid?: string, trackID?: string) => void;
|
|
122
|
+
removeSSRC: (ssrc: number) => void;
|
|
123
|
+
replaceSSRC: (oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string) => void;
|
|
124
|
+
hasSSRC: (ssrc: number) => boolean;
|
|
125
|
+
getSSRCs: () => number[];
|
|
126
|
+
getCNameForSsrc: (ssrc: number) => string;
|
|
127
|
+
setBitrate: (bitRate: number) => void;
|
|
128
|
+
getBitrate: () => number;
|
|
129
|
+
hasPayloadType: (payloadType: number) => boolean;
|
|
130
|
+
addRTXCodec: (payloadType: number, originalPayloadType: number, clockRate: number) => void;
|
|
127
131
|
addRTPMap: () => void;
|
|
128
132
|
parseSdpLine: (line: string) => void;
|
|
129
133
|
}
|
|
130
134
|
|
|
131
135
|
export class Video {
|
|
132
136
|
constructor(mid: string, dir: Direction);
|
|
133
|
-
addVideoCodec: (payloadType:
|
|
134
|
-
addH264Codec: (payloadType:
|
|
135
|
-
addVP8Codec: (payloadType:
|
|
136
|
-
addVP9Codec: (payloadType:
|
|
137
|
+
addVideoCodec: (payloadType: number, codec: string, profile?: string) => void;
|
|
138
|
+
addH264Codec: (payloadType: number, profile?: string) => void;
|
|
139
|
+
addVP8Codec: (payloadType: number) => void;
|
|
140
|
+
addVP9Codec: (payloadType: number) => void;
|
|
137
141
|
|
|
138
142
|
direction: () => Direction;
|
|
139
|
-
generateSdp: (eol: string, addr: string, port:
|
|
143
|
+
generateSdp: (eol: string, addr: string, port: number) => string;
|
|
140
144
|
mid: () => string;
|
|
141
145
|
setDirection: (dir: Direction) => void;
|
|
142
146
|
description: () => string;
|
|
143
147
|
removeFormat: (fmt: string) => void;
|
|
144
|
-
addSSRC: (ssrc:
|
|
145
|
-
removeSSRC: (ssrc:
|
|
146
|
-
replaceSSRC: (oldSsrc:
|
|
147
|
-
hasSSRC: (ssrc:
|
|
148
|
-
getSSRCs: () =>
|
|
149
|
-
getCNameForSsrc: (ssrc:
|
|
150
|
-
setBitrate: (bitRate:
|
|
151
|
-
getBitrate: () =>
|
|
152
|
-
hasPayloadType: (payloadType:
|
|
153
|
-
addRTXCodec: (payloadType:
|
|
148
|
+
addSSRC: (ssrc: number, name?: string, msid?: string, trackID?: string) => void;
|
|
149
|
+
removeSSRC: (ssrc: number) => void;
|
|
150
|
+
replaceSSRC: (oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string) => void;
|
|
151
|
+
hasSSRC: (ssrc: number) => boolean;
|
|
152
|
+
getSSRCs: () => number[];
|
|
153
|
+
getCNameForSsrc: (ssrc: number) => string;
|
|
154
|
+
setBitrate: (bitRate: number) => void;
|
|
155
|
+
getBitrate: () => number;
|
|
156
|
+
hasPayloadType: (payloadType: number) => boolean;
|
|
157
|
+
addRTXCodec: (payloadType: number, originalPayloadType: number, clockRate: number) => void;
|
|
154
158
|
addRTPMap: () => void;
|
|
155
159
|
parseSdpLine: (line: string) => void;
|
|
156
160
|
}
|
|
@@ -158,39 +162,37 @@ export class Video {
|
|
|
158
162
|
export class Track {
|
|
159
163
|
direction: () => Direction;
|
|
160
164
|
mid: () => string;
|
|
165
|
+
type: () => string;
|
|
161
166
|
close: () => void;
|
|
162
167
|
sendMessage: (msg: string) => boolean;
|
|
163
168
|
sendMessageBinary: (buffer: Buffer) => boolean;
|
|
164
169
|
isOpen: () => boolean;
|
|
165
170
|
isClosed: () => boolean;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
setBufferedAmountLowThreshold: (newSize: Number) => void;
|
|
171
|
+
bufferedAmount: () => number;
|
|
172
|
+
maxMessageSize: () => number;
|
|
173
|
+
setBufferedAmountLowThreshold: (newSize: number) => void;
|
|
170
174
|
requestKeyframe: () => boolean;
|
|
171
|
-
setMediaHandler: (handler: RtcpReceivingSession) => void
|
|
175
|
+
setMediaHandler: (handler: RtcpReceivingSession) => void;
|
|
172
176
|
onOpen: (cb: () => void) => void;
|
|
173
177
|
onClosed: (cb: () => void) => void;
|
|
174
178
|
onError: (cb: (err: string) => void) => void;
|
|
175
|
-
|
|
176
|
-
onBufferedAmountLow: (cb: () => void) => void;
|
|
177
|
-
onMessage: (cb: (msg: string | Buffer) => void) => void;
|
|
179
|
+
onMessage: (cb: (msg: Buffer) => void) => void;
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
export class DataChannel {
|
|
181
183
|
close: () => void;
|
|
182
184
|
getLabel: () => string;
|
|
185
|
+
getId: () => number;
|
|
186
|
+
getProtocol: () => string;
|
|
183
187
|
sendMessage: (msg: string) => boolean;
|
|
184
188
|
sendMessageBinary: (buffer: Buffer) => boolean;
|
|
185
189
|
isOpen: () => boolean;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
setBufferedAmountLowThreshold: (newSize: Number) => void;
|
|
190
|
+
bufferedAmount: () => number;
|
|
191
|
+
maxMessageSize: () => number;
|
|
192
|
+
setBufferedAmountLowThreshold: (newSize: number) => void;
|
|
190
193
|
onOpen: (cb: () => void) => void;
|
|
191
194
|
onClosed: (cb: () => void) => void;
|
|
192
195
|
onError: (cb: (err: string) => void) => void;
|
|
193
|
-
onAvailable: (cb: () => void) => void;
|
|
194
196
|
onBufferedAmountLow: (cb: () => void) => void;
|
|
195
197
|
onMessage: (cb: (msg: string | Buffer) => void) => void;
|
|
196
198
|
}
|
|
@@ -198,9 +200,9 @@ export class DataChannel {
|
|
|
198
200
|
export class PeerConnection {
|
|
199
201
|
constructor(peerName: string, config: RtcConfig);
|
|
200
202
|
close: () => void;
|
|
201
|
-
setLocalDescription: (type
|
|
203
|
+
setLocalDescription: (type?: DescriptionType) => void;
|
|
202
204
|
setRemoteDescription: (sdp: string, type: DescriptionType) => void;
|
|
203
|
-
localDescription: () => { type: string
|
|
205
|
+
localDescription: () => { type: string; sdp: string };
|
|
204
206
|
addRemoteCandidate: (candidate: string, mid: string) => void;
|
|
205
207
|
createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel;
|
|
206
208
|
addTrack: (media: Video | Audio) => Track;
|
|
@@ -214,9 +216,14 @@ export class PeerConnection {
|
|
|
214
216
|
onSignalingStateChange: (state: (sdp: string) => void) => void;
|
|
215
217
|
onGatheringStateChange: (state: (sdp: string) => void) => void;
|
|
216
218
|
onDataChannel: (cb: (dc: DataChannel) => void) => void;
|
|
217
|
-
onTrack: () =>
|
|
219
|
+
onTrack: (cb: (track: Track) => void) => void;
|
|
218
220
|
bytesSent: () => number;
|
|
219
221
|
bytesReceived: () => number;
|
|
220
222
|
rtt: () => number;
|
|
221
|
-
getSelectedCandidatePair: () => { local: SelectedCandidateInfo
|
|
223
|
+
getSelectedCandidatePair: () => { local: SelectedCandidateInfo; remote: SelectedCandidateInfo } | null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export class DataChannelStream extends stream.Duplex {
|
|
227
|
+
constructor(rawChannel: DataChannel, options?: Omit<stream.DuplexOptions, 'objectMode'>);
|
|
228
|
+
get label(): string;
|
|
222
229
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const nodeDataChannel = require('../build/Release/node_datachannel.node');
|
|
3
|
+
module.exports = nodeDataChannel;
|
|
4
|
+
|
|
5
|
+
module.exports.DataChannelStream = require('./datachannel-stream');
|
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
/// <reference types="node"/>
|
|
2
2
|
import {IncomingMessage} from 'http';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Decompress a HTTP response if needed.
|
|
4
|
+
/**
|
|
5
|
+
Decompress a HTTP response if needed.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
@param response - The HTTP incoming stream with compressed data.
|
|
8
|
+
@returns The decompressed HTTP response stream.
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import {http} from 'http';
|
|
13
|
+
import decompressResponse = require('decompress-response');
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// TODO: remove this in the next major version, refactor the whole definition to:
|
|
24
|
-
// declare function decompressResponse(response: IncomingMessage): IncomingMessage;
|
|
25
|
-
// export = decompressResponse;
|
|
26
|
-
default: typeof decompressResponse;
|
|
27
|
-
};
|
|
15
|
+
http.get('https://sindresorhus.com', response => {
|
|
16
|
+
response = decompressResponse(response);
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
*/
|
|
20
|
+
declare function decompressResponse(response: IncomingMessage): IncomingMessage;
|
|
28
21
|
|
|
29
22
|
export = decompressResponse;
|
|
@@ -1,40 +1,58 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {PassThrough
|
|
2
|
+
const {Transform, PassThrough} = require('stream');
|
|
3
3
|
const zlib = require('zlib');
|
|
4
4
|
const mimicResponse = require('mimic-response');
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
module.exports = response => {
|
|
7
7
|
const contentEncoding = (response.headers['content-encoding'] || '').toLowerCase();
|
|
8
8
|
|
|
9
9
|
if (!['gzip', 'deflate', 'br'].includes(contentEncoding)) {
|
|
10
10
|
return response;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// TODO: Remove this when targeting Node.js 12.
|
|
13
14
|
const isBrotli = contentEncoding === 'br';
|
|
14
15
|
if (isBrotli && typeof zlib.createBrotliDecompress !== 'function') {
|
|
16
|
+
response.destroy(new Error('Brotli is not supported on Node.js < 12'));
|
|
15
17
|
return response;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
const stream = new PassThroughStream();
|
|
20
|
+
let isEmpty = true;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
const checker = new Transform({
|
|
23
|
+
transform(data, _encoding, callback) {
|
|
24
|
+
isEmpty = false;
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
callback(null, data);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
flush(callback) {
|
|
30
|
+
callback();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const finalStream = new PassThrough({
|
|
35
|
+
autoDestroy: false,
|
|
36
|
+
destroy(error, callback) {
|
|
37
|
+
response.destroy();
|
|
38
|
+
|
|
39
|
+
callback(error);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const decompressStream = isBrotli ? zlib.createBrotliDecompress() : zlib.createUnzip();
|
|
44
|
+
|
|
45
|
+
decompressStream.once('error', error => {
|
|
46
|
+
if (isEmpty && !response.readable) {
|
|
47
|
+
finalStream.end();
|
|
27
48
|
return;
|
|
28
49
|
}
|
|
29
50
|
|
|
30
|
-
|
|
51
|
+
finalStream.destroy(error);
|
|
31
52
|
});
|
|
32
53
|
|
|
33
|
-
response
|
|
54
|
+
mimicResponse(response, finalStream);
|
|
55
|
+
response.pipe(checker).pipe(decompressStream).pipe(finalStream);
|
|
34
56
|
|
|
35
|
-
return
|
|
57
|
+
return finalStream;
|
|
36
58
|
};
|
|
37
|
-
|
|
38
|
-
module.exports = decompressResponse;
|
|
39
|
-
// TODO: remove this in the next major version
|
|
40
|
-
module.exports.default = decompressResponse;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|