node-datachannel 0.21.0 → 0.23.0
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/.eslintignore +3 -1
- package/API.md +1 -0
- package/CMakeLists.txt +6 -1
- package/README.md +2 -2
- package/dist/cjs/lib/datachannel-stream.cjs.map +1 -1
- package/dist/cjs/lib/index.cjs.map +1 -1
- package/dist/cjs/lib/node-datachannel.cjs +3 -0
- package/dist/cjs/lib/node-datachannel.cjs.map +1 -1
- package/dist/cjs/lib/websocket-server.cjs +1 -0
- package/dist/cjs/lib/websocket-server.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCDataChannel.cjs +5 -3
- package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCIceCandidate.cjs +0 -2
- package/dist/cjs/polyfill/RTCIceCandidate.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCPeerConnection.cjs +7 -5
- package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
- package/dist/esm/lib/datachannel-stream.mjs.map +1 -1
- package/dist/esm/lib/index.mjs.map +1 -1
- package/dist/esm/lib/node-datachannel.mjs +3 -0
- package/dist/esm/lib/node-datachannel.mjs.map +1 -1
- package/dist/esm/lib/websocket-server.mjs +1 -0
- package/dist/esm/lib/websocket-server.mjs.map +1 -1
- package/dist/esm/polyfill/RTCDataChannel.mjs +5 -3
- package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -1
- package/dist/esm/polyfill/RTCIceCandidate.mjs +0 -2
- package/dist/esm/polyfill/RTCIceCandidate.mjs.map +1 -1
- package/dist/esm/polyfill/RTCPeerConnection.mjs +7 -5
- package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
- package/dist/types/lib/index.d.ts +5 -5
- package/dist/types/lib/types.d.ts +2 -1
- package/package.json +7 -8
- package/src/cpp/data-channel-wrapper.cpp +7 -3
- package/src/cpp/media-audio-wrapper.cpp +7 -3
- package/src/cpp/media-rtcpreceivingsession-wrapper.cpp +7 -3
- package/src/cpp/media-track-wrapper.cpp +7 -3
- package/src/cpp/media-video-wrapper.cpp +7 -3
- package/src/cpp/peer-connection-wrapper.cpp +12 -3
- package/src/cpp/web-socket-server-wrapper.cpp +7 -3
- package/src/cpp/web-socket-wrapper.cpp +7 -3
- package/src/lib/datachannel-stream.ts +1 -1
- package/src/lib/index.ts +3 -3
- package/src/lib/node-datachannel.ts +5 -0
- package/src/lib/types.ts +2 -1
- package/src/lib/websocket-server.ts +1 -0
- package/src/polyfill/RTCDataChannel.ts +5 -3
- package/src/polyfill/RTCIceCandidate.ts +0 -1
- package/src/polyfill/RTCPeerConnection.ts +8 -5
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#include <cctype>
|
|
10
10
|
#include <sstream>
|
|
11
11
|
|
|
12
|
-
Napi::FunctionReference PeerConnectionWrapper::constructor;
|
|
12
|
+
Napi::FunctionReference PeerConnectionWrapper::constructor = Napi::FunctionReference();
|
|
13
13
|
std::unordered_set<PeerConnectionWrapper *> PeerConnectionWrapper::instances;
|
|
14
14
|
|
|
15
15
|
void PeerConnectionWrapper::CloseAll()
|
|
@@ -65,8 +65,12 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
|
|
|
65
65
|
InstanceMethod("maxMessageSize", &PeerConnectionWrapper::maxMessageSize),
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
constructor
|
|
69
|
-
constructor.
|
|
68
|
+
// If this is not the first call, we don't want to reassign the constructor (hot-reload problem)
|
|
69
|
+
if(constructor.IsEmpty())
|
|
70
|
+
{
|
|
71
|
+
constructor = Napi::Persistent(func);
|
|
72
|
+
constructor.SuppressDestruct();
|
|
73
|
+
}
|
|
70
74
|
|
|
71
75
|
exports.Set("PeerConnection", func);
|
|
72
76
|
return exports;
|
|
@@ -242,6 +246,11 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
|
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
248
|
|
|
249
|
+
// Allow skipping fingerprint validation
|
|
250
|
+
if (config.Get("disableFingerprintVerification").IsBoolean()) {
|
|
251
|
+
rtcConfig.disableFingerprintVerification = config.Get("disableFingerprintVerification").As<Napi::Boolean>();
|
|
252
|
+
}
|
|
253
|
+
|
|
245
254
|
// Create peer-connection
|
|
246
255
|
try
|
|
247
256
|
{
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include "plog/Log.h"
|
|
4
4
|
|
|
5
|
-
Napi::FunctionReference WebSocketServerWrapper::constructor;
|
|
5
|
+
Napi::FunctionReference WebSocketServerWrapper::constructor = Napi::FunctionReference();
|
|
6
6
|
std::unordered_set<WebSocketServerWrapper *> WebSocketServerWrapper::instances;
|
|
7
7
|
|
|
8
8
|
void WebSocketServerWrapper::StopAll()
|
|
@@ -26,8 +26,12 @@ Napi::Object WebSocketServerWrapper::Init(Napi::Env env, Napi::Object exports)
|
|
|
26
26
|
InstanceMethod("onClient", &WebSocketServerWrapper::onClient)
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
constructor
|
|
30
|
-
constructor.
|
|
29
|
+
// If this is not the first call, we don't want to reassign the constructor (hot-reload problem)
|
|
30
|
+
if(constructor.IsEmpty())
|
|
31
|
+
{
|
|
32
|
+
constructor = Napi::Persistent(func);
|
|
33
|
+
constructor.SuppressDestruct();
|
|
34
|
+
}
|
|
31
35
|
|
|
32
36
|
exports.Set("WebSocketServer", func);
|
|
33
37
|
return exports;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include "plog/Log.h"
|
|
4
4
|
|
|
5
|
-
Napi::FunctionReference WebSocketWrapper::constructor;
|
|
5
|
+
Napi::FunctionReference WebSocketWrapper::constructor = Napi::FunctionReference();
|
|
6
6
|
std::unordered_set<WebSocketWrapper *> WebSocketWrapper::instances;
|
|
7
7
|
|
|
8
8
|
void WebSocketWrapper::CloseAll()
|
|
@@ -47,8 +47,12 @@ Napi::Object WebSocketWrapper::Init(Napi::Env env, Napi::Object exports)
|
|
|
47
47
|
InstanceMethod("path", &WebSocketWrapper::path),
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
constructor
|
|
51
|
-
constructor.
|
|
50
|
+
// If this is not the first call, we don't want to reassign the constructor (hot-reload problem)
|
|
51
|
+
if(constructor.IsEmpty())
|
|
52
|
+
{
|
|
53
|
+
constructor = Napi::Persistent(func);
|
|
54
|
+
constructor.SuppressDestruct();
|
|
55
|
+
}
|
|
52
56
|
|
|
53
57
|
exports.Set("WebSocket", func);
|
|
54
58
|
return exports;
|
package/src/lib/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import nodeDataChannel from './node-datachannel';
|
|
2
2
|
import _DataChannelStream from './datachannel-stream';
|
|
3
3
|
import { WebSocketServer } from './websocket-server';
|
|
4
|
-
import { Channel, DataChannelInitConfig, DescriptionType, Direction, LogLevel, RtcConfig, RTCIceConnectionState, RTCIceGatheringState, RTCPeerConnectionState,
|
|
4
|
+
import { Channel, DataChannelInitConfig, DescriptionType, Direction, LogLevel, RtcConfig, RTCIceConnectionState, RTCIceGatheringState, RTCPeerConnectionState, RTCSignalingState, SctpSettings, SelectedCandidateInfo } from './types';
|
|
5
5
|
import { WebSocket } from './websocket';
|
|
6
6
|
|
|
7
7
|
export function preload(): void { nodeDataChannel.preload(); }
|
|
@@ -105,7 +105,7 @@ export interface DataChannel extends Channel {
|
|
|
105
105
|
onClosed(cb: () => void): void;
|
|
106
106
|
onError(cb: (err: string) => void): void;
|
|
107
107
|
onBufferedAmountLow(cb: () => void): void;
|
|
108
|
-
onMessage(cb: (msg: string | Buffer) => void): void;
|
|
108
|
+
onMessage(cb: (msg: string | Buffer | ArrayBuffer) => void): void;
|
|
109
109
|
}
|
|
110
110
|
export const DataChannel: {
|
|
111
111
|
// DataChannel implementation
|
|
@@ -115,7 +115,7 @@ export interface PeerConnection {
|
|
|
115
115
|
close(): void;
|
|
116
116
|
setLocalDescription(type?: DescriptionType): void;
|
|
117
117
|
setRemoteDescription(sdp: string, type: DescriptionType): void;
|
|
118
|
-
localDescription(): { type: DescriptionType; sdp:
|
|
118
|
+
localDescription(): { type: DescriptionType; sdp: string } | null;
|
|
119
119
|
remoteDescription(): { type: DescriptionType; sdp: string } | null;
|
|
120
120
|
addRemoteCandidate(candidate: string, mid: string): void;
|
|
121
121
|
createDataChannel(label: string, config?: DataChannelInitConfig): DataChannel;
|
|
@@ -5,6 +5,11 @@ try {
|
|
|
5
5
|
nodeDataChannel = require('../../../build/Release/node_datachannel.node');
|
|
6
6
|
}
|
|
7
7
|
catch (e) {
|
|
8
|
+
// If this is not a module not found error, rethrow it
|
|
9
|
+
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
10
|
+
throw e;
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
// from src
|
|
9
14
|
nodeDataChannel = require('../../build/Release/node_datachannel.node');
|
|
10
15
|
}
|
package/src/lib/types.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface Channel {
|
|
|
10
10
|
onClosed(cb: () => void): void;
|
|
11
11
|
onError(cb: (err: string) => void): void;
|
|
12
12
|
onBufferedAmountLow(cb: () => void): void;
|
|
13
|
-
onMessage(cb: (msg: string | Buffer) => void): void;
|
|
13
|
+
onMessage(cb: (msg: string | Buffer | ArrayBuffer) => void): void;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface WebSocketServerConfiguration {
|
|
@@ -76,6 +76,7 @@ export interface RtcConfig {
|
|
|
76
76
|
maxMessageSize?: number;
|
|
77
77
|
mtu?: number;
|
|
78
78
|
iceTransportPolicy?: TransportPolicy;
|
|
79
|
+
disableFingerprintVerification?: boolean;
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
// Lowercase to match the description type string from libdatachannel
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import 'node-domexception';
|
|
3
2
|
import * as exceptions from './Exception';
|
|
4
3
|
import { DataChannel } from '../lib/index';
|
|
5
4
|
|
|
@@ -27,7 +26,7 @@ export default class RTCDataChannel extends EventTarget implements globalThis.RT
|
|
|
27
26
|
super();
|
|
28
27
|
|
|
29
28
|
this.#dataChannel = dataChannel;
|
|
30
|
-
this.#binaryType = '
|
|
29
|
+
this.#binaryType = 'blob';
|
|
31
30
|
this.#readyState = this.#dataChannel.isOpen() ? 'open' : 'connecting';
|
|
32
31
|
this.#bufferedAmountLowThreshold = 0;
|
|
33
32
|
this.#maxPacketLifeTime = opts.maxPacketLifeTime || null;
|
|
@@ -73,7 +72,10 @@ export default class RTCDataChannel extends EventTarget implements globalThis.RT
|
|
|
73
72
|
|
|
74
73
|
this.#dataChannel.onMessage((data) => {
|
|
75
74
|
if (ArrayBuffer.isView(data)) {
|
|
76
|
-
|
|
75
|
+
if (this.binaryType == 'arraybuffer')
|
|
76
|
+
data = data.buffer;
|
|
77
|
+
else
|
|
78
|
+
data = Buffer.from(data.buffer);
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
this.dispatchEvent(new MessageEvent('message', { data }));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import 'node-domexception';
|
|
3
2
|
import { SelectedCandidateInfo } from '../lib/types';
|
|
4
3
|
import { PeerConnection } from '../lib/index';
|
|
5
4
|
import RTCSessionDescription from './RTCSessionDescription';
|
|
@@ -383,10 +382,14 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
|
|
|
383
382
|
getStats(): Promise<globalThis.RTCStatsReport> {
|
|
384
383
|
return new Promise((resolve) => {
|
|
385
384
|
const report = new Map();
|
|
386
|
-
const cp = this.#peerConnection
|
|
387
|
-
const bytesSent = this.#peerConnection
|
|
388
|
-
const bytesReceived = this.#peerConnection
|
|
389
|
-
const rtt = this.#peerConnection
|
|
385
|
+
const cp = this.#peerConnection?.getSelectedCandidatePair();
|
|
386
|
+
const bytesSent = this.#peerConnection?.bytesSent();
|
|
387
|
+
const bytesReceived = this.#peerConnection?.bytesReceived();
|
|
388
|
+
const rtt = this.#peerConnection?.rtt();
|
|
389
|
+
|
|
390
|
+
if(!cp) {
|
|
391
|
+
return resolve(report);
|
|
392
|
+
}
|
|
390
393
|
|
|
391
394
|
const localIdRs = getRandomString(8);
|
|
392
395
|
const localId = 'RTCIceCandidate_' + localIdRs;
|