import { EventEmitter } from "eventemitter3"; import { AvatarSDK } from "./AvatarSDK"; import { AvatarSessionConfig, AvatarSessionState, RenderMode, AvatarSessionEvents } from "../types"; /** * AvatarSession class manages the lifecycle of an avatar session * * @note Use `AvatarSDK.createSession()` to create an instance instead of using the constructor directly. * @warning Once the session ends (either normally or due to an error), the session object becomes invalid * and cannot be reused. To start a new session, you must create a new AvatarSession instance * using `AvatarSDK.createSession()`. All resources are automatically cleaned up when the session ends. */ export declare class AvatarSession extends EventEmitter { private readonly _config; private readonly _avatarSDK; private _connection; private _protocol; private _state; private _rtcService; private _webRecorder; private readonly _localSessionId; private _sessionId; /** * Create AvatarSession instance * @param config - Session configuration * @param avatarSDK - AvatarSDK instance */ constructor(config: AvatarSessionConfig, avatarSDK: AvatarSDK); /** Current state of the session */ get state(): AvatarSessionState; /** Local session identifier */ get localSessionId(): string; /** * Start the avatar session * @returns Promise that resolves when the session starts * @note If the session is already starting or started, this method will ignore the request */ start(): Promise; /** * End the avatar session * @returns Promise that resolves when the session ends * @note If the session is already idle, ending, or ended, this method will ignore the request * @warning After calling this method, the session object becomes invalid and cannot be reused. * All resources (WebRecorder, RTCService, Connection) will be automatically cleaned up. * The 'end' event will be emitted before cleanup. To start a new session, create a new * AvatarSession instance using `AvatarSDK.createSession()`. */ end(): Promise; /** * Set avatar video canvas * @param container - HTMLDivElement to render avatar video. Pass null to unset the canvas. * @param mode - Render mode */ setAvatarVideoCanvas(container: HTMLDivElement | null, mode: RenderMode): void; /** * Start local microphone recording * @returns Promise that resolves when audio capture starts successfully * @throws Error if session is not started or audio capture fails to start * @note Audio format: mono channel, 16000Hz sample rate, int16 sample format, little-endian byte order */ startAudioCapture(): Promise; /** * Stop local microphone recording * @returns Promise that resolves when audio capture stops successfully * @throws Error if audio capture fails to stop */ stopAudioCapture(): Promise; /** Destroy the session and release all resources */ destroy(): void; private _generateUUID; private _buildEventParams; private _trackEvent; private _sendCreateSessionMessage; private _sendEndSessionMessage; private _sendAudioData; private _generateServerConfig; private _onConnectionOpen; private _onConnectionError; private _onConnectionClose; private _onConnectionMessage; private _startRTCService; private _onRTCReady; private _onRTCError; private _onAudioCaptureStart; private _onAudioCaptureStop; private _onAudioCaptureFail; private _onAudioFrame; private _bytesToHex; private _handleSessionError; }