@dxfeed/dxlink-websocket-client
Version:
dxLink WebSocket Client allows to connect the remote dxLink WebSocket endpoint
86 lines (85 loc) • 3.67 kB
TypeScript
import { type DXLinkConnectionDetails, DXLinkConnectionState, type DXLinkConnectionStateChangeListener, type DXLinkErrorListener, DXLinkAuthState, type DXLinkAuthStateChangeListener, type DXLinkChannel, type DXLinkClient } from '@dxfeed/dxlink-core';
import type { DXLinkWebSocketClientConfig } from './config';
/**
* Protocol version that is used by client.
*/
export declare const DXLINK_WS_PROTOCOL_VERSION = "0.1";
/**
* dxLink WebSocket client that can be used to connect to the remote dxLink WebSocket endpoint and open channels to services.
*/
export declare class DXLinkWebSocketClient implements DXLinkClient {
private readonly config;
private readonly logger;
private readonly scheduler;
private connector;
private connectionState;
private connectionDetails;
private authState;
private readonly connectionStateChangeListeners;
private readonly errorListeners;
private readonly authStateChangeListeners;
/**
* Authorization type that was determined by server behavior during setup phase.
* This value is used to determine if authorization is required or optional or not defined yet.
*/
private isFirstAuthState;
/**
* Last setted auth token that will be sent to server after connection is established or re-established.
*/
private lastSettedAuthToken;
private lastReceivedMillis;
private lastSentMillis;
/**
* Count of reconnect attempts since last successful connection.
*/
private reconnectAttempts;
private globalChannelId;
private readonly channels;
/**
* Create new instance of {@link DXLinkWebSocketClient}.
* @param config Configuration of the client.
*/
constructor(config?: Partial<DXLinkWebSocketClientConfig>);
connect: (url: string) => void;
reconnect: () => void;
disconnect: () => void;
close: () => void;
getConnectionDetails: () => DXLinkConnectionDetails;
getConnectionState: () => DXLinkConnectionState;
addConnectionStateChangeListener: (listener: DXLinkConnectionStateChangeListener) => Set<DXLinkConnectionStateChangeListener>;
removeConnectionStateChangeListener: (listener: DXLinkConnectionStateChangeListener) => boolean;
setAuthToken: (token: string) => void;
getAuthState: () => DXLinkAuthState;
addAuthStateChangeListener: (listener: DXLinkAuthStateChangeListener) => Set<DXLinkAuthStateChangeListener>;
removeAuthStateChangeListener: (listener: DXLinkAuthStateChangeListener) => boolean;
addErrorListener: (listener: DXLinkErrorListener) => Set<DXLinkErrorListener>;
removeErrorListener: (listener: DXLinkErrorListener) => boolean;
openChannel: (service: string, parameters: Record<string, unknown>) => DXLinkChannel;
private setConnectionState;
private sendMessage;
private sendAuthMessage;
private setAuthState;
private processMessage;
private processSetupMessage;
private publishError;
private processAuthStateMessage;
private requestActiveChannels;
/**
* Process transport open event from connector.
* After transport is opened:
* - setup message is sent to server
* - auth message is sent to server if auth token is set
* - wait for setup message from server
* - wait for auth state message from server
*/
private processTransportOpen;
/**
* Process transport close event from connector.
* After transport is closed by server:
* - reconnect if connection is authorized
* - disconnect if connection is not authorized
*/
private processTransportClose;
private timeoutCheck;
private scheduleKeepalive;
}