livekit-client 2.20.2 → 2.22.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/README.md +10 -10
- package/dist/livekit-client.e2ee.worker.js +1 -1
- package/dist/livekit-client.e2ee.worker.js.map +1 -1
- package/dist/livekit-client.e2ee.worker.mjs +6 -1
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +2588 -1056
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.fm.worker.js +1 -1
- package/dist/livekit-client.fm.worker.js.map +1 -1
- package/dist/livekit-client.fm.worker.mjs +6 -1
- package/dist/livekit-client.fm.worker.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/room/PCTransport.d.ts +49 -2
- package/dist/src/room/PCTransport.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +48 -65
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +6 -0
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/data-channel/DataChannelManager.d.ts +62 -0
- package/dist/src/room/data-channel/DataChannelManager.d.ts.map +1 -0
- package/dist/src/room/data-channel/FlowControlledDataChannel.d.ts +95 -0
- package/dist/src/room/data-channel/FlowControlledDataChannel.d.ts.map +1 -0
- package/dist/src/room/data-channel/LossyDataChannel.d.ts +40 -0
- package/dist/src/room/data-channel/LossyDataChannel.d.ts.map +1 -0
- package/dist/src/room/data-channel/ReliableDataChannel.d.ts +56 -0
- package/dist/src/room/data-channel/ReliableDataChannel.d.ts.map +1 -0
- package/dist/src/room/data-channel/types.d.ts +12 -0
- package/dist/src/room/data-channel/types.d.ts.map +1 -0
- package/dist/src/room/data-stream/compression.d.ts +49 -0
- package/dist/src/room/data-stream/compression.d.ts.map +1 -0
- package/dist/src/room/data-stream/constants.d.ts +18 -0
- package/dist/src/room/data-stream/constants.d.ts.map +1 -0
- package/dist/src/room/data-stream/incoming/IncomingDataStreamManager.d.ts +4 -0
- package/dist/src/room/data-stream/incoming/IncomingDataStreamManager.d.ts.map +1 -1
- package/dist/src/room/data-stream/incoming/StreamReader.d.ts.map +1 -1
- package/dist/src/room/data-stream/outgoing/OutgoingDataStreamManager.d.ts +49 -2
- package/dist/src/room/data-stream/outgoing/OutgoingDataStreamManager.d.ts.map +1 -1
- package/dist/src/room/data-stream/outgoing/header-utils.d.ts +18 -0
- package/dist/src/room/data-stream/outgoing/header-utils.d.ts.map +1 -0
- package/dist/src/room/errors.d.ts +3 -1
- package/dist/src/room/errors.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts +10 -2
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/RemoteParticipant.d.ts +11 -2
- package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
- package/dist/src/room/rpc/client/RpcClientManager.d.ts.map +1 -1
- package/dist/src/room/rpc/server/RpcServerManager.d.ts.map +1 -1
- package/dist/src/room/token-source/TokenSource.d.ts +19 -10
- package/dist/src/room/token-source/TokenSource.d.ts.map +1 -1
- package/dist/src/room/track/LocalVideoTrack.d.ts +12 -1
- package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
- package/dist/src/room/track/RemoteTrack.d.ts +3 -0
- package/dist/src/room/track/RemoteTrack.d.ts.map +1 -1
- package/dist/src/room/track/Track.d.ts.map +1 -1
- package/dist/src/room/types.d.ts +17 -0
- package/dist/src/room/types.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts +28 -0
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/src/test/promiseState.d.ts +12 -0
- package/dist/src/test/promiseState.d.ts.map +1 -0
- package/dist/src/test/signalToken.d.ts.map +1 -1
- package/dist/src/utils/AsyncQueue.d.ts +3 -3
- package/dist/src/utils/AsyncQueue.d.ts.map +1 -1
- package/dist/src/version.d.ts +5 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/ts4.2/index.d.ts +1 -1
- package/dist/ts4.2/room/PCTransport.d.ts +49 -2
- package/dist/ts4.2/room/RTCEngine.d.ts +48 -65
- package/dist/ts4.2/room/Room.d.ts +6 -0
- package/dist/ts4.2/room/data-channel/DataChannelManager.d.ts +62 -0
- package/dist/ts4.2/room/data-channel/FlowControlledDataChannel.d.ts +95 -0
- package/dist/ts4.2/room/data-channel/LossyDataChannel.d.ts +41 -0
- package/dist/ts4.2/room/data-channel/ReliableDataChannel.d.ts +57 -0
- package/dist/ts4.2/room/data-channel/types.d.ts +12 -0
- package/dist/ts4.2/room/data-stream/compression.d.ts +49 -0
- package/dist/ts4.2/room/data-stream/constants.d.ts +18 -0
- package/dist/ts4.2/room/data-stream/incoming/IncomingDataStreamManager.d.ts +4 -0
- package/dist/ts4.2/room/data-stream/outgoing/OutgoingDataStreamManager.d.ts +49 -2
- package/dist/ts4.2/room/data-stream/outgoing/header-utils.d.ts +18 -0
- package/dist/ts4.2/room/errors.d.ts +3 -1
- package/dist/ts4.2/room/participant/LocalParticipant.d.ts +10 -2
- package/dist/ts4.2/room/participant/RemoteParticipant.d.ts +11 -1
- package/dist/ts4.2/room/token-source/TokenSource.d.ts +17 -8
- package/dist/ts4.2/room/track/LocalVideoTrack.d.ts +12 -1
- package/dist/ts4.2/room/track/RemoteTrack.d.ts +3 -0
- package/dist/ts4.2/room/types.d.ts +17 -0
- package/dist/ts4.2/room/utils.d.ts +28 -0
- package/dist/ts4.2/test/promiseState.d.ts +12 -0
- package/dist/ts4.2/utils/AsyncQueue.d.ts +3 -3
- package/dist/ts4.2/version.d.ts +5 -1
- package/package.json +14 -13
- package/src/api/SignalClient.e2e.test.ts +16 -9
- package/src/e2ee/utils.ts +1 -1
- package/src/index.ts +2 -0
- package/src/room/PCTransport.test.ts +243 -1
- package/src/room/PCTransport.ts +181 -80
- package/src/room/RTCEngine.test.ts +397 -101
- package/src/room/RTCEngine.ts +244 -545
- package/src/room/Room.test.ts +138 -4
- package/src/room/Room.ts +92 -25
- package/src/room/data-channel/DataChannelManager.test.ts +152 -0
- package/src/room/data-channel/DataChannelManager.ts +237 -0
- package/src/room/data-channel/FlowControlledDataChannel.test.ts +154 -0
- package/src/room/data-channel/FlowControlledDataChannel.ts +216 -0
- package/src/room/data-channel/LossyDataChannel.test.ts +118 -0
- package/src/room/data-channel/LossyDataChannel.ts +125 -0
- package/src/room/data-channel/ReliableDataChannel.test.ts +158 -0
- package/src/room/data-channel/ReliableDataChannel.ts +153 -0
- package/src/room/data-channel/types.ts +30 -0
- package/src/room/data-stream/compression.ts +117 -0
- package/src/room/data-stream/constants.ts +18 -0
- package/src/room/data-stream/incoming/IncomingDataStreamManager.test.ts +1601 -0
- package/src/room/data-stream/incoming/IncomingDataStreamManager.ts +438 -86
- package/src/room/data-stream/incoming/StreamReader.ts +9 -3
- package/src/room/data-stream/outgoing/OutgoingDataStreamManager.test.ts +1292 -0
- package/src/room/data-stream/outgoing/OutgoingDataStreamManager.ts +489 -116
- package/src/room/data-stream/outgoing/header-utils.ts +87 -0
- package/src/room/errors.ts +7 -2
- package/src/room/participant/LocalParticipant.ts +13 -0
- package/src/room/participant/RemoteParticipant.ts +19 -5
- package/src/room/rpc/client/RpcClientManager.test.ts +20 -27
- package/src/room/rpc/client/RpcClientManager.ts +1 -4
- package/src/room/rpc/server/RpcServerManager.test.ts +24 -23
- package/src/room/rpc/server/RpcServerManager.ts +1 -3
- package/src/room/token-source/TokenSource.ts +25 -12
- package/src/room/track/LocalVideoTrack.test.ts +105 -2
- package/src/room/track/LocalVideoTrack.ts +36 -10
- package/src/room/track/RemoteTrack.test.ts +144 -0
- package/src/room/track/RemoteTrack.ts +39 -12
- package/src/room/track/Track.ts +2 -1
- package/src/room/types.ts +18 -0
- package/src/room/utils.test.ts +71 -2
- package/src/room/utils.ts +119 -0
- package/src/test/promiseState.ts +23 -0
- package/src/test/signalServerSetup.ts +2 -1
- package/src/test/signalToken.ts +17 -13
- package/src/type-polyfills/header-extensions.d.ts +13 -0
- package/src/utils/AsyncQueue.ts +3 -3
- package/src/version.ts +5 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compression helpers for data streams. The buffered deflate-raw variant ({@link deflateRawCompress})
|
|
3
|
+
* is for the inline (single-packet) case where the payload is small and bounded;
|
|
4
|
+
* {@link deflateRawTransform} / {@link inflateRawTransform} serve the chunked (multi-packet)
|
|
5
|
+
* `sendText`/`sendBytes`/`sendFile` paths, streaming the bytes through without buffering the whole
|
|
6
|
+
* payload.
|
|
7
|
+
*
|
|
8
|
+
* These operate on bytes (not strings) so a single set of helpers serves both text and byte streams;
|
|
9
|
+
* the `TextEncoder`/`TextDecoder` boundary lives at the manager/reader edges.
|
|
10
|
+
*
|
|
11
|
+
* Both streaming variants are exposed as `ReadableWritablePair`s so they drop straight into a
|
|
12
|
+
* `pipeThrough` chain. Each needs one localized cast to bridge a DOM lib-type mismatch: the platform
|
|
13
|
+
* `CompressionStream`/`DecompressionStream` type their `writable` as `WritableStream<BufferSource>`
|
|
14
|
+
* (a wider element type than `Uint8Array`), and `WritableStream<W>` is covariant in `W`, so neither
|
|
15
|
+
* is structurally a `ReadableWritablePair<Uint8Array, Uint8Array>` without help.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
import { type NonSharedUint8Array } from '../../type-polyfills/non-shared-typed-arrays';
|
|
20
|
+
import { DataStreamError, DataStreamErrorReason } from '../errors';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A `deflate-raw` compression transform (inverse of {@link inflateRawTransform}): pipe a byte stream
|
|
24
|
+
* through it to get the compressed bytes without buffering the whole payload. Used for the chunked
|
|
25
|
+
* `sendText`/`sendBytes`/`sendFile` paths, where the full payload is known up front but is streamed
|
|
26
|
+
* (e.g. from `file.stream()`) rather than held in memory.
|
|
27
|
+
*/
|
|
28
|
+
export function deflateRawTransform(): ReadableWritablePair<
|
|
29
|
+
NonSharedUint8Array,
|
|
30
|
+
NonSharedUint8Array
|
|
31
|
+
> {
|
|
32
|
+
return new CompressionStream('deflate-raw') as unknown as ReadableWritablePair<
|
|
33
|
+
NonSharedUint8Array,
|
|
34
|
+
NonSharedUint8Array
|
|
35
|
+
>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A `deflate-raw` decompression transform (inverse of {@link deflateRawTransform}): pipe a
|
|
40
|
+
* stream of compressed bytes through it to get the decompressed bytes. Inflate emits output greedily,
|
|
41
|
+
* so as long as the sender flushed at write boundaries each write's content is produced as soon as
|
|
42
|
+
* its compressed bytes arrive.
|
|
43
|
+
*/
|
|
44
|
+
export function inflateRawTransform(): ReadableWritablePair<
|
|
45
|
+
NonSharedUint8Array,
|
|
46
|
+
NonSharedUint8Array
|
|
47
|
+
> {
|
|
48
|
+
return new DecompressionStream('deflate-raw') as unknown as ReadableWritablePair<
|
|
49
|
+
NonSharedUint8Array,
|
|
50
|
+
NonSharedUint8Array
|
|
51
|
+
>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** deflate-raw compresses a byte array in full. Use for inline payloads; prefer the streaming
|
|
55
|
+
* path for the chunked case. */
|
|
56
|
+
export async function deflateRawCompress(data: NonSharedUint8Array): Promise<NonSharedUint8Array> {
|
|
57
|
+
const cs = new CompressionStream('deflate-raw');
|
|
58
|
+
const writer = cs.writable.getWriter();
|
|
59
|
+
writer.write(data as NonSharedUint8Array);
|
|
60
|
+
writer.close();
|
|
61
|
+
return collect(cs.readable);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Decompresses a raw-deflate byte array in full (inverse of {@link deflateRawCompress}).
|
|
66
|
+
* `maxByteLength` bounds the decompressed output (decompression-bomb guard); exceeding it rejects
|
|
67
|
+
* with a `PayloadTooLarge` error.
|
|
68
|
+
*/
|
|
69
|
+
export async function deflateRawDecompress(
|
|
70
|
+
data: NonSharedUint8Array,
|
|
71
|
+
maxByteLength?: number,
|
|
72
|
+
): Promise<NonSharedUint8Array> {
|
|
73
|
+
const ds = new DecompressionStream('deflate-raw');
|
|
74
|
+
const writer = ds.writable.getWriter();
|
|
75
|
+
// The writer promises are intentionally not awaited (output is consumed via `collect`), but
|
|
76
|
+
// they reject when the byte cap cancels the readable mid-stream — swallow that so an enforced
|
|
77
|
+
// cap doesn't surface as an unhandled rejection.
|
|
78
|
+
writer.write(data as NonSharedUint8Array).catch(() => {});
|
|
79
|
+
writer.close().catch(() => {});
|
|
80
|
+
return collect(ds.readable, maxByteLength);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Drains a byte stream, concatenating all of its chunks into a single array. When
|
|
85
|
+
* `maxByteLength` is given, drops the stream and throws `PayloadTooLarge` as soon as the
|
|
86
|
+
* accumulated output exceeds it.
|
|
87
|
+
*/
|
|
88
|
+
export async function collect(
|
|
89
|
+
stream: ReadableStream<NonSharedUint8Array>,
|
|
90
|
+
maxByteLength?: number,
|
|
91
|
+
): Promise<NonSharedUint8Array> {
|
|
92
|
+
const reader = stream.getReader();
|
|
93
|
+
const chunks: Array<NonSharedUint8Array> = [];
|
|
94
|
+
let total = 0;
|
|
95
|
+
while (true) {
|
|
96
|
+
const { done, value } = await reader.read();
|
|
97
|
+
if (done) {
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
chunks.push(value);
|
|
101
|
+
total += value.byteLength;
|
|
102
|
+
if (typeof maxByteLength === 'number' && total > maxByteLength) {
|
|
103
|
+
await reader.cancel();
|
|
104
|
+
throw new DataStreamError(
|
|
105
|
+
`Decompressed payload exceeds the maximum payload size of ${maxByteLength} bytes`,
|
|
106
|
+
DataStreamErrorReason.PayloadTooLarge,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const result = new Uint8Array(total);
|
|
111
|
+
let offset = 0;
|
|
112
|
+
for (const chunk of chunks) {
|
|
113
|
+
result.set(chunk, offset);
|
|
114
|
+
offset += chunk.byteLength;
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum size of a single data-stream chunk in bytes, and the budget used to decide whether a
|
|
3
|
+
* payload can be sent inline as a single header packet. Kept below the ~16k data-channel MTU to
|
|
4
|
+
* leave headroom for protocol framing and E2EE overhead.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export const STREAM_CHUNK_SIZE_BYTES = 15_000;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default cap on the number of decompressed bytes a single incoming compressed data stream may
|
|
12
|
+
* produce (5 GB). A tiny compressed payload can inflate to an arbitrarily large output
|
|
13
|
+
* (decompression bomb), so the decompressor's output is bounded rather than trusting the wire
|
|
14
|
+
* size; streams exceeding the cap error with `PayloadTooLarge`.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_MAX_PAYLOAD_BYTE_LENGTH = 5_000_000_000;
|