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
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,7 +40,7 @@ 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
|
|
@@ -68,7 +68,7 @@ jobs:
|
|
|
68
68
|
|
|
69
69
|
strategy:
|
|
70
70
|
matrix:
|
|
71
|
-
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]
|
|
72
72
|
steps:
|
|
73
73
|
- uses: actions/checkout@v2
|
|
74
74
|
- name: Prepare Cross Compile
|
|
@@ -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:
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v3
|
|
17
|
+
- name: Use Node.js
|
|
18
|
+
uses: actions/setup-node@v3
|
|
19
|
+
with:
|
|
20
|
+
node-version: '16.x'
|
|
21
|
+
- run: npm ci
|
|
22
|
+
- run: npm run lint
|
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.2
|
|
3
|
+
project(node_datachannel VERSION 0.3.2)
|
|
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.3"
|
|
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
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const yargs = require('yargs/yargs');
|
|
3
|
+
const { hideBin } = require('yargs/helpers');
|
|
3
4
|
const nodeDataChannel = require('../../lib/index');
|
|
4
5
|
const WebSocket = require('ws');
|
|
5
|
-
const readline = require(
|
|
6
|
+
const readline = require('readline');
|
|
6
7
|
|
|
7
8
|
// Init Logger
|
|
8
9
|
nodeDataChannel.initLogger('Debug');
|
|
@@ -26,38 +27,36 @@ const argv = yargs(hideBin(process.argv))
|
|
|
26
27
|
.option('disableSend', {
|
|
27
28
|
type: 'boolean',
|
|
28
29
|
description: 'Disable Send',
|
|
29
|
-
default: false
|
|
30
|
+
default: false,
|
|
30
31
|
})
|
|
31
32
|
.option('wsUrl', {
|
|
32
33
|
type: 'string',
|
|
33
34
|
description: 'Web Socket URL',
|
|
34
|
-
default: 'ws://localhost:8000'
|
|
35
|
+
default: 'ws://localhost:8000',
|
|
35
36
|
})
|
|
36
37
|
.option('dataChannelCount', {
|
|
37
38
|
type: 'number',
|
|
38
39
|
description: 'Data Channel Count To Create',
|
|
39
|
-
default: 1
|
|
40
|
-
})
|
|
41
|
-
.argv;
|
|
40
|
+
default: 1,
|
|
41
|
+
}).argv;
|
|
42
42
|
|
|
43
43
|
// Disable Send
|
|
44
|
-
const disableSend = argv.disableSend
|
|
44
|
+
const disableSend = argv.disableSend;
|
|
45
45
|
if (disableSend) console.log('Send Disabled!');
|
|
46
46
|
|
|
47
47
|
// Signaling Server
|
|
48
48
|
const wsUrl = process.env.WS_URL || argv.wsUrl;
|
|
49
|
-
console.log(wsUrl)
|
|
49
|
+
console.log(wsUrl);
|
|
50
50
|
const dataChannelCount = argv.dataChannelCount;
|
|
51
51
|
|
|
52
52
|
// Read Line Interface
|
|
53
53
|
const rl = readline.createInterface({
|
|
54
54
|
input: process.stdin,
|
|
55
|
-
output: process.stdout
|
|
55
|
+
output: process.stdout,
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
|
|
59
58
|
const ws = new WebSocket(wsUrl + '/' + id, {
|
|
60
|
-
perMessageDeflate: false
|
|
59
|
+
perMessageDeflate: false,
|
|
61
60
|
});
|
|
62
61
|
|
|
63
62
|
console.log(`The local ID is: ${id}`);
|
|
@@ -104,7 +103,7 @@ function readUserInput() {
|
|
|
104
103
|
let dcArrItem = {
|
|
105
104
|
dc: null,
|
|
106
105
|
bytesSent: 0,
|
|
107
|
-
bytesReceived: 0
|
|
106
|
+
bytesReceived: 0,
|
|
108
107
|
};
|
|
109
108
|
console.log('Creating DataChannel with label "test-' + i + '"');
|
|
110
109
|
dcArrItem.dc = pcMap[peerId].createDataChannel('test-' + i);
|
|
@@ -112,16 +111,16 @@ function readUserInput() {
|
|
|
112
111
|
dcArrItem.dc.setBufferedAmountLowThreshold(BUFFER_SIZE);
|
|
113
112
|
dcArrItem.dc.onOpen(() => {
|
|
114
113
|
while (!disableSend && dcArrItem.dc.bufferedAmount() <= BUFFER_SIZE) {
|
|
115
|
-
dcArrItem.dc.sendMessage(msgToSend)
|
|
116
|
-
dcArrItem.bytesSent += msgToSend.length
|
|
117
|
-
}
|
|
114
|
+
dcArrItem.dc.sendMessage(msgToSend);
|
|
115
|
+
dcArrItem.bytesSent += msgToSend.length;
|
|
116
|
+
}
|
|
118
117
|
});
|
|
119
118
|
|
|
120
119
|
dcArrItem.dc.onBufferedAmountLow(() => {
|
|
121
120
|
while (!disableSend && dcArrItem.dc.bufferedAmount() <= BUFFER_SIZE) {
|
|
122
|
-
dcArrItem.dc.sendMessage(msgToSend)
|
|
123
|
-
dcArrItem.bytesSent += msgToSend.length
|
|
124
|
-
}
|
|
121
|
+
dcArrItem.dc.sendMessage(msgToSend);
|
|
122
|
+
dcArrItem.bytesSent += msgToSend.length;
|
|
123
|
+
}
|
|
125
124
|
});
|
|
126
125
|
|
|
127
126
|
dcArrItem.dc.onMessage((msg) => {
|
|
@@ -131,23 +130,36 @@ function readUserInput() {
|
|
|
131
130
|
dcArr.push(dcArrItem);
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
|
|
135
133
|
// Report
|
|
136
134
|
let i = 0;
|
|
137
135
|
setInterval(() => {
|
|
138
136
|
let totalBytesSent = 0;
|
|
139
137
|
let totalBytesReceived = 0;
|
|
140
138
|
for (let j = 0; j < dcArr.length; j++) {
|
|
141
|
-
console.log(
|
|
139
|
+
console.log(
|
|
140
|
+
`${j == 0 ? i + '#' : ''} DC-${j + 1} Sent: ${byte2KB(
|
|
141
|
+
dcArr[j].bytesSent,
|
|
142
|
+
)} KB/s / Received: ${byte2KB(dcArr[j].bytesReceived)} KB/s / SendBufferAmount: ${dcArr[
|
|
143
|
+
j
|
|
144
|
+
].dc.bufferedAmount()} / DataChannelOpen: ${dcArr[j].dc.isOpen()}`,
|
|
145
|
+
);
|
|
142
146
|
totalBytesSent += dcArr[j].bytesSent;
|
|
143
147
|
totalBytesReceived += dcArr[j].bytesReceived;
|
|
144
148
|
dcArr[j].bytesSent = 0;
|
|
145
149
|
dcArr[j].bytesReceived = 0;
|
|
146
150
|
}
|
|
147
|
-
console.log(
|
|
151
|
+
console.log(
|
|
152
|
+
`Total Sent: ${byte2KB(totalBytesSent)} KB/s / Total Received: ${byte2KB(
|
|
153
|
+
totalBytesReceived,
|
|
154
|
+
)} KB/s`,
|
|
155
|
+
);
|
|
148
156
|
|
|
149
157
|
if (i % 5 == 0) {
|
|
150
|
-
console.log(
|
|
158
|
+
console.log(
|
|
159
|
+
`Stats# Sent: ${byte2MB(pcMap[peerId].bytesSent())} MB / Received: ${byte2MB(
|
|
160
|
+
pcMap[peerId].bytesReceived(),
|
|
161
|
+
)} MB / rtt: ${pcMap[peerId].rtt()} ms`,
|
|
162
|
+
);
|
|
151
163
|
console.log(`Selected Candidates# ${JSON.stringify(pcMap[peerId].getSelectedCandidatePair())}`);
|
|
152
164
|
console.log(``);
|
|
153
165
|
}
|
|
@@ -179,16 +191,15 @@ function createPeerConnection(peerId) {
|
|
|
179
191
|
let msgToSend = randomId(MESSAGE_SIZE);
|
|
180
192
|
|
|
181
193
|
while (!disableSend && dc.bufferedAmount() <= BUFFER_SIZE) {
|
|
182
|
-
dc.sendMessage(msgToSend)
|
|
183
|
-
}
|
|
194
|
+
dc.sendMessage(msgToSend);
|
|
195
|
+
}
|
|
184
196
|
|
|
185
197
|
dc.onBufferedAmountLow(() => {
|
|
186
198
|
while (!disableSend && dc.bufferedAmount() <= BUFFER_SIZE) {
|
|
187
|
-
dc.sendMessage(msgToSend)
|
|
188
|
-
}
|
|
199
|
+
dc.sendMessage(msgToSend);
|
|
200
|
+
}
|
|
189
201
|
});
|
|
190
202
|
|
|
191
|
-
|
|
192
203
|
dc.onMessage((msg) => {
|
|
193
204
|
// bytesReceived += msg.length;
|
|
194
205
|
});
|
|
@@ -208,9 +219,9 @@ function randomId(length) {
|
|
|
208
219
|
}
|
|
209
220
|
|
|
210
221
|
function byte2KB(bytes) {
|
|
211
|
-
return `${Math.round(bytes / 1000)}
|
|
222
|
+
return `${Math.round(bytes / 1000)}`;
|
|
212
223
|
}
|
|
213
224
|
|
|
214
225
|
function byte2MB(bytes) {
|
|
215
|
-
return `${Math.round(bytes / (1000 * 1000))}
|
|
216
|
-
}
|
|
226
|
+
return `${Math.round(bytes / (1000 * 1000))}`;
|
|
227
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
1
2
|
const nodeDataChannel = require('../../lib/index');
|
|
2
3
|
const WebSocket = require('ws');
|
|
3
|
-
const readline = require(
|
|
4
|
+
const readline = require('readline');
|
|
4
5
|
|
|
5
6
|
// Init Logger
|
|
6
7
|
nodeDataChannel.initLogger('Debug');
|
|
@@ -20,13 +21,13 @@ const BUFFER_SIZE = MESSAGE_SIZE * 10;
|
|
|
20
21
|
// Read Line Interface
|
|
21
22
|
const rl = readline.createInterface({
|
|
22
23
|
input: process.stdin,
|
|
23
|
-
output: process.stdout
|
|
24
|
+
output: process.stdout,
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
// Signaling Server
|
|
27
|
-
const WS_URL = process.env.WS_URL ||
|
|
28
|
+
const WS_URL = process.env.WS_URL || 'ws://localhost:8000';
|
|
28
29
|
const ws = new WebSocket(WS_URL + '/' + id, {
|
|
29
|
-
perMessageDeflate: false
|
|
30
|
+
perMessageDeflate: false,
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
console.log(`The local ID is: ${id}`);
|
|
@@ -77,7 +78,7 @@ function readUserInput() {
|
|
|
77
78
|
dc.onOpen(() => {
|
|
78
79
|
setInterval(() => {
|
|
79
80
|
if (dc.bufferedAmount() <= BUFFER_SIZE) {
|
|
80
|
-
dc.sendMessage(msgToSend)
|
|
81
|
+
dc.sendMessage(msgToSend);
|
|
81
82
|
bytesSent += msgToSend.length;
|
|
82
83
|
}
|
|
83
84
|
}, 2);
|
|
@@ -90,13 +91,21 @@ function readUserInput() {
|
|
|
90
91
|
// Report
|
|
91
92
|
let i = 0;
|
|
92
93
|
setInterval(() => {
|
|
93
|
-
console.log(
|
|
94
|
+
console.log(
|
|
95
|
+
`${i++}# Sent: ${byte2KB(bytesSent)} KB/s / Received: ${byte2KB(
|
|
96
|
+
bytesReceived,
|
|
97
|
+
)} KB/s / SendBufferAmount: ${dc.bufferedAmount()} / DataChannelOpen: ${dc.isOpen()}`,
|
|
98
|
+
);
|
|
94
99
|
bytesSent = 0;
|
|
95
100
|
bytesReceived = 0;
|
|
96
101
|
}, 1000);
|
|
97
102
|
|
|
98
103
|
setInterval(() => {
|
|
99
|
-
console.log(
|
|
104
|
+
console.log(
|
|
105
|
+
`Stats# Sent: ${byte2MB(pcMap[peerId].bytesSent())} MB / Received: ${byte2MB(
|
|
106
|
+
pcMap[peerId].bytesReceived(),
|
|
107
|
+
)} MB / rtt: ${pcMap[peerId].rtt()} ms`,
|
|
108
|
+
);
|
|
100
109
|
console.log(`Selected Candidates# ${JSON.stringify(pcMap[peerId].getSelectedCandidatePair())}`);
|
|
101
110
|
console.log(``);
|
|
102
111
|
}, 5 * 1000);
|
|
@@ -129,12 +138,11 @@ function createPeerConnection(peerId) {
|
|
|
129
138
|
|
|
130
139
|
setInterval(() => {
|
|
131
140
|
if (dc.bufferedAmount() <= BUFFER_SIZE) {
|
|
132
|
-
dc.sendMessage(msgToSend)
|
|
141
|
+
dc.sendMessage(msgToSend);
|
|
133
142
|
bytesSent += msgToSend.length;
|
|
134
143
|
}
|
|
135
144
|
}, 2);
|
|
136
145
|
|
|
137
|
-
|
|
138
146
|
dc.onMessage((msg) => {
|
|
139
147
|
bytesReceived += msg.length;
|
|
140
148
|
});
|
|
@@ -142,13 +150,21 @@ function createPeerConnection(peerId) {
|
|
|
142
150
|
// Report
|
|
143
151
|
let i = 0;
|
|
144
152
|
setInterval(() => {
|
|
145
|
-
console.log(
|
|
153
|
+
console.log(
|
|
154
|
+
`${i++}# Sent: ${byte2KB(bytesSent)} KB/s / Received: ${byte2KB(
|
|
155
|
+
bytesReceived,
|
|
156
|
+
)} KB/s / SendBufferAmount: ${dc.bufferedAmount()} / DataChannelOpen: ${dc.isOpen()}`,
|
|
157
|
+
);
|
|
146
158
|
bytesSent = 0;
|
|
147
159
|
bytesReceived = 0;
|
|
148
160
|
}, 1000);
|
|
149
161
|
|
|
150
162
|
setInterval(() => {
|
|
151
|
-
console.log(
|
|
163
|
+
console.log(
|
|
164
|
+
`Stats# Sent: ${byte2MB(pcMap[peerId].bytesSent())} MB / Received: ${byte2MB(
|
|
165
|
+
pcMap[peerId].bytesReceived(),
|
|
166
|
+
)} MB / rtt: ${pcMap[peerId].rtt()} ms`,
|
|
167
|
+
);
|
|
152
168
|
console.log(`Selected Candidates# ${JSON.stringify(pcMap[peerId].getSelectedCandidatePair())}`);
|
|
153
169
|
console.log(``);
|
|
154
170
|
}, 5 * 1000);
|
|
@@ -168,9 +184,9 @@ function randomId(length) {
|
|
|
168
184
|
}
|
|
169
185
|
|
|
170
186
|
function byte2KB(bytes) {
|
|
171
|
-
return `${Math.round(bytes / 1024)}
|
|
187
|
+
return `${Math.round(bytes / 1024)}`;
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
function byte2MB(bytes) {
|
|
175
|
-
return `${Math.round(bytes / (1024 * 1024))}
|
|
176
|
-
}
|
|
191
|
+
return `${Math.round(bytes / (1024 * 1024))}`;
|
|
192
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
1
2
|
const nodeDataChannel = require('../../lib/index');
|
|
2
3
|
const WebSocket = require('ws');
|
|
3
|
-
const readline = require(
|
|
4
|
+
const readline = require('readline');
|
|
4
5
|
|
|
5
6
|
// Init Logger
|
|
6
7
|
nodeDataChannel.initLogger('Error');
|
|
@@ -12,9 +13,9 @@ const pcMap = {};
|
|
|
12
13
|
const id = randomId(4);
|
|
13
14
|
|
|
14
15
|
// Signaling Server
|
|
15
|
-
const WS_URL = process.env.WS_URL ||
|
|
16
|
+
const WS_URL = process.env.WS_URL || 'ws://localhost:8000';
|
|
16
17
|
const ws = new WebSocket(WS_URL + '/' + id, {
|
|
17
|
-
perMessageDeflate: false
|
|
18
|
+
perMessageDeflate: false,
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
console.log(`The local ID is: ${id}`);
|
|
@@ -52,7 +53,7 @@ function readUserInput() {
|
|
|
52
53
|
// Read Line Interface
|
|
53
54
|
const rl = readline.createInterface({
|
|
54
55
|
input: process.stdin,
|
|
55
|
-
output: process.stdout
|
|
56
|
+
output: process.stdout,
|
|
56
57
|
});
|
|
57
58
|
|
|
58
59
|
rl.question('Enter a remote ID to send an offer:\n', (peerId) => {
|
|
@@ -110,4 +111,4 @@ function randomId(length) {
|
|
|
110
111
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
111
112
|
}
|
|
112
113
|
return result;
|
|
113
|
-
}
|
|
114
|
+
}
|