@lakutata/webrtc 3.1.4 → 3.1.5
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/README.md +2 -1
- package/README.zh-CN.md +1 -1
- package/dist/cjs/exceptions/SignalingConnectionException.d.ts +1 -1
- package/dist/cjs/exceptions/SignalingConnectionException.js +1 -1
- package/dist/cjs/lib/peer/peerConnection.d.ts +2 -0
- package/dist/cjs/lib/peer/peerConnection.js +4 -2
- package/dist/cjs/peer/PeerThreads.js +12 -2
- package/dist/cjs/peer/PeerWorkerCode.js +1 -1
- package/dist/cjs/peer/SignalingClient.d.ts +2 -1
- package/dist/cjs/peer/SignalingClient.js +22 -4
- package/dist/cjs/sfu/SFUWorkerCode.js +1 -1
- package/dist/cjs/shared/SignalingSession.js +1 -0
- package/dist/cjs/shared/Transports.d.ts +1 -1
- package/dist/esm/exceptions/SignalingConnectionException.js +1 -1
- package/dist/esm/lib/peer/peerConnection.js +4 -2
- package/dist/esm/peer/PeerThreads.js +9 -2
- package/dist/esm/peer/PeerWorkerCode.js +1 -1
- package/dist/esm/peer/SignalingClient.js +23 -5
- package/dist/esm/sfu/SFUWorkerCode.js +1 -1
- package/dist/esm/shared/SignalingSession.js +1 -0
- package/dist/types/exceptions/SignalingConnectionException.d.ts +1 -1
- package/dist/types/lib/peer/peerConnection.d.ts +2 -0
- package/dist/types/peer/SignalingClient.d.ts +2 -1
- package/dist/types/shared/Transports.d.ts +1 -1
- package/package.json +9 -5
|
@@ -75,7 +75,8 @@ export interface SignalingClientOptions {
|
|
|
75
75
|
* A lakutata application as a member of the rooms of a signaling server of this package (`Signaling` and
|
|
76
76
|
* `SignalingController`, on this application or another one): it joins rooms and connects to their other members,
|
|
77
77
|
* browsers or applications, with {@link PeerConnection}s. Over Socket.IO (an `http:` or `https:` URL, with the package
|
|
78
|
-
* `socket.io-client`) or JSON-RPC over WebSocket (a `ws:` or `wss:` URL, with the `WebSocket` of Node.js 22 and
|
|
78
|
+
* `socket.io-client`) or JSON-RPC over WebSocket (a `ws:` or `wss:` URL, with the global `WebSocket` of Node.js 22 and
|
|
79
|
+
* later and of Bun, else the package `ws`);
|
|
79
80
|
* it reconnects by itself and joins its rooms again, keeping the peer-to-peer connections.
|
|
80
81
|
*
|
|
81
82
|
* Get a new one with `getObject(SignalingClient, options)` (it is `@Transient`, and needs no registration); `close()`
|
|
@@ -50,11 +50,29 @@ const SignalingSession_js_1 = require("../shared/SignalingSession.js");
|
|
|
50
50
|
const Transports_js_1 = require("../shared/Transports.js");
|
|
51
51
|
const SignalingConnectionException_js_1 = require("../exceptions/SignalingConnectionException.js");
|
|
52
52
|
const PeerConnection_js_1 = require("./PeerConnection.js");
|
|
53
|
+
/**
|
|
54
|
+
* The WebSocket of JSON-RPC: the global one (the browsers, Node.js 22 and later, Bun, Electron), else the one of the
|
|
55
|
+
* package ws (Node.js 18 to 21, which have none)
|
|
56
|
+
*/
|
|
57
|
+
async function webSocketClass() {
|
|
58
|
+
const global = globalThis.WebSocket;
|
|
59
|
+
if (global)
|
|
60
|
+
return global;
|
|
61
|
+
try {
|
|
62
|
+
const module = 'ws';
|
|
63
|
+
const loaded = await Promise.resolve(`${module}`).then(s => __importStar(require(s)));
|
|
64
|
+
return (loaded.WebSocket ?? loaded.default);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new SignalingConnectionException_js_1.SignalingConnectionException('JSON-RPC over WebSocket needs the global WebSocket (Node.js 22 and later) or the package ws: npm install ws');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
53
70
|
/**
|
|
54
71
|
* A lakutata application as a member of the rooms of a signaling server of this package (`Signaling` and
|
|
55
72
|
* `SignalingController`, on this application or another one): it joins rooms and connects to their other members,
|
|
56
73
|
* browsers or applications, with {@link PeerConnection}s. Over Socket.IO (an `http:` or `https:` URL, with the package
|
|
57
|
-
* `socket.io-client`) or JSON-RPC over WebSocket (a `ws:` or `wss:` URL, with the `WebSocket` of Node.js 22 and
|
|
74
|
+
* `socket.io-client`) or JSON-RPC over WebSocket (a `ws:` or `wss:` URL, with the global `WebSocket` of Node.js 22 and
|
|
75
|
+
* later and of Bun, else the package `ws`);
|
|
58
76
|
* it reconnects by itself and joins its rooms again, keeping the peer-to-peer connections.
|
|
59
77
|
*
|
|
60
78
|
* Get a new one with `getObject(SignalingClient, options)` (it is `@Transient`, and needs no registration); `close()`
|
|
@@ -93,6 +111,8 @@ let SignalingClient = class SignalingClient extends core_1.Provider {
|
|
|
93
111
|
this.#clientId = this.id ?? (0, node_crypto_1.randomUUID)();
|
|
94
112
|
const transport = await this.transport();
|
|
95
113
|
this.#session = new SignalingSession_js_1.SignalingSession(transport, {
|
|
114
|
+
//The random session of node:crypto: the global crypto of the session's default comes in Node.js 19
|
|
115
|
+
session: (0, node_crypto_1.randomBytes)(12).toString('hex'),
|
|
96
116
|
iceTransportPolicy: this.iceTransportPolicy,
|
|
97
117
|
createPeerConnection: (configuration) => this.getObject(PeerConnection_js_1.PeerConnection, {
|
|
98
118
|
...configuration,
|
|
@@ -214,9 +234,7 @@ let SignalingClient = class SignalingClient extends core_1.Provider {
|
|
|
214
234
|
async transport() {
|
|
215
235
|
const url = new URL(this.url);
|
|
216
236
|
if (url.protocol === 'ws:' || url.protocol === 'wss:') {
|
|
217
|
-
const WebSocketClass =
|
|
218
|
-
if (!WebSocketClass)
|
|
219
|
-
throw new SignalingConnectionException_js_1.SignalingConnectionException('JSON-RPC over WebSocket needs the global WebSocket (Node.js 22 and later)');
|
|
237
|
+
const WebSocketClass = await webSocketClass();
|
|
220
238
|
url.searchParams.set('id', this.#clientId);
|
|
221
239
|
const address = url.toString();
|
|
222
240
|
return new Transports_js_1.JSONRPCTransport(() => new WebSocketClass(address), this.timeout);
|