@livekit/rtc-node 0.13.32 → 0.13.33

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 (110) hide show
  1. package/dist/async_queue.d.ts +2 -3
  2. package/dist/audio_filter.d.ts +2 -3
  3. package/dist/audio_frame.d.ts +5 -6
  4. package/dist/audio_mixer.d.ts +3 -6
  5. package/dist/audio_resampler.d.ts +3 -6
  6. package/dist/audio_source.d.ts +5 -6
  7. package/dist/{audio_stream-4M8XlO4-.d.cts → audio_stream-CnODFAmo.d.cts} +1 -0
  8. package/dist/audio_stream.d.cts +1 -1
  9. package/dist/audio_stream.d.ts +61 -18
  10. package/dist/data_streams/index.d.ts +4 -3
  11. package/dist/data_streams/stream_reader.d.ts +48 -2
  12. package/dist/data_streams/stream_writer.d.ts +5 -7
  13. package/dist/data_streams/types.d.ts +41 -2
  14. package/dist/e2ee.d.ts +8 -10
  15. package/dist/ffi_client.d.ts +8 -10
  16. package/dist/frame_processor.d.ts +8 -11
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.ts +22 -17
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -107
  22. package/dist/log.d.ts +5 -7
  23. package/dist/participant.cjs +7 -2
  24. package/dist/participant.cjs.map +1 -1
  25. package/dist/participant.d.cts +1 -1
  26. package/dist/participant.d.ts +152 -18
  27. package/dist/participant.d.ts.map +1 -1
  28. package/dist/room.cjs +6 -0
  29. package/dist/room.cjs.map +1 -1
  30. package/dist/room.d.cts +2 -2
  31. package/dist/room.d.ts +220 -18
  32. package/dist/room.d.ts.map +1 -1
  33. package/dist/rpc.d.ts +7 -9
  34. package/dist/track.d.cts +1 -1
  35. package/dist/track.d.ts +67 -18
  36. package/dist/track_publication.d.cts +1 -1
  37. package/dist/track_publication.d.ts +45 -18
  38. package/dist/transcription.d.ts +3 -4
  39. package/dist/types.d.ts +2 -3
  40. package/dist/utils.d.ts +4 -5
  41. package/dist/version.cjs +1 -1
  42. package/dist/version.cjs.map +1 -1
  43. package/dist/version.d.cts +1 -1
  44. package/dist/version.d.ts +2 -3
  45. package/dist/video_frame.d.ts +4 -5
  46. package/dist/video_source.d.ts +6 -8
  47. package/dist/video_stream.d.cts +1 -1
  48. package/dist/video_stream.d.ts +5 -22
  49. package/package.json +5 -6
  50. package/src/index.ts +8 -1
  51. package/src/participant.ts +7 -1
  52. package/src/room.ts +10 -0
  53. package/src/version.ts +1 -1
  54. package/dist/async_queue.js +0 -56
  55. package/dist/async_queue.js.map +0 -1
  56. package/dist/audio_filter.js +0 -24
  57. package/dist/audio_filter.js.map +0 -1
  58. package/dist/audio_frame.js +0 -78
  59. package/dist/audio_frame.js.map +0 -1
  60. package/dist/audio_mixer.js +0 -269
  61. package/dist/audio_mixer.js.map +0 -1
  62. package/dist/audio_resampler.js +0 -154
  63. package/dist/audio_resampler.js.map +0 -1
  64. package/dist/audio_source.js +0 -134
  65. package/dist/audio_source.js.map +0 -1
  66. package/dist/audio_stream-CTyN1Ldy.d.ts +0 -523
  67. package/dist/audio_stream.js +0 -122
  68. package/dist/audio_stream.js.map +0 -1
  69. package/dist/data_streams/index.js +0 -3
  70. package/dist/data_streams/index.js.map +0 -1
  71. package/dist/data_streams/stream_reader.js +0 -124
  72. package/dist/data_streams/stream_reader.js.map +0 -1
  73. package/dist/data_streams/stream_writer.js +0 -26
  74. package/dist/data_streams/stream_writer.js.map +0 -1
  75. package/dist/data_streams/types.js +0 -1
  76. package/dist/data_streams/types.js.map +0 -1
  77. package/dist/e2ee.js +0 -251
  78. package/dist/e2ee.js.map +0 -1
  79. package/dist/ffi_client.js +0 -89
  80. package/dist/ffi_client.js.map +0 -1
  81. package/dist/frame_processor.js +0 -29
  82. package/dist/frame_processor.js.map +0 -1
  83. package/dist/index.js.map +0 -1
  84. package/dist/log.js +0 -9
  85. package/dist/log.js.map +0 -1
  86. package/dist/participant.js +0 -715
  87. package/dist/participant.js.map +0 -1
  88. package/dist/room.js +0 -900
  89. package/dist/room.js.map +0 -1
  90. package/dist/rpc.js +0 -65
  91. package/dist/rpc.js.map +0 -1
  92. package/dist/track.js +0 -234
  93. package/dist/track.js.map +0 -1
  94. package/dist/track_publication.js +0 -100
  95. package/dist/track_publication.js.map +0 -1
  96. package/dist/transcription.js +0 -1
  97. package/dist/transcription.js.map +0 -1
  98. package/dist/types-_PdPVish.d.ts +0 -87
  99. package/dist/types.js +0 -1
  100. package/dist/types.js.map +0 -1
  101. package/dist/utils.js +0 -35
  102. package/dist/utils.js.map +0 -1
  103. package/dist/version.js +0 -5
  104. package/dist/version.js.map +0 -1
  105. package/dist/video_frame.js +0 -207
  106. package/dist/video_frame.js.map +0 -1
  107. package/dist/video_source.js +0 -53
  108. package/dist/video_source.js.map +0 -1
  109. package/dist/video_stream.js +0 -70
  110. package/dist/video_stream.js.map +0 -1
