import { type Connection, Proc } from "./core"; /** * Takes the procedure's input data and a socket object. * The `connection` represents a link to the server. */ export type ClientProcHandler = (input: I, connection: Connection) => O | Promise; export interface ClientConfig { /** * Chatter server URL. */ url: string | URL; /** * Enables extra logging when true. */ verbose?: boolean; /** * Number of seconds to wait after the most recent message was received before sending a ping message. * Pings are used to keep the connection alive and check that we can communicate with the server. * Default is 30 seconds. */ pingInterval?: number; } export declare enum ConnectionState { /** * The initial state. No active connection to the server. */ Disconnected = 0, /** * A connection is being established. No active connection yet. */ Connecting = 1, /** * Server connection is active and ready to send and receive. */ Connected = 2, /** * Connection liveness needs to be checked and possibly reconnected. */ Unknown = 3 } export declare function createClient(config: ClientConfig): ChatterClient; declare class ChatterClient implements Connection { #private; constructor(config: ClientConfig); /** * The current connection state. */ get state(): ConnectionState; /** * Persistent client ID. Stored in localStorage to persist between sessions. */ get clientId(): string; /** * Ephemeral session ID. Regenerated each time the page is loaded. */ get sessionId(): string; /** * True when the socket is open and ready. */ get isConnected(): boolean; /** * Registers a callback to run when the `state` value changes. * Returns a function that stops listening for changes. */ onStateChange(callback: (state: ConnectionState) => void): () => void; /** * Implements a `Proc` so it can be called from the other end of the connection. */ on(proc: Proc, handler: ClientProcHandler): void; call(proc: Proc): Promise; call(proc: Proc, input: null): Promise; call(proc: Proc, input: I): Promise; } export {};