///
import EventEmitter from 'events';
import WebSocket from 'isomorphic-ws';
import { WebsocketClientOptions, WSClientConfigurableOptions } from '../types/websockets/client.js';
import { WsOperation } from '../types/websockets/requests.js';
import { DefaultLogger } from './logger.js';
import { MessageEventLike } from './requestUtils.js';
import { WsTopicRequest, WsTopicRequestOrStringTopic } from './websocket/websocket-util.js';
import { WsStore } from './websocket/WsStore.js';
import { WSConnectedResult } from './websocket/WsStore.types.js';
interface WSClientEventMap {
/** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
open: (evt: {
wsKey: WsKey;
event: any;
}) => void;
/** Reconnecting a dropped connection */
reconnect: (evt: {
wsKey: WsKey;
event: any;
}) => void;
/** Successfully reconnected a connection that dropped */
reconnected: (evt: {
wsKey: WsKey;
event: any;
}) => void;
/** Connection closed */
close: (evt: {
wsKey: WsKey;
event: any;
}) => void;
/** Received reply to websocket command (e.g. after subscribing to topics) */
response: (response: any & {
wsKey: WsKey;
}) => void;
/** Received data for topic */
update: (response: any & {
wsKey: WsKey;
}) => void;
/** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */
exception: (response: any & {
wsKey: WsKey;
}) => void;
error: (response: any & {
wsKey: WsKey;
}) => void;
/** Confirmation that a connection successfully authenticated */
authenticated: (event: {
wsKey: WsKey;
event: any;
}) => void;
}
export interface EmittableEvent {
eventType: 'response' | 'update' | 'exception' | 'authenticated';
event: TEvent;
}
export interface BaseWebsocketClient {
on>(event: U, listener: WSClientEventMap[U]): this;
emit>(event: U, ...args: Parameters[U]>): boolean;
}
/**
* Base WebSocket abstraction layer. Handles connections, tracking each connection as a unique "WS Key"
*/
export declare abstract class BaseWebsocketClient<
/**
* The WS connections supported by the client, each identified by a unique primary key
*/
TWSKey extends string> extends EventEmitter {
/**
* State store to track a list of topics (topic requests) we are expected to be subscribed to if reconnected
*/
private wsStore;
protected logger: typeof DefaultLogger;
protected options: WebsocketClientOptions;
private wsApiRequestId;
constructor(options?: WSClientConfigurableOptions, logger?: typeof DefaultLogger);
protected abstract sendPingEvent(wsKey: TWSKey, ws: WebSocket): void;
protected abstract sendPongEvent(wsKey: TWSKey, ws: WebSocket): void;
protected abstract isWsPing(data: any): boolean;
protected abstract isWsPong(data: any): boolean;
protected abstract getWsAuthRequestEvent(wsKey: TWSKey): Promise