livekit-client 2.15.4 → 2.15.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.
Files changed (62) hide show
  1. package/dist/livekit-client.e2ee.worker.js +1 -1
  2. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  3. package/dist/livekit-client.e2ee.worker.mjs +329 -124
  4. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  5. package/dist/livekit-client.esm.mjs +834 -541
  6. package/dist/livekit-client.esm.mjs.map +1 -1
  7. package/dist/livekit-client.umd.js +1 -1
  8. package/dist/livekit-client.umd.js.map +1 -1
  9. package/dist/src/e2ee/worker/FrameCryptor.d.ts +0 -46
  10. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
  11. package/dist/src/e2ee/worker/naluUtils.d.ts +27 -0
  12. package/dist/src/e2ee/worker/naluUtils.d.ts.map +1 -0
  13. package/dist/src/index.d.ts +2 -2
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/room/Room.d.ts +6 -10
  16. package/dist/src/room/Room.d.ts.map +1 -1
  17. package/dist/src/room/data-stream/incoming/IncomingDataStreamManager.d.ts +20 -0
  18. package/dist/src/room/data-stream/incoming/IncomingDataStreamManager.d.ts.map +1 -0
  19. package/dist/src/room/{StreamReader.d.ts → data-stream/incoming/StreamReader.d.ts} +32 -6
  20. package/dist/src/room/data-stream/incoming/StreamReader.d.ts.map +1 -0
  21. package/dist/src/room/data-stream/outgoing/OutgoingDataStreamManager.d.ts +27 -0
  22. package/dist/src/room/data-stream/outgoing/OutgoingDataStreamManager.d.ts.map +1 -0
  23. package/dist/src/room/{StreamWriter.d.ts → data-stream/outgoing/StreamWriter.d.ts} +1 -1
  24. package/dist/src/room/data-stream/outgoing/StreamWriter.d.ts.map +1 -0
  25. package/dist/src/room/errors.d.ts +13 -0
  26. package/dist/src/room/errors.d.ts.map +1 -1
  27. package/dist/src/room/participant/LocalParticipant.d.ts +32 -19
  28. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  29. package/dist/src/room/track/LocalTrack.d.ts +7 -2
  30. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  31. package/dist/src/room/types.d.ts +17 -1
  32. package/dist/src/room/types.d.ts.map +1 -1
  33. package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +0 -46
  34. package/dist/ts4.2/src/e2ee/worker/naluUtils.d.ts +27 -0
  35. package/dist/ts4.2/src/index.d.ts +2 -2
  36. package/dist/ts4.2/src/room/Room.d.ts +6 -10
  37. package/dist/ts4.2/src/room/data-stream/incoming/IncomingDataStreamManager.d.ts +20 -0
  38. package/dist/ts4.2/src/room/{StreamReader.d.ts → data-stream/incoming/StreamReader.d.ts} +32 -6
  39. package/dist/ts4.2/src/room/data-stream/outgoing/OutgoingDataStreamManager.d.ts +27 -0
  40. package/dist/ts4.2/src/room/{StreamWriter.d.ts → data-stream/outgoing/StreamWriter.d.ts} +1 -1
  41. package/dist/ts4.2/src/room/errors.d.ts +13 -0
  42. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +32 -19
  43. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +7 -2
  44. package/dist/ts4.2/src/room/types.d.ts +17 -1
  45. package/package.json +1 -1
  46. package/src/e2ee/worker/FrameCryptor.ts +48 -139
  47. package/src/e2ee/worker/naluUtils.ts +328 -0
  48. package/src/index.ts +2 -2
  49. package/src/room/Room.ts +93 -206
  50. package/src/room/data-stream/incoming/IncomingDataStreamManager.ts +247 -0
  51. package/src/room/data-stream/incoming/StreamReader.ts +317 -0
  52. package/src/room/data-stream/outgoing/OutgoingDataStreamManager.ts +316 -0
  53. package/src/room/{StreamWriter.ts → data-stream/outgoing/StreamWriter.ts} +1 -1
  54. package/src/room/errors.ts +34 -0
  55. package/src/room/participant/LocalParticipant.ts +39 -295
  56. package/src/room/track/LocalAudioTrack.ts +2 -2
  57. package/src/room/track/LocalTrack.ts +65 -48
  58. package/src/room/types.ts +22 -1
  59. package/src/room/utils.ts +2 -2
  60. package/dist/src/room/StreamReader.d.ts.map +0 -1
  61. package/dist/src/room/StreamWriter.d.ts.map +0 -1
  62. package/src/room/StreamReader.ts +0 -170
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/room/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;IACF,YAAY,CAAC,EAAE;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,qBAAqB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,WAAW,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAA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AAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,gBAAgB;IAC1D,IAAI,EAAE,cAAc,CAAC;IACrB,UAAU,EAAE,+BAA+B,CAAC,CAAC,CAAC,CAAC;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0BAA0B,EAAE,MAAM,CAAC;IACnC,+BAA+B,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AACD,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAe,SAAQ,cAAc;CAAG"}
@@ -128,52 +128,6 @@ export declare class FrameCryptor extends BaseFrameCryptor {
128
128
  */
129
129
  private getVideoCodec;
130
130
  }
