Protected
configurationProtected
wsProtected
cleanupThe WebSocket client to clean up.
void
Connects to the WebSocket server and subscribes to the specified streams. This method returns a Promise that resolves when the connection is established, or rejects with an error if the connection fails to be established within 10 seconds.
A single stream name or an array of stream names to subscribe to.
A Promise that resolves when the connection is established.
Protected
connectConnects all WebSocket connections in the pool
The Websocket server URL.
A promise that resolves when all connections are established.
Protected
createCreates a new WebSocket client instance.
The URL to connect to.
A new WebSocket client instance.
Disconnects the WebSocket connection and clears the stream callback map. This method is called to clean up the connection and associated resources.
Protected
emitProtected
getRetrieves available WebSocket connections based on the connection mode and readiness. In 'single' mode, returns the first connection in the pool. In 'pool' mode, filters and returns connections that are ready for use.
Optional flag to include non-established WebSocket connections.
An array of available WebSocket connections.
Protected
getGets a WebSocket connection from the pool or single connection. If the connection mode is 'single', it returns the first connection in the pool. If the connection mode is 'pool', it returns an available connection from the pool, using a round-robin selection strategy. If no available connections are found, it throws an error.
A boolean indicating whether to allow connections that are not established.
The selected WebSocket connection.
Protected
getFormats the WebSocket URL with stream and configuration parameters to be used for reconnection.
The base WebSocket URL.
The target WebSocket connection.
The formatted WebSocket URL with streams and optional parameters.
Protected
initInitializes a WebSocket connection.
The Websocket server URL.
Whether this is a connection renewal.
Optional
connection: WebsocketConnectionAn optional WebSocket connection to use.
The WebSocket connection.
Checks if the WebSocket connection is currently open.
Optional
connection: WebsocketConnectionAn optional WebSocket connection to check. If not provided, the entire connection pool is checked.
true
if the connection is open, false
otherwise.
Protected
isChecks if the provided WebSocket connection is ready for use. A connection is considered ready if it is open, has no pending reconnection, and has not been closed.
The WebSocket connection to check.
An optional flag to allow non-established WebSocket connections.
true
if the connection is ready, false
otherwise.
Checks if the specified stream is currently subscribed.
The name of the stream to check.
true
if the stream is currently subscribed, false
otherwise.
Protected
onHandles incoming WebSocket messages, parsing the data and invoking the appropriate callback function.
If the message contains a stream name that is registered in the streamCallbackMap
, the corresponding
callback function is called with the message data.
If the message cannot be parsed, an error is logged.
The raw WebSocket message data.
The WebSocket connection that received the message.
Protected
onCalled when the WebSocket connection is opened. Processes any pending subscriptions for the target connection.
The URL of the WebSocket connection.
The WebSocket connection that was opened.
Protected
sendSends a payload through the WebSocket connection.
Message to send.
Optional
id: stringOptional request identifier.
Whether to return a promise.
Timeout duration in milliseconds.
Optional
connection: WebsocketConnectionThe WebSocket connection to use.
A promise if promiseBased
is true, void otherwise.
Subscribes to one or multiple WebSocket streams Handles both single and pool modes
Single stream name or array of stream names to subscribe to
Optional
id: stringOptional subscription ID
void
Unsubscribes from one or multiple WebSocket streams Handles both single and pool modes
Single stream name or array of stream names to unsubscribe from
Optional
id: stringOptional unsubscription ID
void
Cleans up WebSocket connection resources. Removes all listeners and clears any associated timers for the provided WebSocket client.