import { WsListenerService, WsListenerServiceConfig, Message, Template } from './ws-listener.service'; interface PingConfig { /** * Send ping request every `heartbeatMs` (null - disabled). */ heartbeatMs?: number; /** * Send ping request if there are no incoming messages for more than `checkAliveMs` (null - disabled). */ checkAliveMs?: number; /** * May be a string, an object or a function. */ request: Message | (() => Message | Promise); /** * May be a template or a matcher function. */ response: Template; /** * A timeout to await for the response. */ timeoutMs?: number; } interface ReconnectConfig { /** * Delay before auto reconnect (null - disabled). */ delayMs?: number; /** * Resubscribe simultaneously to all subscriptions. */ parallelResubscribe?: boolean; } export declare type Subscribe = () => void | Promise; export declare type WsServiceConfig = WsListenerServiceConfig & { ping?: PingConfig; reconnect?: ReconnectConfig; }; export declare class WsService extends WsListenerService { protected pingConf: PingConfig; protected reconnectConf: ReconnectConfig; protected isReconnectConfigured: boolean; protected heartbeatTimeoutId: ReturnType; protected checkAliveTimeoutId: ReturnType; protected subs: any[]; /** * Set to `true` on open if reconnect is configured. * Set to `false` on `close` * Check on `close` event handler */ protected shouldReconnect: boolean; constructor({ ping, reconnect, ...conf }: WsServiceConfig); protected _init(): void; open(): Promise; protected _handleMessage(event: any): Promise; protected _reconnectableClose(...args: Parameters): ReturnType; close(...args: Parameters): ReturnType; /** * Return `true` if successfully received pong, otherwise return `false`. * Throw if ping request or response in not configured. */ ping(): Promise; protected _heartbeatLoop(): void; protected _scheduleCheckAlive(): void; protected _configureAutoReconnect(): void; /** * Reopen the connection. * Restore all subscriptions (call functions previously passed to `subscribe` method). */ reconnect(): Promise; /** * Accept a function that performs a sequence of actions required to subscribe. * Call the accepted function once to subscribe. * Add the function to a list of functions to be called on `reconnect`. * Return subscribe function passed as an argument (can be used to `unsubscribe` later). */ subscribe(fn: Subscribe): Promise; /** * Remove a function from a list of functions to be called on reconnect. * A sequence of actions required to unsubscribe should be performed elsewhere. */ unsubscribe(fn: Subscribe): Promise; } export {};