131
- /**
132
- * Slice the NALUs present in the supplied buffer, assuming it is already byte-aligned
133
- * code adapted from https://github.com/medooze/h264-frame-parser/blob/main/lib/NalUnits.ts to return indices only
134
- */
135
- export declare function findNALUIndices(stream: Uint8Array): number[];
136
- export declare function parseNALUType(startByte: number): NALUType;
137
- export declare enum NALUType {
138
- /** Coded slice of a non-IDR picture */
139
- SLICE_NON_IDR = 1,
140
- /** Coded slice data partition A */
141
- SLICE_PARTITION_A = 2,
142
- /** Coded slice data partition B */
143
- SLICE_PARTITION_B = 3,
144
- /** Coded slice data partition C */
145
- SLICE_PARTITION_C = 4,
146
- /** Coded slice of an IDR picture */
147
- SLICE_IDR = 5,
148
- /** Supplemental enhancement information */
149
- SEI = 6,
150
- /** Sequence parameter set */
151
- SPS = 7,
152
- /** Picture parameter set */
153
- PPS = 8,
154
- /** Access unit delimiter */
155
- AUD = 9,
156
- /** End of sequence */
157
- END_SEQ = 10,
158
- /** End of stream */
159
- END_STREAM = 11,
160
- /** Filler data */
161
- FILLER_DATA = 12,
162
- /** Sequence parameter set extension */
163
- SPS_EXT = 13,
164
- /** Prefix NAL unit */
165
- PREFIX_NALU = 14,
166
- /** Subset sequence parameter set */
167
- SUBSET_SPS = 15,
168
- /** Depth parameter set */
169
- DPS = 16,
170
- /** Coded slice of an auxiliary coded picture without partitioning */
171
- SLICE_AUX = 19,
172
- /** Coded slice extension */
173
- SLICE_EXT = 20,
174
- /** Coded slice extension for a depth view component or a 3D-AVC texture view component */
175
- SLICE_LAYER_EXT = 21
176
- }
177
131
  /**
178
132
  * we use a magic frame trailer to detect whether a frame is injected
179
133
  * by the livekit server and thus to be treated as unencrypted
@@ -0,0 +1,27 @@
1
+ /**
2
+ * NALU (Network Abstraction Layer Unit) utilities for H.264 and H.265 video processing
3
+ * Contains functions for parsing and working with NALUs in video frames
4
+ */
5
+ /**
6
+ * Detected codec type from NALU analysis
7
+ */
8
+ export type DetectedCodec = 'h264' | 'h265' | 'unknown';
9
+ /**
10
+ * Result of NALU processing for frame encryption
11
+ */
12
+ export interface NALUProcessingResult {
13
+ /** Number of unencrypted bytes at the start of the frame */
14
+ unencryptedBytes: number;
15
+ /** Detected codec type */
16
+ detectedCodec: DetectedCodec;
17
+ /** Whether this frame requires NALU processing */
18
+ requiresNALUProcessing: boolean;
19
+ }
20
+ /**
21
+ * Process NALU data for frame encryption, detecting codec and finding unencrypted bytes
22
+ * @param data Frame data
23
+ * @param knownCodec Known codec from other sources (optional)
24
+ * @returns NALU processing result
25
+ */
26
+ export declare function processNALUsForEncryption(data: Uint8Array, knownCodec?: 'h264' | 'h265'): NALUProcessingResult;
27
+ //# sourceMappingURL=naluUtils.d.ts.map
@@ -40,8 +40,8 @@ export { facingModeFromDeviceLabel, facingModeFromLocalTrack } from './room/trac
40
40
  export * from './room/track/options';
