UNPKG

@voxket-ai/voxket-live

Version:

A React widget for embedding Voxket-powered audio/video/chat experiences.

94 lines (93 loc) 2.96 kB
import { Room, ConnectionState } from 'livekit-client'; import { VoxketEventEmitter } from './event-emitter'; import { VoxketEvents, AgentInfo, ParticipantInfo, ModalityValue } from '../types/core'; export interface ConnectionConfig { baseUrl: string; appId?: string; appSecret?: string; authToken?: string; /** When set, fetchConnectionDetails() calls the join endpoint for this session ID */ sessionId?: string; } /** * ConnectionManager * * Manages all connection-related functionality including: * - Room connection and disconnection * - Connection state management * - Participant tracking * - Connection details fetching * - Room event handling */ export declare class ConnectionManager { private room; private config; private eventEmitter; private connectionState; private isConnected; private currentAgentInfo; constructor(config: ConnectionConfig, eventEmitter: VoxketEventEmitter<VoxketEvents>); /** * Initialize or reinitialize the room */ private initializeRoom; /** * Setup event listeners for the room */ private setupRoomEventListeners; addConsentLog(consentVersion: string, consentType: stirng, modalities: ModalityValue[], agentId: string, participantName: any): Promise<any>; /** * Fetch connection details from the server. * * Two paths: * 1. Join existing session — when `this.config.sessionId` is set: * POST /api/live/sessions/{sessionId}/join → { token, wss_url, session_id } * 2. Create new session — default path: * POST /api/live/agent/session → { token, wss_url, session_id, agent_info } */ fetchConnectionDetails(agentId: string, participantName: string, modalities: ModalityValue[], participantMetadata?: Record<string, any>): Promise<{ serverUrl: string; participantToken: string; voxketSessionId: string; agentInfo?: AgentInfo; isHumanHandled?: boolean; }>; /** * Connect to the room */ connect(agentId: string, participantName: string, modalities: ModalityValue[], participantMetadata?: Record<string, any>): Promise<{ serverUrl: string; participantToken: string; voxketSessionId: string; agentInfo?: AgentInfo; isHumanHandled?: boolean; }>; /** * Disconnect from the room */ disconnect(): Promise<void>; /** * Get the current room instance */ getRoom(): Room | null; /** * Get the connection state */ getConnectionState(): ConnectionState; /** * Check if connected */ get connected(): boolean; /** * Get current agent info */ getCurrentAgentInfo(): AgentInfo | null; /** * Get all participants */ getParticipants(): ParticipantInfo[]; /** * Update configuration */ updateConfig(updates: Partial<ConnectionConfig>): void; }