UNPKG

@sayna-ai/js-sdk

Version:

Browser SDK for connecting Sayna clients to real-time voice rooms.

65 lines 2.03 kB
import { Room } from "livekit-client"; import type { AudioCaptureOptions } from "livekit-client"; /** * Token payload returned by Sayna's API. * Must include the access token and the room URL (liveUrl). */ export interface TokenResponse { token: string; liveUrl: string; [key: string]: unknown; } export interface SaynaClientOptions { tokenUrl?: string | URL; tokenFetchHandler?: () => Promise<TokenResponse>; audioElement?: HTMLAudioElement; enableAudioPlayback?: boolean; } /** * SaynaClient wraps LiveKit client logic for browser usage. */ export declare class SaynaClient { private readonly options; private room; private readonly enableAudioPlayback; private isConnecting; private audioElement; private createdAudioElement; private readonly attachedAudioTracks; private readonly handleTrackSubscribed; private readonly handleTrackUnsubscribed; private readonly handleRoomDisconnected; constructor(options: SaynaClientOptions); /** * Returns the underlying LiveKit room instance if connected. */ get currentRoom(): Room | null; /** * Returns true when the client is connected to LiveKit. */ get isConnected(): boolean; /** * Returns the HTMLAudioElement used for remote playback, if any. */ get playbackElement(): HTMLAudioElement | null; /** * Fetches a token (if needed), connects to LiveKit and resolves to the Room instance. */ connect(): Promise<Room>; /** * Enables the microphone and publishes audio track to the room. */ publishMicrophone(options?: AudioCaptureOptions): Promise<void>; /** * Disconnects from the room and cleans up local resources. */ disconnect(): Promise<void>; private resolveToken; private ensureAudioElement; private detachAllTracks; private safeDisconnect; private requireConnectedRoom; private toAbsoluteUrl; private assertBrowserEnvironment; } //# sourceMappingURL=index.d.ts.map