41
41
  export * from './room/track/processor/types';
42
42
  export * from './room/track/types';
43
- export type * from './room/StreamReader';
44
- export type * from './room/StreamWriter';
43
+ export type * from './room/data-stream/incoming/StreamReader';
44
+ export type * from './room/data-stream/outgoing/StreamWriter';
45
45
  export type { DataPublishOptions, SimulationScenario, TranscriptionSegment, ChatMessage, SendTextOptions, } from './room/types';
46
46
  export * from './version';
47
47
  export {
@@ -3,7 +3,7 @@ import type TypedEmitter from 'typed-emitter';
3
3
  import 'webrtc-adapter';
4
4
  import type { InternalRoomOptions, RoomConnectOptions, RoomOptions } from '../options';
5
5
  import RTCEngine from './RTCEngine';
6
- import type { ByteStreamHandler, TextStreamHandler } from './StreamReader';
6
+ import type { ByteStreamHandler, TextStreamHandler } from './data-stream/incoming/StreamReader';
7
7
  import LocalParticipant from './participant/LocalParticipant';
8
8
  import type Participant from './participant/Participant';
9
9
  import type { ConnectionQuality } from './participant/Participant';
@@ -74,10 +74,8 @@ declare class Room extends Room_base {
74
74
  * map to store first point in time when a particular transcription segment was received
75
75
  */
76
76
  private transcriptionReceivedTimes;
77
- private byteStreamControllers;
78
- private textStreamControllers;
79
- private byteStreamHandlers;
80
- private textStreamHandlers;
77
+ private incomingDataStreamManager;
78
+ private outgoingDataStreamManager;
81
79
  private rpcHandlers;
82
80
  /**
83
81
  * Creates a new Room, the primary construct for a LiveKit session.
@@ -121,7 +119,6 @@ declare class Room extends Room_base {
121
119
  * @param method - The name of the RPC method to unregister
122
120
  */
123
121
  unregisterRpcMethod(method: string): void;
124
- private handleIncomingRpcRequest;
125
122
  /**
126
123
  * @experimental
127
124
  */
@@ -226,15 +223,14 @@ declare class Room extends Room_base {
226
223
  private handleSubscriptionPermissionUpdate;
227
224
  private handleSubscriptionError;
228
225
  private handleDataPacket;
229
- private handleStreamHeader;
230
- private handleStreamChunk;
231
- private handleStreamTrailer;
232
226
  private handleUserPacket;
233
227
  private handleSipDtmf;
234
- bufferedSegments: Map<string, TranscriptionSegmentModel>;
235
228
  private handleTranscription;
236
229
  private handleChatMessage;
237
230
  private handleMetrics;
231
+ private handleDataStream;
232
+ private handleIncomingRpcRequest;
233
+ bufferedSegments: Map<string, TranscriptionSegmentModel>;
238
234
  private handleAudioPlaybackStarted;
239
235
  private handleAudioPlaybackFailed;
240
236
  private handleVideoPlaybackStarted;
@@ -0,0 +1,20 @@
1
+ import type { DataPacket } from '@livekit/protocol';
2
+ import type { ByteStreamHandler, TextStreamHandler } from './StreamReader';
3
+ export default class IncomingDataStreamManager {
4
+ private log;
5
+ private byteStreamControllers;
6
+ private textStreamControllers;
7
+ private byteStreamHandlers;
8
+ private textStreamHandlers;
9
+ registerTextStreamHandler(topic: string, callback: TextStreamHandler): void;
10
+ unregisterTextStreamHandler(topic: string): void;
11
+ registerByteStreamHandler(topic: string, callback: ByteStreamHandler): void;
12
+ unregisterByteStreamHandler(topic: string): void;
13
+ clearHandlersAndControllers(): void;
14
+ validateParticipantHasNoActiveDataStreams(participantIdentity: string): void;
15
+ handleDataStreamPacket(packet: DataPacket): Promise<void>;
16
+ private handleStreamHeader;
17
+ private handleStreamChunk;
18
+ private handleStreamTrailer;
19
+ }
20
+ //# sourceMappingURL=IncomingDataStreamManager.d.ts.map
@@ -1,35 +1,53 @@
1
1
  import type { DataStream_Chunk } from '@livekit/protocol';
2
- import type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types';
2
+ import type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from '../../types';
3
+ import { Future } from '../../utils';
4
+ export type BaseStreamReaderReadAllOpts = {
5
+ /** An AbortSignal can be used to terminate reads early. */
6
+ signal?: AbortSignal;
7
+ };
3
8
  declare abstract class BaseStreamReader<T extends BaseStreamInfo> {
4
9
  protected reader: ReadableStream<DataStream_Chunk>;
5
10
  protected totalByteSize?: number;
6
11
  protected _info: T;
7
12
  protected bytesReceived: number;
13
+ protected outOfBandFailureRejectingFuture?: Future<never>;
8
14
  get info(): T;
9
- constructor(info: T, stream: ReadableStream<DataStream_Chunk>, totalByteSize?: number);
15
+ /** @internal */
16
+ protected validateBytesReceived(doneReceiving?: boolean): void;
17
+ constructor(info: T, stream: ReadableStream<DataStream_Chunk>, totalByteSize?: number, outOfBandFailureRejectingFuture?: Future<never>);
10
18
  protected abstract handleChunkReceived(chunk: DataStream_Chunk): void;
11
19
  onProgress?: (progress: number | undefined) => void;
12
- abstract readAll(): Promise<string | Array<Uint8Array>>;
20
+ abstract readAll(opts?: BaseStreamReaderReadAllOpts): Promise<string | Array<Uint8Array>>;
13
21
  }
14
22
  export declare class ByteStreamReader extends BaseStreamReader<ByteStreamInfo> {
15
23
  protected handleChunkReceived(chunk: DataStream_Chunk): void;
16
24
  onProgress?: (progress: number | undefined) => void;
25
+ signal?: AbortSignal;
17
26
  [Symbol.asyncIterator](): {
18
27
  next: () => Promise<IteratorResult<Uint8Array>>;
19
28
  return(): Promise<IteratorResult<Uint8Array>>;
20
29
  };
21
- readAll(): Promise<Array<Uint8Array>>;
30
+ /**
31
+ * Injects an AbortSignal, which if aborted, will terminate the currently active
32
+ * stream iteration operation.
33
+ *
34
+ * Note that when using AbortSignal.timeout(...), the timeout applies across
35
+ * the whole iteration operation, not just one individual chunk read.
36
+ */
37
+ withAbortSignal(signal: AbortSignal): this;
38
+ readAll(opts?: BaseStreamReaderReadAllOpts): Promise<Array<Uint8Array>>;
22
39
  }
23
40
  /**
24
41
  * A class to read chunks from a ReadableStream and provide them in a structured format.
25
42
  */
26
43
  export declare class TextStreamReader extends BaseStreamReader<TextStreamInfo> {
27
44
  private receivedChunks;
45
+ signal?: AbortSignal;
28
46
  /**
29
47
  * A TextStreamReader instance can be used as an AsyncIterator that returns the entire string
30
48
  * that has been received up to the current point in time.
31
49
  */
32
- constructor(info: TextStreamInfo, stream: ReadableStream<DataStream_Chunk>, totalChunkCount?: number);
50
+ constructor(info: TextStreamInfo, stream: ReadableStream<DataStream_Chunk>, totalChunkCount?: number, outOfBandFailureRejectingFuture?: Future<never>);
33
51
  protected handleChunkReceived(chunk: DataStream_Chunk): void;
34
52
  /**
35
53
  * @param progress - progress of the stream between 0 and 1. Undefined for streams of unknown size
@@ -44,7 +62,15 @@ export declare class TextStreamReader extends BaseStreamReader<TextStreamInfo> {
44
62
  next: () => Promise<IteratorResult<string>>;
45
63
  return(): Promise<IteratorResult<string>>;
46
64
  };
47
- readAll(): Promise<string>;
65
+ /**
66
+ * Injects an AbortSignal, which if aborted, will terminate the currently active
67
+ * stream iteration operation.
68
+ *
69
+ * Note that when using AbortSignal.timeout(...), the timeout applies across
70
+ * the whole iteration operation, not just one individual chunk read.
71
+ */
72
+ withAbortSignal(signal: AbortSignal): this;
73
+ readAll(opts?: BaseStreamReaderReadAllOpts): Promise<string>;
48
74
  }
49
75
  export type ByteStreamHandler = (reader: ByteStreamReader, participantInfo: {
50
76
  identity: string;
@@ -0,0 +1,27 @@
1
+ import type { StructuredLogger } from '../../../logger';
2
+ import type RTCEngine from '../../RTCEngine';
3
+ import type { SendFileOptions, SendTextOptions, StreamBytesOptions, StreamTextOptions, TextStreamInfo } from '../../types';
4
+ import { ByteStreamWriter, TextStreamWriter } from './StreamWriter';
5
+ /**
6
+ * Manages sending custom user data via data channels.
7
+ * @internal
8
+ */
9
+ export default class OutgoingDataStreamManager {
10
+ protected engine: RTCEngine;
11
+ protected log: StructuredLogger;
12
+ constructor(engine: RTCEngine, log: StructuredLogger);
13
+ setupEngine(engine: RTCEngine): void;
14
+ /** {@inheritDoc LocalParticipant.sendText} */
15
+ sendText(text: string, options?: SendTextOptions): Promise<TextStreamInfo>;
16
+ /**
17
+ * @internal
18
+ * @experimental CAUTION, might get removed in a minor release
19
+ */
20
+ streamText(options?: StreamTextOptions): Promise<TextStreamWriter>;
21
+ sendFile(file: File, options?: SendFileOptions): Promise<{
22
+ id: string;
23
+ }>;
24
+ private _sendFile;
25
+ streamBytes(options?: StreamBytesOptions): Promise<ByteStreamWriter>;
26
+ }
27
+ //# sourceMappingURL=OutgoingDataStreamManager.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types';
1
+ import type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from '../../types';
2
2
  declare class BaseStreamWriter<T, InfoType extends BaseStreamInfo> {
3
3
  protected writableStream: WritableStream<T>;
4
4
  protected defaultWriter: WritableStreamDefaultWriter<T>;
@@ -46,6 +46,19 @@ export declare class SignalRequestError extends LivekitError {
46
46
  reasonName: string;
47
47
  constructor(message: string, reason: RequestErrorReason);
48
48
  }
49
+ export declare enum DataStreamErrorReason {
50
+ AlreadyOpened = 0,
51
+ AbnormalEnd = 1,
52
+ DecodeFailed = 2,
53
+ LengthExceeded = 3,
54
+ Incomplete = 4,
55
+ HandlerAlreadyRegistered = 7
56
+ }
57
+ export declare class DataStreamError extends LivekitError {
58
+ reason: DataStreamErrorReason;
59
+ reasonName: string;
60
+ constructor(message: string, reason: DataStreamErrorReason);
61
+ }
49
62
  export declare enum MediaDeviceFailure {
50
63
  PermissionDenied = "PermissionDenied",
51
64
  NotFound = "NotFound",
@@ -1,13 +1,14 @@
1
1
  import { Codec, ParticipantInfo, ParticipantPermission } from '@livekit/protocol';
2
2
  import type { InternalRoomOptions } from '../../options';
3
3
  import type RTCEngine from '../RTCEngine';
4
- import { ByteStreamWriter, TextStreamWriter } from '../StreamWriter';
4
+ import type OutgoingDataStreamManager from '../data-stream/outgoing/OutgoingDataStreamManager';
5
+ import type { TextStreamWriter } from '../data-stream/outgoing/StreamWriter';
5
6
  import type { PerformRpcParams, RpcInvocationData } from '../rpc';
6
7
  import LocalTrack from '../track/LocalTrack';
7
8
  import LocalTrackPublication from '../track/LocalTrackPublication';
8
9
  import { Track } from '../track/Track';
9
10
  import type { AudioCaptureOptions, BackupVideoCodec, CreateLocalTracksOptions, ScreenShareCaptureOptions, TrackPublishOptions, VideoCaptureOptions } from '../track/options';
10
- import type { ChatMessage, DataPublishOptions, SendTextOptions, StreamTextOptions, TextStreamInfo } from '../types';
11
+ import type { ChatMessage, DataPublishOptions, SendFileOptions, SendTextOptions, StreamBytesOptions, StreamTextOptions, TextStreamInfo } from '../types';
11
12
  import Participant from './Participant';
12
13
  import type { ParticipantTrackPermission } from './ParticipantTrackPermission';
13
14
  import type RemoteParticipant from './RemoteParticipant';
@@ -34,12 +35,13 @@ export default class LocalParticipant extends Participant {
34
35
  private activeAgentFuture?;
35
36
  private firstActiveAgent?;
36
37
  private rpcHandlers;
38
+ private roomOutgoingDataStreamManager;
37
39
  private pendingSignalRequests;
38
40
  private enabledPublishVideoCodecs;
39
41
  private pendingAcks;
40
42
  private pendingResponses;
41
43
  /** @internal */
42
- constructor(sid: string, identity: string, engine: RTCEngine, options: InternalRoomOptions, roomRpcHandlers: Map<string, (data: RpcInvocationData) => Promise<string>>);
44
+ constructor(sid: string, identity: string, engine: RTCEngine, options: InternalRoomOptions, roomRpcHandlers: Map<string, (data: RpcInvocationData) => Promise<string>>, roomOutgoingDataStreamManager: OutgoingDataStreamManager);
43
45
  get lastCameraError(): Error | undefined;
44
46
  get lastMicrophoneError(): Error | undefined;
45
47
  get isE2EEEnabled(): boolean;
@@ -156,7 +158,9 @@ export default class LocalParticipant extends Participant {
156
158
  * @param digit DTMF digit
157
159
  */
158
160
  publishDtmf(code: number, digit: string): Promise<void>;
161
+ /** @deprecated Consider migrating to {@link sendText} */
159
162
  sendChatMessage(text: string, options?: SendTextOptions): Promise<ChatMessage>;
163
+ /** @deprecated Consider migrating to {@link sendText} */
160
164
  editChatMessage(editText: string, originalMessage: ChatMessage): Promise<{
161
165
  readonly message: string;
162
166
  readonly editTimestamp: number;
@@ -164,30 +168,39 @@ export default class LocalParticipant extends Participant {
164
168
  readonly timestamp: number;
165
169
  readonly attachedFiles?: Array<File>;
166
170
  }>;
171
+ /**
172
+ * Sends the given string to participants in the room via the data channel.
173
+ * For longer messages, consider using {@link streamText} instead.
174
+ *
175
+ * @param text The text payload
176
+ * @param options.topic Topic identifier used to route the stream to appropriate handlers.
177
+ */
167
178
  sendText(text: string, options?: SendTextOptions): Promise<TextStreamInfo>;
168
179
  /**
180
+ * Creates a new TextStreamWriter which can be used to stream text incrementally
181
+ * to participants in the room via the data channel.
182
+ *
183
+ * @param options.topic Topic identifier used to route the stream to appropriate handlers.
184
+ *
169
185
  * @internal
170
186
  * @experimental CAUTION, might get removed in a minor release
171
187
  */
172
188
  streamText(options?: StreamTextOptions): Promise<TextStreamWriter>;
173
- sendFile(file: File, options?: {
174
- mimeType?: string;
175
- topic?: string;
176
- destinationIdentities?: Array<string>;
177
- onProgress?: (progress: number) => void;
178
- }): Promise<{
189
+ /** Send a File to all participants in the room via the data channel.
190
+ * @param file The File object payload
191
+ * @param options.topic Topic identifier used to route the stream to appropriate handlers.
192
+ * @param options.onProgress A callback function used to monitor the upload progress percentage.
193
+ */
194
+ sendFile(file: File, options?: SendFileOptions): Promise<{
179
195
  id: string;
180
196
  }>;
181
- private _sendFile;
182
- streamBytes(options?: {
183
- name?: string;
184
- topic?: string;
185
- attributes?: Record<string, string>;
186
- destinationIdentities?: Array<string>;
187
- streamId?: string;
188
- mimeType?: string;
189
- totalSize?: number;
190
- }): Promise<ByteStreamWriter>;
197
+ /**
198
+ * Stream bytes incrementally to participants in the room via the data channel.
199
+ * For sending files, consider using {@link sendFile} instead.
200
+ *
201
+ * @param options.topic Topic identifier used to route the stream to appropriate handlers.
202
+ */
203
+ streamBytes(options?: StreamBytesOptions): Promise<import("../data-stream/outgoing/StreamWriter").ByteStreamWriter>;
191
204
  /**
192
205
  * Initiate an RPC call to a remote participant
193
206
  * @param params - Parameters for initiating the RPC call, see {@link PerformRpcParams}
@@ -23,11 +23,10 @@ export default abstract class LocalTrack<TrackKind extends Track.Kind = Track.Ki
23
23
  protected pauseUpstreamLock: Mutex;
24
24
  protected processorElement?: HTMLMediaElement;
25
25
  protected processor?: TrackProcessor<TrackKind, any>;
26
- protected processorLock: Mutex;
27
26
  protected audioContext?: AudioContext;
28
27
  protected manuallyStopped: boolean;
29
28
  protected localTrackRecorder: LocalTrackRecorder<typeof this> | undefined;
30
- private restartLock;
29
+ protected trackChangeLock: Mutex;
31
30
  /**
32
31
  *
33
32
  * @param mediaTrack
@@ -104,6 +103,12 @@ export default abstract class LocalTrack<TrackKind extends Track.Kind = Track.Ki
104
103
  * @returns
105
104
  */
106
105
  stopProcessor(keepElement?: boolean): Promise<void>;
106
+ /**
107
+ * @internal
108
+ * This method assumes the caller has acquired a trackChangeLock already.
109
+ * The public facing method for stopping the processor is `stopProcessor` and it wraps this method in the trackChangeLock.
110
+ */
111
+ protected internalStopProcessor(keepElement?: boolean): Promise<void>;
107
112
  /** @internal */
108
113
  startPreConnectBuffer(timeslice?: number): void;
109
114
  /** @internal */
@@ -1,4 +1,5 @@
1
- import type { DataStream_Chunk } from '@livekit/protocol';
1
+ import type { DataStream_Chunk, Encryption_Type } from '@livekit/protocol';
2
+ import type { Future } from './utils';
2
3
  export type SimulationOptions = {
3
4
  publish?: {
4
5
  audio?: boolean;
@@ -30,6 +31,19 @@ export interface StreamTextOptions {
30
31
  totalSize?: number;
31
32
  attributes?: Record<string, string>;
32
33
  }
34
+ export type StreamBytesOptions = {
35
+ name?: string;
36
+ topic?: string;
37
+ attributes?: Record<string, string>;
38
+ destinationIdentities?: Array<string>;
39
+ streamId?: string;
40
+ mimeType?: string;
41
+ totalSize?: number;
42
+ };
43
+ export type SendFileOptions = Pick<StreamBytesOptions, 'topic' | 'mimeType' | 'destinationIdentities'> & {
44
+ onProgress?: (progress: number) => void;
45
+ encryptionType?: Encryption_Type.NONE;
46
+ };
33
47
  export type DataPublishOptions = {
34
48
  /**
35
49
  * whether to send this as reliable or lossy.
@@ -76,6 +90,8 @@ export interface StreamController<T extends DataStream_Chunk> {
76
90
  controller: ReadableStreamDefaultController<T>;
77
91
  startTime: number;
78
92
  endTime?: number;
93
+ sendingParticipantIdentity: string;
94
+ outOfBandFailureRejectingFuture: Future<never>;
79
95
  }
80
96
  export interface BaseStreamInfo {
81
97
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livekit-client",
3
- "version": "2.15.4",
3
+ "version": "2.15.5",
4
4
  "description": "JavaScript/TypeScript client SDK for LiveKit",
5
5
  "main": "./dist/livekit-client.umd.js",
6
6
  "unpkg": "./dist/livekit-client.umd.js",