export interface WsReconnectOptions { /** Wait before each attempt, in ms, or a function of the attempt number (0 first). Defaults to 2000. */ delay?: number | ((attempt: number) => number); /** Attempts in a row before giving up; a successful open resets the count. Defaults to no limit. */ attempts?: number; } export type WsFrame = Parameters[0]; export interface WsClientOptions { /** Path on the page's own host, `ws:` or `wss:` following the page. Needed unless `url` is set. */ path?: string; /** Full socket URL, or a function read at each (re)connect; wins over `path`. */ url?: string | (() => string); protocols?: string | string[]; /** Message sent on open. Return null to skip auth and become ready immediately (guest). */ authMessage?: () => object | null; /** The `type` of the server's reply that ends the auth handshake. Defaults to `authed`. */ readyType?: string; /** Fired once ready: after the server replies with `readyType`, or immediately when there is no auth. */ onReady?: () => void; onMessage: (msg: TMsg) => void; onError?: (event: Event) => void; /** Fired for a frame `parse` rejects; the frame is dropped and the client keeps running, silently when this is unset. */ onInvalidMessage?: (data: unknown, error: unknown) => void; onClose?: (event: CloseEvent) => void; /** Reads an incoming frame, throwing on a bad one. Defaults to JSON, which must be an object. */ parse?: (data: unknown) => TMsg; /** Writes an outgoing message. Defaults to `JSON.stringify`. */ serialize?: (data: object) => WsFrame; /** Auto-reconnect after a drop: `true` waits 2s, a number that many ms, or a backoff. Off by default (a game socket needs a full rejoin, not a silent reconnect). */ reconnect?: boolean | number | WsReconnectOptions; } export interface WsClient { send: (data: object) => void; ready: () => boolean; close: () => void; } /** Shared WS transport: URL, socket lifecycle, encode/decode (JSON by default), auth handshake, send-queue. */ export declare function createWsClient(opts: WsClientOptions): WsClient; //# sourceMappingURL=wsClient.d.ts.map