import { AddTrackRequest, AudioTrackFeature, ConnectionQualityUpdate, DataTrackSubscriberHandles, JoinResponse, LeaveRequest, MediaSectionsRequirement, ParticipantInfo, PublishDataTrackResponse, ReconnectReason, ReconnectResponse, RequestResponse, Room, RoomMovedResponse, SessionDescription, SignalResponse, SignalTarget, SimulateScenario, SpeakerInfo, StreamStateUpdate, SubscribedQualityUpdate, SubscriptionPermissionUpdate, SubscriptionResponse, SyncState, TrackPermission, TrackPublishedResponse, TrackUnpublishedResponse, UnpublishDataTrackResponse, UpdateSubscription, UpdateTrackSettings, VideoLayer } from '@livekit/protocol'; import type { DataTrackHandle } from '../room/data-track/handle'; import { type DataTrackSid } from '../room/data-track/types'; import type { LoggerOptions } from '../room/types'; import { AsyncQueue } from '../utils/AsyncQueue'; import { WebSocketStream } from './WebSocketStream'; interface ConnectOpts extends SignalOptions { /** internal */ reconnect?: boolean; /** internal */ reconnectReason?: number; /** internal */ sid?: string; } export interface SignalOptions { autoSubscribe: boolean; adaptiveStream?: boolean; maxRetries: number; e2eeEnabled: boolean; websocketTimeout: number; } export declare enum SignalConnectionState { CONNECTING = 0, CONNECTED = 1, RECONNECTING = 2, DISCONNECTING = 3, DISCONNECTED = 4 } /** @internal */ export declare class SignalClient { requestQueue: AsyncQueue; queuedRequests: Array<() => Promise>; useJSON: boolean; /** signal rtt in milliseconds */ rtt: number; /** simulate signaling latency by delaying messages */ signalLatency?: number; onClose?: (reason: string) => void; onAnswer?: (sd: RTCSessionDescriptionInit, offerId: number, midToTrackId: { [key: string]: string; }) => void; onOffer?: (sd: RTCSessionDescriptionInit, offerId: number, midToTrackId: { [key: string]: string; }) => void; onTrickle?: (sd: RTCIceCandidateInit, target: SignalTarget) => void; onParticipantUpdate?: (updates: ParticipantInfo[]) => void; onLocalTrackPublished?: (res: TrackPublishedResponse) => void; onNegotiateRequested?: () => void; onSpeakersChanged?: (res: SpeakerInfo[]) => void; onRemoteMuteChanged?: (trackSid: string, muted: boolean) => void; onRoomUpdate?: (room: Room) => void; onConnectionQuality?: (update: ConnectionQualityUpdate) => void; onStreamStateUpdate?: (update: StreamStateUpdate) => void; onSubscribedQualityUpdate?: (update: SubscribedQualityUpdate) => void; onSubscriptionPermissionUpdate?: (update: SubscriptionPermissionUpdate) => void; onSubscriptionError?: (update: SubscriptionResponse) => void; onLocalTrackUnpublished?: (res: TrackUnpublishedResponse) => void; onTokenRefresh?: (token: string) => void; onLeave?: (leave: LeaveRequest) => void; onRequestResponse?: (response: RequestResponse) => void; onLocalTrackSubscribed?: (trackSid: string) => void; onRoomMoved?: (res: RoomMovedResponse) => void; onMediaSectionsRequirement?: (requirement: MediaSectionsRequirement) => void; onPublishDataTrackResponse?: (event: PublishDataTrackResponse) => void; onUnPublishDataTrackResponse?: (event: UnpublishDataTrackResponse) => void; onDataTrackSubscriberHandles?: (event: DataTrackSubscriberHandles) => void; onJoined?: (event: JoinResponse) => void; connectOptions?: ConnectOpts; ws?: WebSocketStream; get currentState(): SignalConnectionState; get isDisconnected(): boolean; private get isEstablishingConnection(); private getNextRequestId; private options?; private pingTimeout; private pingTimeoutDuration; private pingIntervalDuration; private pingInterval; private closingLock; private state; private connectionLock; private log; private loggerContextCb?; private _requestId; private streamWriter; private useV0SignalPath; constructor(useJSON?: boolean, loggerOptions?: LoggerOptions); private get logContext(); join(url: string, token: string, opts: SignalOptions, abortSignal?: AbortSignal, useV0Path?: boolean, publisherOffer?: SessionDescription): Promise; reconnect(url: string, token: string, sid?: string, reason?: ReconnectReason): Promise; private connect; startReadingLoop(signalReader: ReadableStreamDefaultReader, firstMessage?: SignalResponse): Promise; /** @internal */ resetCallbacks: () => void; close(updateState?: boolean, reason?: string): Promise; sendOffer(offer: RTCSessionDescriptionInit, offerId: number): void; sendAnswer(answer: RTCSessionDescriptionInit, offerId: number): Promise; sendIceCandidate(candidate: RTCIceCandidateInit, target: SignalTarget): Promise; sendMuteTrack(trackSid: string, muted: boolean): Promise; sendAddTrack(req: AddTrackRequest): Promise; sendUpdateLocalMetadata(metadata: string, name: string, attributes?: Record): Promise; sendUpdateTrackSettings(settings: UpdateTrackSettings): void; sendUpdateSubscription(sub: UpdateSubscription): Promise; sendSyncState(sync: SyncState): Promise; sendUpdateVideoLayers(trackSid: string, layers: VideoLayer[]): Promise; sendUpdateSubscriptionPermissions(allParticipants: boolean, trackPermissions: TrackPermission[]): Promise; sendSimulateScenario(scenario: SimulateScenario): Promise; sendPing(): Promise<[void, void]>; sendUpdateLocalAudioTrack(trackSid: string, features: AudioTrackFeature[]): Promise; sendLeave(): Promise; sendPublishDataTrackRequest(handle: DataTrackHandle, name: string, usesE2ee: boolean): Promise; sendUnPublishDataTrackRequest(handle: DataTrackHandle): Promise; sendUpdateDataSubscription(sid: DataTrackSid, subscribe: boolean): Promise; private sendRequest; private handleSignalResponse; setReconnected(): void; private handleOnClose; private handleWSError; /** * Resets the ping timeout and starts a new timeout. * Call this after receiving a pong message */ private resetPingTimeout; /** * Clears ping timeout (does not start a new timeout) */ private clearPingTimeout; private startPingInterval; private clearPingInterval; /** * Handles the successful connection to the signal server * @param connection The WebSocket connection * @param timeoutHandle The timeout handle to clear * @param firstMessage Optional first message to process * @internal */ private handleSignalConnected; /** * Validates the first message received from the signal server * @param firstSignalResponse The first signal response received * @param isReconnect Whether this is a reconnection attempt * @returns Validation result with response or error * @internal */ private validateFirstMessage; /** * Handles WebSocket connection errors by validating with the server * @param reason The error that occurred * @param validateUrl The URL to validate the connection with * @returns A ConnectionError with appropriate reason and status * @internal */ private handleConnectionError; } export declare function toProtoSessionDescription(rsd: RTCSessionDescription | RTCSessionDescriptionInit, id?: number): SessionDescription; export {}; //# sourceMappingURL=SignalClient.d.ts.map