import { DataPacket_Kind, DisconnectReason, Encryption_Type, MetricsBatch, ParticipantPermission, ServerInfo, SipDTMF, SubscriptionError, TranscriptionSegment as TranscriptionSegmentModel } from '@livekit/protocol'; import type TypedEmitter from 'typed-emitter'; import type { CoreRoomOptions, InternalRoomOptions, RoomConnectOptions } from '../options'; import type { NonSharedUint8Array } from '../type-polyfills/non-shared-typed-arrays'; import TypedPromise from '../utils/TypedPromise'; import RTCEngine from './RTCEngine'; import type { DataChannelKind } from './data-channel/types'; import type LocalDataTrack from './data-track/LocalDataTrack'; import type RemoteDataTrack from './data-track/RemoteDataTrack'; import type { DataTrackSid } from './data-track/types'; import { UnexpectedConnectionState } from './errors'; import type { RoomExtension } from './extensions'; import { LocalParticipant } from './participant/LocalParticipant'; import Participant from './participant/Participant'; import { type ConnectionQuality } from './participant/Participant'; import RemoteParticipant from './participant/RemoteParticipant'; import LocalTrackPublication from './track/LocalTrackPublication'; import type RemoteTrack from './track/RemoteTrack'; import RemoteTrackPublication from './track/RemoteTrackPublication'; import { Track } from './track/Track'; import type { TrackPublication } from './track/TrackPublication'; import { type ChatMessage, type SimulationScenario, type TranscriptionSegment } from './types'; export declare enum ConnectionState { Disconnected = "disconnected", Connecting = "connecting", Connected = "connected", Reconnecting = "reconnecting", SignalReconnecting = "signalReconnecting" } declare const CoreRoom_base: new () => TypedEmitter; /** * The room without optional features. Use `CoreRoom.with(...extensions)` to build a room class * with the features an application needs, or use `Room` from the main entry for all of them. * * In LiveKit, a room is the logical grouping for a list of participants. * Participants in a room can publish tracks, and subscribe to others' tracks. * * a Room fires [[RoomEvent | RoomEvents]]. * * @noInheritDoc * @experimental */ export declare class CoreRoom extends CoreRoom_base { state: ConnectionState; /** * map of identity: [[RemoteParticipant]] */ remoteParticipants: Map; /** * list of participants that are actively speaking. when this changes * a [[RoomEvent.ActiveSpeakersChanged]] event is fired */ activeSpeakers: Participant[]; /** * @internal */ engine: RTCEngine; /** the current participant */ localParticipant: LocalParticipant; /** options of room */ options: InternalRoomOptions; /** reflects the sender encryption status of the local participant */ isE2EEEnabled: boolean; serverInfo?: Partial; private roomInfo?; private sidToIdentity; /** connect options of room */ private connOptions?; private audioEnabled; private audioContext?; /** * whether `audioContext` was created by the SDK and therefore has to be closed by it. * A context handed in through `webAudioMix` is owned by the application instead. */ private ownsAudioContext; /** * set once the audio context has been released as part of a disconnect. Guards against * creating a new context outside of a connection lifecycle, where nothing would close it again. */ private audioContextReleased; /** * serialises `acquireAudioContext` against `releaseAudioContext`. Both await per-track graph * rebuilds, so without it a reconnect landing inside a disconnect's teardown leaves the two * racing to set the participants' context, and the loser's value is the one that sticks. */ private audioContextMutex; /** tears down the iOS dummy audio element, set while one is in place. See `startAudio` */ private releaseDummyAudioElement?; /** silent audio tracks this room acquired, handed back to the shared source on disconnect */ private acquiredEmptyAudioTracks; /** used for aborting pending connections to a LiveKit server */ private abortController?; /** future holding client initiated connection attempt */ private connectFuture?; private disconnectLock; /** the E2EE manager slot; filled by the `e2ee` extension */ private connectionReconcileInterval?; private statsLogInterval?; private regionUrlProvider?; private regionUrl?; private isVideoPlaybackBlocked; private log; private statsLog; private bufferedEvents; /** * the room as it was before the current full reconnect. Every region the full reconnect tries * starts from it, so the region it connects to reports every change since the outage */ private roomInfoBeforeRestart?; private isResuming; private pendingTrackAddedCallbacks; /** * map to store first point in time when a particular transcription segment was received */ private transcriptionReceivedTimes; private installedExtensions; /** Values extensions hand to core (the `*Provider` members of an install result); shared with the local participant. */ private readonly slots; private extensionDisposers; private dataPacketHandlers; /** aborts the `devicechange` listener; also reachable from the FinalizationRegistry callback */ private cleanupController?; private disposed; get hasE2EESetup(): boolean; /** * Creates a new Room, the primary construct for a LiveKit session. * @param options */ constructor(options?: CoreRoomOptions); /** * Installs resolved extensions on this room. `installExtensions()` in `extensions.ts` resolves * dependencies and calls this; `createRoom()` and the full `Room` go through it. * @internal */ installExtensions(extensions: readonly RoomExtension[]): void; /** The engine keeps its own copy of the slots it reads on the hot path. */ private applySlotsToEngine; private get extensionResults(); /** * Releases everything the room holds: disconnects if connected, disposes the extensions and * removes global listeners. The room cannot connect again afterwards. */ dispose(): Promise; private get logContext(); /** * if the current room has a participant with `recorder: true` in its JWT grant **/ get isRecording(): boolean; /** * server assigned unique room id. * returns once a sid has been issued by the server. */ getSid(): TypedPromise; /** user assigned name, derived from JWT token */ get name(): string; /** room metadata */ get metadata(): string | undefined; get numParticipants(): number; get numPublishers(): number; private maybeCreateEngine; private createRegionStrategy; /** * getLocalDevices abstracts navigator.mediaDevices.enumerateDevices. * In particular, it requests device permissions by default if needed * and makes sure the returned device does not consist of dummy devices * @param kind * @returns a list of available local devices */ static getLocalDevices(kind?: MediaDeviceKind, requestPermissions?: boolean): Promise; static cleanupRegistry: false | FinalizationRegistry; /** * Builds the constructor's `devicechange` listener. It lives outside the constructor so that * its closure only captures `roomRef`, not the constructor's context (which holds the Room). */ private static createWeakDeviceChangeListener; /** * prepareConnection should be called as soon as the page is loaded, in order * to speed up the connection attempt. This function will * - perform DNS resolution and pre-warm the DNS cache * - establish TLS connection and cache TLS keys * * With LiveKit Cloud, it will also determine the best edge data center for * the current client to connect to if a token is provided. */ prepareConnection(url: string, token?: string): Promise; connect: (url: string, token: string, opts?: RoomConnectOptions) => Promise; private connectSignal; private applyJoinResponse; private attemptConnection; /** * disconnects the room, emits [[RoomEvent.Disconnected]] */ disconnect: (stopTracks?: boolean) => Promise; /** * retrieves a participant by identity * @param identity * @returns */ getParticipantByIdentity(identity: string): Participant | undefined; private clearConnectionFutures; /** * @internal for testing */ simulateScenario(scenario: SimulationScenario, arg?: any): Promise; private onPageLeave; /** * iOS blocks audio element playback if * - user is not publishing audio themselves and * - no other audio source is playing * * as a workaround, we create an audio element with an empty track, so that * silent audio is always playing * * The element is shared with any other room on the page and handed back on disconnect, so it * outlives whichever room happened to create it. */ private acquireDummyAudioElement; /** * Obtains a silent audio track from the shared source and keeps track of it, so that it can be * handed back on disconnect and the shared `AudioContext` behind it can be closed again. */ private acquireEmptyAudioStreamTrack; private releaseAcquiredEmptyAudioTrack; private releaseAcquiredEmptyAudioTracks; /** * Browsers have different policies regarding audio playback. Most requiring * some form of user interaction (click/tap/etc). * In those cases, audio will be silent until a click/tap triggering one of the following * - `startAudio` * - `getUserMedia` */ startAudio: () => Promise; startVideo: () => Promise; /** * Returns true if audio playback is enabled */ get canPlaybackAudio(): boolean; /** * Returns true if video playback is enabled */ get canPlaybackVideo(): boolean; getActiveDevice(kind: MediaDeviceKind): string | undefined; /** * Switches all active devices used in this room to the given device. * * Note: setting AudioOutput is not supported on some browsers. See [setSinkId](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId#browser_compatibility) * * @param kind use `videoinput` for camera track, * `audioinput` for microphone track, * `audiooutput` to set speaker for all incoming audio tracks * @param deviceId */ switchActiveDevice(kind: MediaDeviceKind, deviceId: string, exact?: boolean): Promise; private setupLocalParticipantEvents; private recreateEngine; private onTrackAdded; private cancelPendingTrackAdded; private handleLocalTrackSubscribed; private emitLocalTrackSubscribed; private handleRestarting; private handleSignalRestarted; private handleDisconnect; private handleParticipantUpdates; private handleParticipantDisconnected; private handleActiveSpeakersUpdate; private handleSpeakersChanged; private handleStreamStateUpdate; private handleSubscriptionPermissionUpdate; private handleSubscriptionError; private handleDataPacket; private handleUserPacket; private handleSipDtmf; private handleTranscription; private handleMetrics; bufferedSegments: Map; private handleAudioPlaybackStarted; private handleAudioPlaybackFailed; private handleVideoPlaybackStarted; private handleVideoPlaybackFailed; /** * attempt to select the default devices if the previously selected devices are no longer available after a device change event */ private selectDefaultDevices; private handleDeviceChange; private handleRoomUpdate; private handleConnectionQualityUpdate; /** * @param forConnect whether this acquisition belongs to a connect, which is the only caller * allowed to put a released room back on an audio context. */ private acquireAudioContext; /** * Points the room and its participants at `audioContext`, rebuilding the web audio graph of * every audio track in it. Closes the previous context if the SDK `owned` it. */ private setRoomAudioContext; /** * Detaches the web audio graph the SDK built from the current audio context and closes that * context if the SDK created it. A context provided through `webAudioMix` is left untouched. */ private releaseAudioContext; private createParticipant; private getOrCreateParticipant; private sendSyncState; /** * After resuming, we'll need to notify the server of the current * subscription settings. */ private updateSubscriptions; private getRemoteParticipantBySid; /** The client capabilities this SDK advertises to other participants in its `ClientInfo`. */ private getClientInfoCapabilities; private setStatsLogging; /** * Dumps stats of both peer connections. */ private logWebRTCStats; private registerConnectionReconcile; private clearConnectionReconcile; private setAndEmitConnectionState; private emitBufferedEvents; private emitWhenConnected; private onLocalParticipantMetadataChanged; private onLocalParticipantNameChanged; private onLocalAttributesChanged; private onLocalTrackMuted; private onLocalTrackUnmuted; private onTrackProcessorUpdate; private onLocalTrackPublished; private onLocalTrackUnpublished; private onLocalTrackRestarted; private onLocalConnectionQualityChanged; private onMediaDevicesError; private onLocalParticipantPermissionsChanged; /** Puts the room into the connected state without a server (`ExtensionContext.simulateConnected`). */ private simulateConnected; emit(event: E, ...args: Parameters): boolean; } export default CoreRoom; export type RoomEventCallbacks = { connected: () => void; reconnecting: () => void; signalReconnecting: () => void; reconnected: () => void; disconnected: (reason?: DisconnectReason) => void; connectionStateChanged: (state: ConnectionState) => void; moved: (name: string) => void; mediaDevicesChanged: () => void; participantConnected: (participant: RemoteParticipant) => void; participantDisconnected: (participant: RemoteParticipant, disconnectReason?: DisconnectReason) => void; trackPublished: (publication: RemoteTrackPublication, participant: RemoteParticipant) => void; trackSubscribed: (track: RemoteTrack, publication: RemoteTrackPublication, participant: RemoteParticipant) => void; trackSubscriptionFailed: (trackSid: string, participant: RemoteParticipant, reason?: SubscriptionError) => void; trackUnpublished: (publication: RemoteTrackPublication, participant: RemoteParticipant) => void; trackUnsubscribed: (track: RemoteTrack, publication: RemoteTrackPublication, participant: RemoteParticipant) => void; trackMuted: (publication: TrackPublication, participant: Participant) => void; trackUnmuted: (publication: TrackPublication, participant: Participant) => void; localTrackPublished: (publication: LocalTrackPublication, participant: LocalParticipant) => void; localTrackUnpublished: (publication: LocalTrackPublication, participant: LocalParticipant) => void; localAudioSilenceDetected: (publication: LocalTrackPublication) => void; participantMetadataChanged: (metadata: string | undefined, participant: RemoteParticipant | LocalParticipant) => void; participantNameChanged: (name: string, participant: RemoteParticipant | LocalParticipant) => void; participantPermissionsChanged: (prevPermissions: ParticipantPermission | undefined, participant: RemoteParticipant | LocalParticipant) => void; participantAttributesChanged: (changedAttributes: Record, participant: RemoteParticipant | LocalParticipant) => void; activeSpeakersChanged: (speakers: Array) => void; roomMetadataChanged: (metadata: string) => void; dataReceived: (payload: NonSharedUint8Array, participant?: RemoteParticipant, kind?: DataPacket_Kind, topic?: string, encryptionType?: Encryption_Type, participantIdentity?: string) => void; sipDTMFReceived: (dtmf: SipDTMF, participant?: RemoteParticipant) => void; /** @deprecated Use a text stream handler for the `lk.transcription` topic instead. */ transcriptionReceived: (transcription: TranscriptionSegment[], participant?: Participant, publication?: TrackPublication) => void; connectionQualityChanged: (quality: ConnectionQuality, participant: Participant) => void; mediaDevicesError: (error: Error, kind?: MediaDeviceKind) => void; trackStreamStateChanged: (publication: RemoteTrackPublication, streamState: Track.StreamState, participant: RemoteParticipant) => void; trackSubscriptionPermissionChanged: (publication: RemoteTrackPublication, status: TrackPublication.PermissionStatus, participant: RemoteParticipant) => void; trackSubscriptionStatusChanged: (publication: RemoteTrackPublication, status: TrackPublication.SubscriptionStatus, participant: RemoteParticipant) => void; audioPlaybackChanged: (playing: boolean) => void; videoPlaybackChanged: (playing: boolean) => void; signalConnected: () => void; recordingStatusChanged: (recording: boolean) => void; participantEncryptionStatusChanged: (encrypted: boolean, participant?: Participant) => void; encryptionError: (error: Error, participant?: Participant) => void; dcBufferStatusChanged: (isLow: boolean, kind: DataChannelKind) => void; activeDeviceChanged: (kind: MediaDeviceKind, deviceId: string) => void; chatMessage: (message: ChatMessage, participant?: RemoteParticipant | LocalParticipant) => void; localTrackSubscribed: (publication: LocalTrackPublication, participant: LocalParticipant) => void; metricsReceived: (metrics: MetricsBatch, participant?: Participant) => void; participantActive: (participant: Participant) => void; dataTrackPublished: (track: RemoteDataTrack) => void; dataTrackUnpublished: (sid: DataTrackSid) => void; localDataTrackPublished: (track: LocalDataTrack) => void; localDataTrackUnpublished: (sid: DataTrackSid) => void; }; //# sourceMappingURL=CoreRoom.d.ts.map