@lakutata/webrtc 3.1.1 → 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
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ npm install @lakutata/webrtc
|
|
|
26
26
|
An application also needs `lakutata` (or `@lakutata/core` and `@lakutata/entrypoint`). The signaling is served over
|
|
27
27
|
Socket.IO (`npm install socket.io`) or JSON-RPC over WebSocket (`npm install ws`), through the adapters of the
|
|
28
28
|
entrypoint. An application joining rooms over Socket.IO needs `socket.io-client`; over JSON-RPC, it uses the
|
|
29
|
-
`WebSocket` built into Node.js 22 and Bun
|
|
29
|
+
`WebSocket` built into Node.js 22 and Bun, else the `WebSocket` of `ws` (Node.js 18 to 21). Instances working together
|
|
30
|
+
need `nats` or `ioredis`.
|
|
30
31
|
|
|
31
32
|
A frontend installs the same package and imports `@lakutata/webrtc/client`; the framework is not installed with it.
|
|
32
33
|
|
package/README.zh-CN.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
npm install @lakutata/webrtc
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
应用还需要 `lakutata`(或者 `@lakutata/core` 和 `@lakutata/entrypoint`)。信令通过 entrypoint 的适配器提供,走 Socket.IO(`npm install socket.io`)或 WebSocket 上的 JSON-RPC(`npm install ws`)。应用作为成员通过 Socket.IO 加入房间时需要 `socket.io-client`;通过 JSON-RPC 加入时,使用 Node.js 22 和 Bun 自带的 `WebSocket
|
|
18
|
+
应用还需要 `lakutata`(或者 `@lakutata/core` 和 `@lakutata/entrypoint`)。信令通过 entrypoint 的适配器提供,走 Socket.IO(`npm install socket.io`)或 WebSocket 上的 JSON-RPC(`npm install ws`)。应用作为成员通过 Socket.IO 加入房间时需要 `socket.io-client`;通过 JSON-RPC 加入时,使用 Node.js 22 和 Bun 自带的 `WebSocket`,没有时使用 `ws` 的 `WebSocket`(Node.js 18 到 21)。多个实例协同工作时需要 `nats` 或 `ioredis`。
|
|
19
19
|
|
|
20
20
|
前端安装同一个包,引用 `@lakutata/webrtc/client`;框架不会随之安装。
|
|
21
21
|
|
|
@@ -2,7 +2,7 @@ import { Exception } from '@lakutata/core';
|
|
|
2
2
|
/**
|
|
3
3
|
* Thrown when `SignalingClient` cannot use the transport of its URL: Socket.IO (an `http:` or `https:` URL) needs the
|
|
4
4
|
* package `socket.io-client`, JSON-RPC (a `ws:` or `wss:` URL) needs the global `WebSocket` (Node.js 22 and later,
|
|
5
|
-
* Bun)
|
|
5
|
+
* Bun) or the package `ws`. Its `errno` is `'E_SIGNALING_CONNECTION'`.
|
|
6
6
|
*/
|
|
7
7
|
export declare class SignalingConnectionException extends Exception {
|
|
8
8
|
/**
|
|
@@ -5,7 +5,7 @@ const core_1 = require("@lakutata/core");
|
|
|
5
5
|
/**
|
|
6
6
|
* Thrown when `SignalingClient` cannot use the transport of its URL: Socket.IO (an `http:` or `https:` URL) needs the
|
|
7
7
|
* package `socket.io-client`, JSON-RPC (a `ws:` or `wss:` URL) needs the global `WebSocket` (Node.js 22 and later,
|
|
8
|
-
* Bun)
|
|
8
|
+
* Bun) or the package `ws`. Its `errno` is `'E_SIGNALING_CONNECTION'`.
|
|
9
9
|
*/
|
|
10
10
|
class SignalingConnectionException extends core_1.Exception {
|
|
11
11
|
constructor() {
|
|
@@ -56,6 +56,7 @@ export declare class RTCPeerConnection extends EventTarget {
|
|
|
56
56
|
private readonly sctpManager;
|
|
57
57
|
private readonly secureManager;
|
|
58
58
|
private isClosed;
|
|
59
|
+
private closing?;
|
|
59
60
|
private shouldNegotiationneeded;
|
|
60
61
|
private lastCreatedAnswer?;
|
|
61
62
|
private lastCreatedOffer?;
|
|
@@ -307,6 +308,7 @@ export declare class RTCPeerConnection extends EventTarget {
|
|
|
307
308
|
private createPeerConnectionStats;
|
|
308
309
|
getStats(selector?: MediaStreamTrack | null): Promise<RTCStatsReport>;
|
|
309
310
|
close(): Promise<void>;
|
|
311
|
+
private closeOnce;
|
|
310
312
|
private completePeerEvents;
|
|
311
313
|
}
|
|
312
314
|
export type DebugConfig = Partial<{
|
|
@@ -1399,8 +1399,10 @@ class RTCPeerConnection extends helper_js_1.EventTarget {
|
|
|
1399
1399
|
return (0, stats_js_1.buildStatsReport)(stats, this.transceiverManager.getStatsRootIds(selector));
|
|
1400
1400
|
}
|
|
1401
1401
|
async close() {
|
|
1402
|
-
|
|
1403
|
-
|
|
1402
|
+
this.closing ??= this.closeOnce();
|
|
1403
|
+
return this.closing;
|
|
1404
|
+
}
|
|
1405
|
+
async closeOnce() {
|
|
1404
1406
|
this.isClosed = true;
|
|
1405
1407
|
this.pendingRemoteCandidates.length = 0;
|
|
1406
1408
|
this.setSignalingState('closed');
|
|
@@ -8,10 +8,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.PeerThreads = void 0;
|
|
13
16
|
exports.buildPeerThreadsOptions = buildPeerThreadsOptions;
|
|
14
|
-
const node_os_1 = require("node:os");
|
|
17
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
15
18
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
16
19
|
const core_1 = require("@lakutata/core");
|
|
17
20
|
const di_1 = require("@lakutata/core/decorator/di");
|
|
@@ -24,6 +27,13 @@ const log = (0, log_js_1.debug)('webrtc/peer/threads');
|
|
|
24
27
|
* How long a thread asked to stop has to close its connections, in milliseconds
|
|
25
28
|
*/
|
|
26
29
|
const STOP_TIMEOUT = 5000;
|
|
30
|
+
/**
|
|
31
|
+
* The parallelism the system advises: os.availableParallelism (Node.js 18.14, 19.4), else the cores
|
|
32
|
+
*/
|
|
33
|
+
function parallelism() {
|
|
34
|
+
//node-compat: os.availableParallelism
|
|
35
|
+
return typeof node_os_1.default.availableParallelism === 'function' ? node_os_1.default.availableParallelism() : Math.max(1, node_os_1.default.cpus().length);
|
|
36
|
+
}
|
|
27
37
|
/**
|
|
28
38
|
* Worker threads serving connections, to use more cores: a {@link PeerConnection} given the name of this component
|
|
29
39
|
* (its `threads` option) runs its ICE, DTLS, SCTP and SRTP there, while its object, its events and the messages of its
|
|
@@ -67,7 +77,7 @@ let PeerThreads = class PeerThreads extends core_1.Component {
|
|
|
67
77
|
async init() {
|
|
68
78
|
if (!PeerWorkerCode_js_1.peerWorkerCode)
|
|
69
79
|
throw new Error('The code of the worker threads of the connections is not built (scripts/workers.mjs)');
|
|
70
|
-
const count = this.threads ?? Math.max(1, (
|
|
80
|
+
const count = this.threads ?? Math.max(1, parallelism() - 1);
|
|
71
81
|
this.#slots = Array.from({ length: count }, (_, index) => ({ index: index, connections: new Map(), opening: 0 }));
|
|
72
82
|
log_js_1.debugHandlerWatchers.add(this.#debugging);
|
|
73
83
|
}
|