import { ConnectionQuality } from 'livekit-client'; import { AvatarStreamError } from './error'; /** * Represents transcription data received from the LiveKit room */ export interface TranscriptionData { message_type: 'ai' | 'human'; content: string; } /** * Configuration options for audio handling */ interface AudioConfig { /** Called when audio playback starts */ onPlaying?: () => void; /** Called when audio playback pauses */ onPause?: () => void; /** Called when audio playback ends */ onEnded?: () => void; /** Called when audio playback resumes after a pause */ onResumed?: () => void; /** Enable debug mode for additional logging */ isDebug?: boolean; } /** * Configuration options for the LiveKit client */ interface LiveKitClientConfig { /** Audio configuration options */ audioConfig?: AudioConfig; /** Error handler callback */ onError?: (error: AvatarStreamError) => 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; /** Called when reconnection attempts start */ onReconnecting?: () => void; /** Called when successfully reconnected */ onReconnected?: () => void; } /** * Manages connection to a LiveKit room and handles audio streaming */ export declare class LiveKitClient { private room; private audioHandler; private onTranscriptionUpdate; private reconnectTimeout; private readonly state; private readonly config; /** * Creates a new LiveKit client * @param config Configuration options */ constructor(config?: LiveKitClientConfig); /** * Gets the default room options for LiveKit * @returns RoomOptions configuration */ private static getRoomOptions; /** * Initializes the LiveKit room connection * @param url LiveKit server URL * @param token Authentication token * @returns Promise resolving to true if connection was successful */ init(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; /** * Attaches an audio track to the audio handler * @param track The remote track to attach * @private */ private attachAudioTrack; /** * Handles audio errors by attempting recovery * @private */ private handleAudioError; /** * Finds the first available audio track in the room * @returns The first available audio track, or null if none found * @private */ private findFirstAvailableAudioTrack; /** * 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 disconnection events * @param reason The reason for disconnection * @private */ private handleDisconnect; /** * Schedules a reconnection attempt with exponential backoff * @private */ private scheduleReconnect; /** * Parses transcription data from a JSON string * @param jsonString The JSON string to parse * @returns The parsed data, or null if parsing failed * @private */ private parseTranscriptionData; /** * Validates that data is a valid TranscriptionData object * @param data The data to validate * @returns Type guard for TranscriptionData * @private */ private isValidTranscriptionData; /** * Handles data received events * @param payload The data payload received * @private */ private handleDataReceived; /** * Emits a custom event * @param event The event name * @param data The event data * @private */ private emit; /** * Removes all tracks from the peer connection * This is a cleanup method to ensure proper resource release * @private */ private removeAllTracksFromPeerConnection; /** * Disconnects from the LiveKit room and cleans up resources * @returns Promise that resolves when disconnection is complete */ disconnect(): Promise; /** * Pauses audio playback */ pause(): Promise; /** * Resumes audio playback * @throws Error if playback cannot be resumed */ resume(): Promise; /** * Stops audio playback and cleans up resources without disconnecting */ stop(): Promise; /** * Sets a callback to receive transcription updates * @param callback The callback function */ setTranscriptionCallback(callback: (data: TranscriptionData) => void): void; /** * Initiates audio playback in response to a user gesture * This is needed to work around browser autoplay restrictions * @throws Error if playback cannot be initiated */ userInitiatedPlay(): Promise; /** * Checks if the client is connected to the LiveKit room * @returns True if connected, false otherwise */ isConnected(): boolean; /** * Checks if the client is currently attempting to reconnect * @returns True if reconnecting, false otherwise */ isReconnectingState(): boolean; /** * Gets the current connection quality * @returns The connection quality, or null if not connected */ getConnectionQuality(): ConnectionQuality | null; } export {};