@@ -1,134 +0,0 @@
1
- import {
2
- AudioSourceType,
3
- CaptureAudioFrameRequest,
4
- ClearAudioBufferRequest,
5
- FfiHandle,
6
- NewAudioSourceRequest
7
- } from "@livekit/rtc-ffi-bindings";
8
- import { FfiClient } from "./ffi_client.js";
9
- class AudioSource {
10
- constructor(sampleRate, numChannels, queueSize = 1e3) {
11
- /** @internal */
12
- this.promise = void 0;
13
- /** @internal */
14
- this.resolvePromise = void 0;
15
- /** @internal */
16
- this.timeout = void 0;
17
- /** @internal */
18
- this.closed = false;
19
- /**
20
- * Resolve the pending waitForPlayout() promise (if any) and reset the queue
21
- * bookkeeping. Mirrors python-sdks' AudioSource._release_waiter: the promise is
22
- * discarded here and lazily re-created by the next captureFrame, so a later
23
- * waitForPlayout() can never consume a stale resolution and report playout
24
- * complete while audio is still queued.
25
- * @internal
26
- */
27
- this.releaseWaiter = () => {
28
- var _a;
29
- if (!this.promise) {
30
- return;
31
- }
32
- (_a = this.resolvePromise) == null ? void 0 : _a.call(this);
33
- this.lastCapture = 0;
34
- this.currentQueueSize = 0;
35
- this.promise = void 0;
36
- this.resolvePromise = void 0;
37
- if (this.timeout) {
38
- clearTimeout(this.timeout);
39
- this.timeout = void 0;
40
- }
41
- };
42
- this.sampleRate = sampleRate;
43
- this.numChannels = numChannels;
44
- this.queueSize = queueSize;
45
- this.lastCapture = 0;
46
- this.currentQueueSize = 0;
47
- const req = new NewAudioSourceRequest({
48
- type: AudioSourceType.AUDIO_SOURCE_NATIVE,
49
- sampleRate,
50
- numChannels,
51
- queueSizeMs: queueSize
52
- });
53
- const res = FfiClient.instance.request({
54
- message: {
55
- case: "newAudioSource",
56
- value: req
57
- }
58
- });
59
- this.info = res.source.info;
60
- this.ffiHandle = new FfiHandle(res.source.handle.id);
61
- }
62
- get queuedDuration() {
63
- return Math.max(
64
- this.currentQueueSize - Number(process.hrtime.bigint() / BigInt(1e6)) + this.lastCapture,
65
- 0
66
- );
67
- }
68
- clearQueue() {
69
- const req = new ClearAudioBufferRequest({
70
- sourceHandle: this.ffiHandle.handle
71
- });
72
- FfiClient.instance.request({
73
- message: {
74
- case: "clearAudioBuffer",
75
- value: req
76
- }
77
- });
78
- this.releaseWaiter();
79
- }
80
- async waitForPlayout() {
81
- if (!this.promise) {
82
- return;
83
- }
84
- await this.promise;
85
- }
86
- async captureFrame(frame) {
87
- if (this.closed) {
88
- throw new Error("AudioSource is closed");
89
- }
90
- if (frame.samplesPerChannel === 0) {
91
- return;
92
- }
93
- const now = Number(process.hrtime.bigint() / BigInt(1e6));
94
- const elapsed = this.lastCapture === 0 ? 0 : now - this.lastCapture;
95
- const frameDurationMs = frame.samplesPerChannel / frame.sampleRate * 1e3;
96
- this.currentQueueSize = Math.max(this.currentQueueSize - elapsed, 0) + frameDurationMs;
97
- this.lastCapture = now;
98
- if (this.timeout) {
99
- clearTimeout(this.timeout);
100
- }
101
- if (!this.promise) {
102
- this.promise = new Promise((resolve) => {
103
- this.resolvePromise = resolve;
104
- });
105
- }
106
- this.timeout = setTimeout(this.releaseWaiter, this.currentQueueSize);
107
- const req = new CaptureAudioFrameRequest({
108
- sourceHandle: this.ffiHandle.handle,
109
- buffer: frame.protoInfo()
110
- });
111
- const res = FfiClient.instance.request({
112
- message: { case: "captureAudioFrame", value: req }
113
- });
114
- const cb = await FfiClient.instance.waitFor((ev) => {
115
- return ev.message.case == "captureAudioFrame" && ev.message.value.asyncId == res.asyncId;
116
- });
117
- if (cb.error) {
118
- throw new Error(cb.error);
119
- }
120
- }
121
- async close() {
122
- if (this.timeout) {
123
- clearTimeout(this.timeout);
124
- this.timeout = void 0;
125
- }
126
- this.releaseWaiter();
127
- this.ffiHandle.dispose();
128
- this.closed = true;
129
- }
130
- }
131
- export {
132
- AudioSource
133
- };
134
- //# sourceMappingURL=audio_source.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/audio_source.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type {\n AudioSourceInfo,\n CaptureAudioFrameCallback,\n CaptureAudioFrameResponse,\n ClearAudioBufferResponse,\n NewAudioSourceResponse,\n} from '@livekit/rtc-ffi-bindings';\nimport {\n AudioSourceType,\n CaptureAudioFrameRequest,\n ClearAudioBufferRequest,\n FfiHandle,\n NewAudioSourceRequest,\n} from '@livekit/rtc-ffi-bindings';\nimport type { AudioFrame } from './audio_frame.js';\nimport { FfiClient } from './ffi_client.js';\n\nexport class AudioSource {\n /** @internal */\n info: AudioSourceInfo;\n /** @internal */\n ffiHandle: FfiHandle;\n /** @internal */\n lastCapture: number;\n /** @internal */\n currentQueueSize: number;\n /** @internal */\n promise?: Promise<void> = undefined;\n /** @internal */\n resolvePromise?: () => void = undefined;\n /** @internal */\n timeout?: ReturnType<typeof setTimeout> = undefined;\n /** @internal */\n closed = false;\n\n sampleRate: number;\n numChannels: number;\n queueSize: number;\n\n constructor(sampleRate: number, numChannels: number, queueSize = 1000) {\n this.sampleRate = sampleRate;\n this.numChannels = numChannels;\n this.queueSize = queueSize;\n\n this.lastCapture = 0;\n this.currentQueueSize = 0;\n\n const req = new NewAudioSourceRequest({\n type: AudioSourceType.AUDIO_SOURCE_NATIVE,\n sampleRate: sampleRate,\n numChannels: numChannels,\n queueSizeMs: queueSize,\n });\n\n const res = FfiClient.instance.request<NewAudioSourceResponse>({\n message: {\n case: 'newAudioSource',\n value: req,\n },\n });\n\n this.info = res.source!.info!;\n this.ffiHandle = new FfiHandle(res.source!.handle!.id!);\n }\n\n get queuedDuration(): number {\n return Math.max(\n this.currentQueueSize - Number(process.hrtime.bigint() / BigInt(1000000)) + this.lastCapture,\n 0,\n );\n }\n\n clearQueue() {\n const req = new ClearAudioBufferRequest({\n sourceHandle: this.ffiHandle.handle,\n });\n\n FfiClient.instance.request<ClearAudioBufferResponse>({\n message: {\n case: 'clearAudioBuffer',\n value: req,\n },\n });\n\n this.releaseWaiter();\n }\n\n /**\n * Resolve the pending waitForPlayout() promise (if any) and reset the queue\n * bookkeeping. Mirrors python-sdks' AudioSource._release_waiter: the promise is\n * discarded here and lazily re-created by the next captureFrame, so a later\n * waitForPlayout() can never consume a stale resolution and report playout\n * complete while audio is still queued.\n * @internal\n */\n releaseWaiter = () => {\n if (!this.promise) {\n return;\n }\n\n this.resolvePromise?.();\n this.lastCapture = 0;\n this.currentQueueSize = 0;\n this.promise = undefined;\n this.resolvePromise = undefined;\n // cancel the drain timer (e.g. when released early by clearQueue), otherwise\n // it would fire later and release the waiter of a subsequent segment\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = undefined;\n }\n };\n\n async waitForPlayout() {\n if (!this.promise) {\n return;\n }\n\n await this.promise;\n }\n\n async captureFrame(frame: AudioFrame) {\n if (this.closed) {\n throw new Error('AudioSource is closed');\n }\n\n if (frame.samplesPerChannel === 0) {\n return;\n }\n\n const now = Number(process.hrtime.bigint() / BigInt(1000000));\n const elapsed = this.lastCapture === 0 ? 0 : now - this.lastCapture;\n const frameDurationMs = (frame.samplesPerChannel / frame.sampleRate) * 1000;\n this.currentQueueSize = Math.max(this.currentQueueSize - elapsed, 0) + frameDurationMs;\n\n this.lastCapture = now;\n\n if (this.timeout) {\n clearTimeout(this.timeout);\n }\n\n if (!this.promise) {\n this.promise = new Promise<void>((resolve) => {\n this.resolvePromise = resolve;\n });\n }\n\n this.timeout = setTimeout(this.releaseWaiter, this.currentQueueSize);\n\n const req = new CaptureAudioFrameRequest({\n sourceHandle: this.ffiHandle.handle,\n buffer: frame.protoInfo(),\n });\n\n const res = FfiClient.instance.request<CaptureAudioFrameResponse>({\n message: { case: 'captureAudioFrame', value: req },\n });\n\n const cb = await FfiClient.instance.waitFor<CaptureAudioFrameCallback>((ev) => {\n return ev.message.case == 'captureAudioFrame' && ev.message.value.asyncId == res.asyncId;\n });\n\n if (cb.error) {\n throw new Error(cb.error);\n }\n }\n\n async close() {\n // Clear any pending playout timeout so its callback doesn't fire after\n // the handle is disposed, which would reference freed native state.\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = undefined;\n }\n // Resolve any pending waitForPlayout() promise so callers don't hang.\n this.releaseWaiter();\n this.ffiHandle.dispose();\n this.closed = true;\n }\n}\n"],"mappings":"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","names":[]}
@@ -1,523 +0,0 @@
1
- import { UnderlyingSource } from 'node:stream/web';
2
- import { AudioFrame } from './audio_frame.js';
3
- import { FrameProcessor } from './frame_processor.js';
4
- import * as _livekit_rtc_ffi_bindings from '@livekit/rtc-ffi-bindings';
5
- import { FfiHandle, TrackPublicationInfo, OwnedTrackPublication, TrackKind, TrackSource, EncryptionType, ParticipantInfo, OwnedParticipant, ParticipantKind, ParticipantKindDetail, DisconnectReason, TrackPublishOptions, RoomInfo, ConnectionQuality, DataPacketKind, ConnectionState, IceTransportType, ContinualGatheringPolicy, IceServer, SimulateScenarioKind, RoomOptions as RoomOptions$1, TrackInfo, OwnedTrack, StreamState } from '@livekit/rtc-ffi-bindings';
6
- import { AudioSource } from './audio_source.js';
7
- import './ffi_client.js';
8
- import { TypedEventEmitter } from '@livekit/typed-emitter';
9
- import { B as BaseStreamInfo, c as ByteStreamOptions, T as TextStreamHandler, a as ByteStreamHandler } from './types-_PdPVish.js';
10
- import { E2EEManager, E2EEOptions } from './e2ee.js';
11
- import { Mutex } from '@livekit/mutex';
12
- import { PathLike } from 'node:fs';
13
- import { TextStreamWriter, ByteStreamWriter } from './data_streams/stream_writer.js';
14
- import { PerformRpcParams, RpcInvocationData } from './rpc.js';
15
- import { Transcription } from './transcription.js';
16
- import { ChatMessage } from './types.js';
17
- import { VideoSource } from './video_source.js';
18
-
19
- declare abstract class TrackPublication {
20
- /** @internal */
21
- ffiHandle: FfiHandle;
22
- /** @internal */
23
- info?: TrackPublicationInfo;
24
- track?: Track;
25
- constructor(ownedInfo: OwnedTrackPublication);
26
- get sid(): string | undefined;
27
- get name(): string | undefined;
28
- get kind(): TrackKind | undefined;
29
- get source(): TrackSource | undefined;
30
- get simulcasted(): boolean | undefined;
31
- get width(): number | undefined;
32
- get height(): number | undefined;
33
- get mimeType(): string | undefined;
34
- get muted(): boolean | undefined;
35
- get encryptionType(): EncryptionType | undefined;
36
- /**
37
- * Update the publication's info in place. Used by the SDK when the
38
- * server re-issues IDs / metadata for an existing publication (e.g.
39
- * after a full reconnect). Application code holding a cached
40
- * publication reference continues to read fresh values via the
41
- * unchanged object identity.
42
- * @internal
43
- */
44
- updateInfo(info: TrackPublicationInfo): void;
45
- }
46
- declare class LocalTrackPublication extends TrackPublication {
47
- private firstSubscription;
48
- private firstSubscriptionResolver;
49
- constructor(ownedInfo: OwnedTrackPublication);
50
- waitForSubscription(): Promise<void>;
51
- /** @internal */
52
- resolveFirstSubscription(): void;
53
- }
54
- declare class RemoteTrackPublication extends TrackPublication {
55
- subscribed: boolean;
56
- constructor(ownedInfo: OwnedTrackPublication);
57
- setSubscribed(subscribed: boolean): void;
58
- }
59
-
60
- declare abstract class Participant {
61
- /** @internal */
62
- info: ParticipantInfo;
63
- /** @internal */
64
- ffi_handle: FfiHandle;
65
- trackPublications: Map<string, TrackPublication>;
66
- constructor(owned_info: OwnedParticipant);
67
- get sid(): string | undefined;
68
- get name(): string | undefined;
69
- get identity(): string;
70
- get metadata(): string;
71
- get attributes(): Record<string, string>;
72
- get kind(): ParticipantKind;
73
- get kindDetails(): ParticipantKindDetail[];
74
- get disconnectReason(): DisconnectReason | undefined;
75
- }
76
- type DataPublishOptions = {
77
- /**
78
- * whether to send this as reliable or lossy.
79
- * For data that you need delivery guarantee (such as chat messages), use Reliable.
80
- * For data that should arrive as quickly as possible, but you are ok with dropped
81
- * packets, use Lossy.
82
- */
83
- reliable?: boolean;
84
- /**
85
- * the identities of participants who will receive the message, will be sent to every one if empty
86
- */
87
- destination_identities?: string[];
88
- /** the topic under which the message gets published */
89
- topic?: string;
90
- };
91
- declare class LocalParticipant extends Participant {
92
- private rpcHandlers;
93
- private ffiEventLock;
94
- private disconnectSignal;
95
- trackPublications: Map<string, LocalTrackPublication>;
96
- constructor(info: OwnedParticipant, ffiEventLock: Mutex, disconnectSignal: AbortSignal);
97
- publishData(data: Uint8Array, options: DataPublishOptions): Promise<void>;
98
- publishDtmf(code: number, digit: string): Promise<void>;
99
- publishTranscription(transcription: Transcription): Promise<void>;
100
- updateMetadata(metadata: string): Promise<void>;
101
- /**
102
- * Returns a `StreamWriter` instance that allows to write individual chunks of text to a stream.
103
- * Well suited for TTS and/or streaming LLM output. If you want to simply send a text then use sendText() instead
104
- */
105
- streamText(options?: {
106
- topic?: string;
107
- attributes?: Record<string, string>;
108
- destinationIdentities?: Array<string>;
109
- streamId?: string;
110
- senderIdentity?: string;
111
- }): Promise<TextStreamWriter>;
112
- sendText(text: string, options?: {
113
- topic?: string;
114
- attributes?: Record<string, string>;
115
- destinationIdentities?: Array<string>;
116
- streamId?: string;
117
- }): Promise<BaseStreamInfo>;
118
- streamBytes(options?: {
119
- name?: string;
120
- topic?: string;
121
- attributes?: Record<string, string>;
122
- destinationIdentities?: Array<string>;
123
- streamId?: string;
124
- mimeType?: string;
125
- totalSize?: number;
126
- }): Promise<ByteStreamWriter>;
127
- /** Sends a file provided as PathLike to specified recipients */
128
- sendFile(path: PathLike, options?: ByteStreamOptions): Promise<void>;
129
- private sendStreamHeader;
130
- private sendStreamChunk;
131
- private sendStreamTrailer;
132
- /**
133
- * Sends a chat message to participants in the room
134
- *
135
- * @param text - The text content of the chat message.
136
- * @param destinationIdentities - An optional array of recipient identities to whom the message will be sent. If omitted, the message is broadcast to all participants.
137
- * @param senderIdentity - An optional identity of the sender. If omitted, the default sender identity is used.
138
- *
139
- */
140
- sendChatMessage(text: string, destinationIdentities?: Array<string>, senderIdentity?: string): Promise<ChatMessage>;
141
- /**
142
- * @experimental
143
- */
144
- editChatMessage(editText: string, originalMessage: ChatMessage, destinationIdentities?: Array<string>, senderIdentity?: string): Promise<ChatMessage>;
145
- updateName(name: string): Promise<void>;
146
- setAttributes(attributes: Record<string, string>): Promise<void>;
147
- publishTrack(track: LocalTrack, options: TrackPublishOptions): Promise<LocalTrackPublication>;
148
- unpublishTrack(trackSid: string, stopOnUnpublish?: boolean): Promise<void>;
149
- /**
150
- * Initiate an RPC call to a remote participant.
151
- * @param params - Parameters for initiating the RPC call, see {@link PerformRpcParams}
152
- * @returns A promise that resolves with the response payload or rejects with an error.
153
- * @throws Error on failure. Details in `message`.
154
- */
155
- performRpc({ destinationIdentity, method, payload, responseTimeout, }: PerformRpcParams): Promise<string>;
156
- /**
157
- * Establishes the participant as a receiver for calls of the specified RPC method.
158
- * Will overwrite any existing callback for the same method.
159
- *
160
- * @param method - The name of the indicated RPC method
161
- * @param handler - Will be invoked when an RPC request for this method is received
162
- * @returns A promise that resolves when the method is successfully registered
163
- *
164
- * @example
165
- * ```typescript
166
- * room.localParticipant?.registerRpcMethod(
167
- * 'greet',
168
- * async (data: RpcInvocationData) => {
169
- * console.log(`Received greeting from ${data.callerIdentity}: ${data.payload}`);
170
- * return `Hello, ${data.callerIdentity}!`;
171
- * }
172
- * );
173
- * ```
174
- *
175
- * See {@link RpcInvocationData} for more details on invocation params.
176
- *
177
- * The handler should return a Promise that resolves to a string.
178
- * If unable to respond within `responseTimeout`, the request will result in an error on the caller's side.
179
- *
180
- * You may throw errors of type `RpcError` with a string `message` in the handler,
181
- * and they will be received on the caller's side with the message intact.
182
- * Other errors thrown in your handler will not be transmitted as-is, and will instead arrive to the caller as `1500` ("Application Error").
183
- */
184
- registerRpcMethod(method: string, handler: (data: RpcInvocationData) => Promise<string>): void;
185
- /**
186
- * Unregisters a previously registered RPC method.
187
- *
188
- * @param method - The name of the RPC method to unregister
189
- */
190
- unregisterRpcMethod(method: string): void;
191
- /** @internal */
192
- handleRpcMethodInvocation(invocationId: bigint, method: string, requestId: string, callerIdentity: string, payload: string, responseTimeout: number): Promise<void>;
193
- }
194
- declare class RemoteParticipant extends Participant {
195
- trackPublications: Map<string, RemoteTrackPublication>;
196
- constructor(owned_info: OwnedParticipant);
197
- }
198
-
199
- interface RtcConfiguration {
200
- iceTransportType: IceTransportType;
201
- continualGatheringPolicy: ContinualGatheringPolicy;
202
- iceServers: IceServer[];
203
- }
204
- declare const defaultRtcConfiguration: RtcConfiguration;
205
- interface RoomOptions {
206
- autoSubscribe: boolean;
207
- dynacast: boolean;
208
- /**
209
- * @deprecated Use `encryption` instead. See x for details
210
- */
211
- e2ee?: E2EEOptions;
212
- encryption?: E2EEOptions;
213
- rtcConfig?: RtcConfiguration;
214
- }
215
- declare const defaultRoomOptions: RoomOptions$1;
216
- declare const Room_base: new () => TypedEventEmitter<RoomCallbacks>;
217
- declare class Room extends Room_base {
218
- private info?;
219
- private ffiHandle?;
220
- /**
221
- * used to ensure events are processed sequentially and allow for
222
- * the local participant to acquire the lock while doing state updates related to FFI events
223
- * before processing the next events
224
- */
225
- private ffiEventLock;
226
- private byteStreamControllers;
227
- private textStreamControllers;
228
- private byteStreamHandlers;
229
- private textStreamHandlers;
230
- private preConnectEvents;
231
- private disconnectController;
232
- private hasCleanedUp;
233
- private _token?;
234
- private _serverUrl?;
235
- private _connectionState;
236
- e2eeManager?: E2EEManager;
237
- remoteParticipants: Map<string, RemoteParticipant>;
238
- localParticipant?: LocalParticipant;
239
- constructor();
240
- get connectionState(): ConnectionState;
241
- get name(): string | undefined;
242
- get metadata(): string | undefined;
243
- get isConnected(): boolean;
244
- /** @internal */
245
- get token(): string | undefined;
246
- /** @internal */
247
- get serverUrl(): string | undefined;
248
- private sidPromise?;
249
- /**
250
- * Gets the room's server ID. This ID is assigned by the LiveKit server
251
- * and is unique for each room session.
252
- * SID is assigned asynchronously after connection.
253
- * @returns Promise that resolves to the room's server ID, or empty string if not connected
254
- */
255
- getSid(): Promise<string>;
256
- getRtcStats(): Promise<_livekit_rtc_ffi_bindings.GetSessionStatsCallback_Result>;
257
- get numParticipants(): number;
258
- get numPublishers(): number;
259
- get creationTime(): Date;
260
- get isRecording(): boolean;
261
- /**
262
- * The time in seconds after which a room will be closed after the last
263
- * participant has disconnected.
264
- */
265
- get departureTimeout(): number;
266
- /**
267
- * The time in seconds after which an empty room will be automatically closed.
268
- */
269
- get emptyTimeout(): number;
270
- /**
271
- * Connects to a LiveKit room using the provided URL and access token.
272
- * @param url - The WebSocket URL of the LiveKit server
273
- * @param token - A valid LiveKit access token for authentication
274
- * @param opts - Optional room configuration options
275
- * @throws ConnectError - if connection fails
276
- */
277
- connect(url: string, token: string, opts?: RoomOptions): Promise<void>;
278
- /**
279
- * Disconnects from the room and cleans up all resources.
280
- * This will stop all tracks and close the connection.
281
- */
282
- disconnect(): Promise<void>;
283
- /**
284
- * Trigger a reconnection / chaos scenario for testing. Most useful in
285
- * tests to deterministically force a Resume (signal-only reconnect that
286
- * preserves the PeerConnection and existing publications) or a full
287
- * reconnect (the SDK rebuilds the RtcSession and re-publishes existing
288
- * local tracks; `RoomEvent.Reconnected` fires).
289
- */
290
- simulateScenario(scenario: SimulateScenarioKind): Promise<void>;
291
- private updateConnectionState;
292
- private cleanupOnDisconnect;
293
- /**
294
- * Registers a handler for incoming text data streams on a specific topic.
295
- * Text streams are used for receiving structured text data from other participants.
296
- * @param topic - The topic to listen for text streams on
297
- * @param callback - Function to handle incoming text stream data
298
- * @throws Error - if a handler for this topic is already registered
299
- */
300
- registerTextStreamHandler(topic: string, callback: TextStreamHandler): void;
301
- unregisterTextStreamHandler(topic: string): void;
302
- /**
303
- * Registers a handler for incoming byte data streams on a specific topic.
304
- * Byte streams are used for receiving binary data like files from other participants.
305
- * @param topic - The topic to listen for byte streams on
306
- * @param callback - Function to handle incoming byte stream data
307
- * @throws Error - if a handler for this topic is already registered
308
- */
309
- registerByteStreamHandler(topic: string, callback: ByteStreamHandler): void;
310
- unregisterByteStreamHandler(topic: string): void;
311
- private onFfiEvent;
312
- private processFfiEvent;
313
- private retrieveParticipantByIdentity;
314
- private requireParticipantByIdentity;
315
- private requireRemoteParticipant;
316
- private requirePublicationOfParticipant;
317
- private requirePublicationOfRemoteParticipant;
318
- private createRemoteParticipant;
319
- private handleStreamHeader;
320
- private handleStreamChunk;
321
- private handleStreamTrailer;
322
- }
323
- declare class ConnectError extends Error {
324
- constructor(message: string);
325
- }
326
- type RoomCallbacks = {
327
- participantConnected: (participant: RemoteParticipant) => void;
328
- participantDisconnected: (participant: RemoteParticipant) => void;
329
- localTrackPublished: (publication: LocalTrackPublication, participant: LocalParticipant) => void;
330
- localTrackUnpublished: (publication: LocalTrackPublication, participant: LocalParticipant) => void;
331
- /**
332
- * Fired when the SDK auto-republished a local track during a full
333
- * reconnect. The publication object's identity is preserved (the same
334
- * instance is updated in place with the new server-assigned SIDs);
335
- * `previousSid` is provided for callers that key external state on the
336
- * old SID and need to reconcile.
337
- */
338
- localTrackRepublished: (publication: LocalTrackPublication, previousSid: string, participant: LocalParticipant) => void;
339
- localTrackSubscribed: (track: LocalTrack) => void;
340
- trackPublished: (publication: RemoteTrackPublication, participant: RemoteParticipant) => void;
341
- trackUnpublished: (publication: RemoteTrackPublication, participant: RemoteParticipant) => void;
342
- trackSubscribed: (track: RemoteTrack, publication: RemoteTrackPublication, participant: RemoteParticipant) => void;
343
- trackUnsubscribed: (track: RemoteTrack, publication: RemoteTrackPublication, participant: RemoteParticipant) => void;
344
- trackSubscriptionFailed: (trackSid: string, participant: RemoteParticipant, reason?: string) => void;
345
- trackMuted: (publication: TrackPublication, participant: Participant) => void;
346
- trackUnmuted: (publication: TrackPublication, participant: Participant) => void;
347
- activeSpeakersChanged: (speakers: Participant[]) => void;
348
- roomMetadataChanged: (metadata: string) => void;
349
- roomInfoUpdated: (info: RoomInfo) => void;
350
- participantMetadataChanged: (metadata: string | undefined, participant: Participant) => void;
351
- participantNameChanged: (name: string, participant: Participant) => void;
352
- participantAttributesChanged: (changedAttributes: Record<string, string>, participant: Participant) => void;
353
- participantEncryptionStatusChanged: (isEncrypted: boolean, participant: Participant) => void;
354
- connectionQualityChanged: (quality: ConnectionQuality, participant: Participant) => void;
355
- dataReceived: (payload: Uint8Array, participant?: RemoteParticipant, kind?: DataPacketKind, topic?: string, encryptionType?: EncryptionType) => void;
356
- chatMessage: (message: ChatMessage, participant?: Participant) => void;
357
- dtmfReceived: (code: number, digit: string, participant: RemoteParticipant) => void;
358
- encryptionError: (error: Error) => void;
359
- connectionStateChanged: (state: ConnectionState) => void;
360
- connected: () => void;
361
- disconnected: (reason: DisconnectReason) => void;
362
- reconnecting: () => void;
363
- reconnected: () => void;
364
- roomSidChanged: (sid: string) => void;
365
- roomUpdated: () => void;
366
- moved: () => void;
367
- tokenRefreshed: () => void;
368
- };
369
- declare enum RoomEvent {
370
- ParticipantConnected = "participantConnected",
371
- ParticipantDisconnected = "participantDisconnected",
372
- LocalTrackPublished = "localTrackPublished",
373
- LocalTrackUnpublished = "localTrackUnpublished",
374
- LocalTrackRepublished = "localTrackRepublished",
375
- LocalTrackSubscribed = "localTrackSubscribed",
376
- TrackPublished = "trackPublished",
377
- TrackUnpublished = "trackUnpublished",
378
- TrackSubscribed = "trackSubscribed",
379
- TrackUnsubscribed = "trackUnsubscribed",
380
- TrackSubscriptionFailed = "trackSubscriptionFailed",
381
- TrackMuted = "trackMuted",
382
- TrackUnmuted = "trackUnmuted",
383
- ActiveSpeakersChanged = "activeSpeakersChanged",
384
- RoomMetadataChanged = "roomMetadataChanged",
385
- RoomSidChanged = "roomSidChanged",
386
- ParticipantMetadataChanged = "participantMetadataChanged",
387
- ParticipantNameChanged = "participantNameChanged",
388
- ParticipantAttributesChanged = "participantAttributesChanged",
389
- ParticipantEncryptionStatusChanged = "participantEncryptionStatusChanged",
390
- ConnectionQualityChanged = "connectionQualityChanged",
391
- DataReceived = "dataReceived",
392
- ChatMessage = "chatMessage",
393
- DtmfReceived = "dtmfReceived",
394
- EncryptionError = "encryptionError",
395
- ConnectionStateChanged = "connectionStateChanged",
396
- Connected = "connected",
397
- Disconnected = "disconnected",
398
- Reconnecting = "reconnecting",
399
- Reconnected = "reconnected",
400
- RoomUpdated = "roomUpdated",
401
- Moved = "moved",
402
- TokenRefreshed = "tokenRefreshed"
403
- }
404
-
405
- declare abstract class Track {
406
- /** @internal */
407
- info?: TrackInfo;
408
- /** @internal */
409
- ffi_handle: FfiHandle;
410
- private roomRef;
411
- private audioStreams;
412
- private streamFinalizationRegistry;
413
- private onRoomTokenRefreshed;
414
- constructor(owned: OwnedTrack);
415
- /** @internal */
416
- resolveRoom(): Room | null;
417
- /** @internal */
418
- setRoom(room: Room | null): void;
419
- /** @internal */
420
- registerAudioStream(stream: AudioStreamSource): void;
421
- /** @internal */
422
- unregisterAudioStream(stream: AudioStreamSource): void;
423
- /**
424
- * End every {@link AudioStream} attached to this track.
425
- *
426
- * @remarks
427
- * The FFI keeps feeding an audio stream until the stream's own handle is
428
- * dropped, so streams on a track that is no longer subscribed would otherwise
429
- * go on delivering audio for the lifetime of the process.
430
- *
431
- * @internal
432
- */
433
- closeAudioStreams(): void;
434
- private iterateStreams;
435
- private pushProcessorMetadataToStream;
436
- get sid(): string | undefined;
437
- get name(): string | undefined;
438
- get kind(): TrackKind | undefined;
439
- get stream_state(): StreamState | undefined;
440
- get muted(): boolean | undefined;
441
- close(): Promise<void>;
442
- }
443
- declare class LocalAudioTrack extends Track {
444
- private source?;
445
- constructor(owned: OwnedTrack, source?: AudioSource);
446
- static createAudioTrack(name: string, source: AudioSource): LocalAudioTrack;
447
- close(closeSource?: boolean): Promise<void>;
448
- }
449
- declare class LocalVideoTrack extends Track {
450
- private source?;
451
- constructor(owned: OwnedTrack, source?: VideoSource);
452
- static createVideoTrack(name: string, source: VideoSource): LocalVideoTrack;
453
- close(closeSource?: boolean): Promise<void>;
454
- }
455
- declare class RemoteVideoTrack extends Track {
456
- constructor(owned: OwnedTrack);
457
- }
458
- declare class RemoteAudioTrack extends Track {
459
- constructor(owned: OwnedTrack);
460
- }
461
- type LocalTrack = LocalVideoTrack | LocalAudioTrack;
462
- type RemoteTrack = RemoteVideoTrack | RemoteAudioTrack;
463
- type AudioTrack = LocalAudioTrack | RemoteAudioTrack;
464
- type VideoTrack = LocalVideoTrack | RemoteVideoTrack;
465
-
466
- interface AudioStreamOptions {
467
- noiseCancellation?: NoiseCancellationOptions | FrameProcessor<AudioFrame>;
468
- /**
469
- * When the audio stream closes, whether to run the {@link FrameProcessor}'s
470
- * `close()` method. If `false`, the processor is left open so it can be
471
- * reused with another {@link AudioStream}. Only relevant when
472
- * `noiseCancellation` is a {@link FrameProcessor}. Defaults to `true`.
473
- */
474
- autoCloseNoiseCancellation?: boolean;
475
- sampleRate?: number;
476
- numChannels?: number;
477
- frameSizeMs?: number;
478
- }
479
- interface NoiseCancellationOptions {
480
- moduleId: string;
481
- options: Record<string, any>;
482
- }
483
- /** @internal */
484
- declare class AudioStreamSource implements UnderlyingSource<AudioFrame> {
485
- private controller?;
486
- private ffiHandle;
487
- private disposed;
488
- private sampleRate;
489
- private numChannels;
490
- private legacyNcOptions?;
491
- private frameProcessor;
492
- private autoCloseProcessor;
493
- private frameSizeMs?;
494
- private track;
495
- constructor(track: Track, sampleRateOrOptions?: number | AudioStreamOptions, numChannels?: number);
496
- /** @internal */
497
- get processor(): FrameProcessor<AudioFrame> | null;
498
- private onEvent;
499
- start(controller: ReadableStreamDefaultController<AudioFrame>): void;
500
- /**
501
- * Detach from the FFI and release resources: on `eos`, on `cancel()`, or
502
- * because the track went away (e.g. it was unsubscribed — which never
503
- * produces an `eos`, so without this the stream would keep delivering
504
- * frames). Already-buffered frames stay readable and the consumer sees `done`
505
- * after draining them.
506
- *
507
- * @remarks
508
- * Idempotent, so `eos` arriving after a `cancel()` (or vice versa) doesn't
509
- * double-dispose the handle while buffered frames are still queued.
510
- *
511
- * @internal
512
- */
513
- teardown(): void;
514
- cancel(): void;
515
- }
516
- declare class AudioStream extends ReadableStream<AudioFrame> {
517
- constructor(track: Track);
518
- constructor(track: Track, sampleRate: number);
519
- constructor(track: Track, sampleRate: number, numChannels: number);
520
- constructor(track: Track, options: AudioStreamOptions);
521
- }
522
-
523
- export { AudioStream as A, ConnectError as C, type DataPublishOptions as D, LocalAudioTrack as L, type NoiseCancellationOptions as N, Participant as P, RemoteAudioTrack as R, Track as T, type VideoTrack as V, type AudioTrack as a, LocalParticipant as b, type LocalTrack as c, LocalTrackPublication as d, LocalVideoTrack as e, RemoteParticipant as f, type RemoteTrack as g, RemoteTrackPublication as h, RemoteVideoTrack as i, Room as j, RoomEvent as k, type RoomOptions as l, type RtcConfiguration as m, TrackPublication as n, type RoomCallbacks as o, defaultRoomOptions as p, defaultRtcConfiguration as q, type AudioStreamOptions as r, AudioStreamSource as s };