import { CloseEvent, ErrorEvent, Event } from 'reconnecting-websocket'; export declare enum CloseEventCode { NORMAL_CLOSURE = 1000, GOING_AWAY = 1001, PROTOCOL_ERROR = 1002, UNSUPPORTED_DATA = 1003 } export declare enum WEBSOCKET_STATE { CONNECTING = 0, OPEN = 1, CLOSING = 2, CLOSED = 3 } export declare enum PingMessage { PING = "ping", PONG = "pong" } export declare class ReconnectingWebsocket { private readonly onReconnect; private static readonly RECONNECTING_OPTIONS; private readonly logger; private socket?; private pingerId?; private readonly PING_INTERVAL; private hasUnansweredPing; private onOpen?; private onMessage?; private onError?; private onClose?; /** * Cleanup function returned by onBackFromSleep to stop the sleep detection interval. * This prevents memory leaks by ensuring the interval is cleared when the WebSocket is disconnected. */ private readonly stopBackFromSleepHandler?; private isPingingEnabled; private readonly pendingHealthChecks; private lastMessageTimestamp; constructor(onReconnect: () => Promise, options?: { pingInterval?: number; }); private readonly internalOnError; private readonly internalOnMessage; private readonly internalOnOpen; private readonly internalOnReconnect; private readonly internalOnClose; private startPinging; private stopPinging; private readonly sendPing; connect(): void; send(message: any): void; getState(): WEBSOCKET_STATE; /** * Lightweight health probe that intelligently determines connection health. * * If the WebSocket is actively processing messages (i.e., received a message within the last 5 seconds), * it considers the connection healthy without sending a ping, as message processing * indicates the connection is working properly. * * If the WebSocket is idle, it sends a ping and expects a pong within the timeout. * This approach prevents false failures during high-load scenarios where pong responses * get queued behind many other messages. * * Does not close or reconnect the socket; callers can decide how to react to failures. */ checkHealth(timeoutMs?: number): Promise; disconnect(reason?: string): void; /** * Cleans up all active intervals and timers to prevent memory leaks. * This includes: * - The ping interval (via stopPinging) * - The sleep detection interval (via stopBackFromSleepHandler) * * This method should be called whenever the WebSocket connection is terminated. */ private cleanup; private getReconnectingWebsocket; private resolvePendingHealthChecks; setOnOpen(onOpen: (event: Event) => void): void; setOnMessage(onMessage: (data: string) => void): void; setOnError(onError: (error: ErrorEvent) => void): void; setOnClose(onClose: (event: CloseEvent) => void): void; disablePinging(): void; } //# sourceMappingURL=ReconnectingWebsocket.d.ts.map