import { Websocket } from "./websocket"; /** * Events that can be fired by the websocket. */ export declare const WebsocketEvent: { /** Fired when the connection is opened. */ readonly open: "open"; /** Fired when the connection is closed. */ readonly close: "close"; /** Fired when the connection has been closed because of an error, such as when some data couldn't be sent. */ readonly error: "error"; /** Fired when a message is received. */ readonly message: "message"; /** Fired when the websocket tries to reconnect after a connection loss. */ readonly retry: "retry"; /** Fired when the websocket successfully reconnects after a connection loss. */ readonly reconnect: "reconnect"; }; /** Union of all event type strings, allowing plain strings like "open" as event types. */ export type WebsocketEvent = (typeof WebsocketEvent)[keyof typeof WebsocketEvent]; /** Provides member types (e.g. WebsocketEvent.open) for use as generic type arguments. */ export declare namespace WebsocketEvent { type open = typeof WebsocketEvent.open; type close = typeof WebsocketEvent.close; type error = typeof WebsocketEvent.error; type message = typeof WebsocketEvent.message; type retry = typeof WebsocketEvent.retry; type reconnect = typeof WebsocketEvent.reconnect; } /*** * Details/properties of a retry-event. */ export type RetryEventDetail = { /** Number of retries that have been made since the connection was lost. */ readonly retries: number; /** Time (ms) waited since the last connection-retry. */ readonly backoff: number; /** Timestamp of when the connection was lost or undefined if the connection has never been established. */ readonly lastConnection: Date | undefined; }; /** * Properties of a reconnect-event. */ export type ReconnectEventDetail = Omit; /** * Maps websocket events to their corresponding event. */ export type WebsocketEventMap = { [WebsocketEvent.open]: Event; [WebsocketEvent.close]: CloseEvent; [WebsocketEvent.error]: Event; [WebsocketEvent.message]: MessageEvent; [WebsocketEvent.retry]: CustomEvent; [WebsocketEvent.reconnect]: CustomEvent; }; /** * Listener for websocket events. * */ export type WebsocketEventListener = (instance: Websocket, ev: WebsocketEventMap[K]) => unknown; export type WebsocketEventListenerParams = Parameters>; /** * Options for websocket events. */ export type WebsocketEventListenerOptions = EventListenerOptions & AddEventListenerOptions; /** * Listener for websocket events with options. */ export type WebsocketEventListenerWithOptions = { readonly listener: WebsocketEventListener; readonly options?: WebsocketEventListenerOptions; }; /** * Maps websocket events to their corresponding event-listeners. */ export type WebsocketEventListeners = { [K in WebsocketEvent]: WebsocketEventListenerWithOptions[]; }; //# sourceMappingURL=websocket_event.d.ts.map