import { QuoteRequestDto } from '../restApi'; export declare type JSONRPCID = string | number | null; export declare type JSONRPCParams = Record | unknown[]; export declare type JSONRPCRequest = { jsonrpc: '2.0'; method: string; params?: JSONRPCParams; id: JSONRPCID; }; interface WSEventHandlers { onReply?: (data: any) => void; onReconnecting?: (data: any) => void; onReconnected?: (data: any) => void; onError?: (data: any) => void; onMessage?: (channelName: string, data: any) => void; onClose?: () => void; onOpen?: (retriesAttempted: number, channelsSubscribed: number) => void; } export interface IRollaWSOptions { /** * Websocket connection URL */ wsUrl: string; /** * Authorization information */ authorization: string; /** * If specified it will try to reconnect `retryCount` times at an interval of `retryInterval` ms. */ retryCount?: number; /** * Retry interval. Defaults to 3000ms (3 seconds). In order for this to take effect `retryCount` also needs to be specified. */ retryInterval?: number; /** * If this should run in debug mode, additional logging will be emitted */ debugMode?: boolean; logger?: any; eventHandlers?: WSEventHandlers; } /** * Library for managing websocket connections for Rolla. * Todo: a big task for this is to unit test it */ export declare class RollaWS { private options; /** * Core WS connection used to communicate */ private socket?; /** * Mapping between channels and callbacks that should respond to new messages from a channel */ private channelListeners; /** * The setInterval instance of the retry count feature */ private retryIntervalInstance?; /** * Global retry count counter, this needs to be reset whenever we clearInterval(retryIntervalCounter) */ private currentRetryCount; /** * @param options Websocket connection options */ constructor(options: IRollaWSOptions); /** * Opens a new websocket connection to the yield api * @returns Promise */ open(): Promise; /** * Close the socket connection */ close(): Promise; /** * Subscribes to Rolla Quote Requests * @param callback The callback that will be fired */ subscribeToQuoteRequests(callback: (data: QuoteRequestDto) => void): void; /** * Subscribes to Rolla Meta Transactions Requests * @param callback The callback that will be fired */ subscribeToMetaTxs(callback: (data: any) => void): void; /** * Add an event listener to a particular channel * @param socketChannel Socket channel name, ex. quote requests, meta txs * @param callback the callback to be triggered when a an event is emitted inside this channel */ private subscribeToChannel; /** * @param data * @returns */ private parseIncomingMessage; /** * Internal logging for WebSockets * @param message message to be logged */ private logInfo; /** * Send a json rpc command over the websocket * @param jsonRpcCommand */ private socketSend; /** * Function that it's called when the websocket connection is closed */ private handleClose; } export {};