import type { WsConnectionStatus, WsStatusListener } from './types.js'; type WsEventMap = { open: () => void; close: (code: number, reason: string) => void; error: (error: Event) => void; message: (data: string) => void; }; type WsEvent = keyof WsEventMap; /** * Options for {@link ReconnectingWebSocket}. * * @public */ export interface ReconnectingWebSocketOptions { maxRetries?: number; pingIntervalMs?: number; /** * Keepalive frame sent every `pingIntervalMs` while the socket is open. * Framing is venue-specific, so when omitted no keepalive is sent. */ pingPayload?: string; /** * Stale-stream watchdog window. With `pingPayload` configured, the socket is * force-reconnected when no inbound frame arrives within this window. * Defaults to 3× `pingIntervalMs`. */ staleWindowMs?: number; } /** * A `WebSocket` transport that auto-reconnects with jittered exponential * backoff (`partysocket` internals), buffers sends (bounded) while * disconnected, keepalive-pings with the caller-supplied `pingPayload`, and * force-reconnects a silently stale stream. Surfaces the * {@link WsConnectionStatus} state machine: `reconnecting` on transient drops, * terminal `disconnected` once the retry budget is exhausted. * * @public */ export declare class ReconnectingWebSocket { private readonly socket; private readonly maxRetries; private readonly pingIntervalMs; private readonly pingPayload; private readonly staleWindowMs; private closed; private reconnectRequested; private lastCloseRetryCount; private pingTimer; private staleTimer; private listeners; private statusListeners; private status; private readyResolvers; constructor(url: string, options?: ReconnectingWebSocketOptions); private handleOpen; private handleClose; private handleError; private handleMessage; private setStatus; private callListener; private startPing; private stopPing; private armWatchdog; private clearWatchdog; /** * Send `data`, buffering it (bounded) for replay when the socket is not yet * open. * * @public */ send(data: string): void; /** * Permanently close the socket and suppress further reconnection. * * @public */ close(): void; /** * Drop the current connection (if any) and reconnect with a fresh retry * budget. Recovers a socket that reached terminal `disconnected`: status * returns to `reconnecting` and the normal backoff cycle restarts. * * @public */ reconnect(): void; /** * Register a listener for a socket lifecycle event. * * @public */ on(event: E, fn: WsEventMap[E]): void; /** * Remove a previously registered lifecycle-event listener. * * @public */ off(event: E, fn: WsEventMap[E]): void; /** * Current connection health. `reconnecting` until the first open; * `disconnected` once auto-reconnect is abandoned (terminal until * {@link ReconnectingWebSocket.reconnect} is called). * * @public */ getStatus(): WsConnectionStatus; /** * Register a connection-health listener. Fires on every status transition, * including the terminal `disconnected` emitted on reconnect exhaustion. * * @public */ onStatus(fn: WsStatusListener): void; /** * Remove a previously registered connection-health listener. * * @public */ offStatus(fn: WsStatusListener): void; /** * Resolve once the socket is open; reject if it closes or exhausts retries * before opening. When the socket is already terminally dead — `close()`d or * reconnect-exhausted (`disconnected`) — rejects immediately rather than * queuing a waiter nothing would ever settle. * * @public */ ready(): Promise; } export {}; //# sourceMappingURL=ReconnectingWebSocket.d.ts.map