import { Participant, RemoteTrack, Room } from 'livekit-client'; import { Logger } from './logger'; import { AvatarStreamError } from './error'; import { ConnectionState } from './connection-state-machine'; /** * Configuration for the room manager */ export interface RoomManagerConfig { /** Logger instance */ logger?: Logger; /** Error handler callback */ onError?: (error: AvatarStreamError) => void; /** Called when track is subscribed */ onTrackSubscribed?: (track: RemoteTrack) => void; /** Called when track is unsubscribed */ onTrackUnsubscribed?: (track: RemoteTrack) => void; /** Called when active speakers change */ onActiveSpeakersChanged?: (speakers: Participant[]) => void; /** Called when data is received */ onDataReceived?: (payload: Uint8Array) => void; /** Called when reconnecting */ onReconnecting?: () => void; /** Called when reconnected */ onReconnected?: () => void; /** Whether to automatically attempt reconnection on unexpected disconnects */ autoReconnect?: boolean; /** Maximum number of reconnection attempts */ maxReconnectAttempts?: number; /** Base interval between reconnection attempts (will increase with backoff) */ reconnectInterval?: number; } /** * Manages LiveKit room connection, events, and reconnection */ export declare class RoomManager { private room; private logger; private stateMachine; private reconnectTimeout; private state; private config; /** * Creates a new room manager * @param config Configuration options */ constructor(config?: RoomManagerConfig); /** * Sets up handlers for state transitions * @private */ private setupStateTransitionHandlers; /** * Gets the default room options for LiveKit * @returns RoomOptions configuration */ private static getRoomOptions; /** * Connects to a LiveKit room * @param url LiveKit server URL * @param token Authentication token * @returns Promise resolving to true if connection was successful */ connect(url: string, token: string): Promise; /** * Disables local participant's media to save bandwidth * @private */ private disableLocalParticipantMedia; /** * Sets up event listeners for the LiveKit room * @private */ private setupEventListeners; /** * Handles media device errors * @param error The error that occurred * @private */ private handleDeviceError; /** * Handles the reconnecting event from LiveKit * @private */ private handleReconnecting; /** * Handles the reconnected event from LiveKit * @private */ private handleReconnected; /** * Handles track subscription events * @param track The remote track that was subscribed to * @private */ private handleTrackSubscribed; /** * Handles track unsubscription events * @param track The remote track that was unsubscribed * @private */ private handleTrackUnsubscribed; /** * Handles local track unpublication events * @param publication The local track publication that was unpublished * @private */ private handleLocalTrackUnpublished; /** * Handles active speaker change events * @param speakers The new active speakers * @private */ private handleActiveSpeakerChange; /** * Handles data received events * @param payload The data payload received * @private */ private handleDataReceived; /** * Handles disconnection events * @param reason The reason for disconnection * @private */ private handleDisconnect; /** * Schedules a reconnection attempt with exponential backoff * @private */ private scheduleReconnect; /** * Finds the first available audio track in the room * @returns The first available audio track, or null if none found */ findFirstAvailableAudioTrack(): RemoteTrack | null; /** * Disconnects from the LiveKit room and cleans up resources * @returns Promise that resolves when disconnection is complete */ disconnect(): Promise; /** * Stops all tracks without disconnecting from the room */ stopTracks(): Promise; /** * Checks if connected to a LiveKit room * @returns True if connected */ isConnected(): boolean; /** * Checks if currently reconnecting * @returns True if reconnecting */ isReconnecting(): boolean; /** * Gets the current connection state * @returns The current connection state */ getConnectionState(): ConnectionState; /** * Gets the LiveKit room instance * @returns The LiveKit room instance, or null if not connected */ getRoom(): Room | null; }