ProtectedconfigurationProtectedconnectionProtectedwsProtectedcleanupThe WebSocket client to clean up.
void
ProtectedclearClears all timers associated with a WebSocket connection.
The WebSocket client instance to clear timers for.
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.
ProtectedconnectConnects all WebSocket connections in the pool
The Websocket server URL.
A promise that resolves when all connections are established.
ProtectedcreateCreates 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.
ProtectedemitProtectedgetRetrieves 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.
ProtectedgetGets 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.
ProtectedgetFormats 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.
ProtectedinitInitializes a WebSocket connection.
The Websocket server URL.
Whether this is a connection renewal.
Optionalconnection: WebsocketConnectionAn optional WebSocket connection to use.
The WebSocket connection.
Checks if the WebSocket connection is currently open.
Optionalconnection: WebsocketConnectionAn optional WebSocket connection to check. If not provided, the entire connection pool is checked.
true if the connection is open, false otherwise.
ProtectedisChecks 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.
ProtectedonHandles 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.
ProtectedonCalled 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.
ProtectedscheduleSchedules a timer for a WebSocket connection and tracks it
WebSocket client instance
Function to execute when timer triggers
Time in milliseconds before callback execution
Timer type ('timeout' or 'interval')
Timer handle
ProtectedsendSends a payload through the WebSocket connection.
Message to send.
Optionalid: stringOptional request identifier.
Whether to return a promise.
Timeout duration in milliseconds.
Optionalconnection: 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
Optionalid: 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
Optionalid: stringOptional unsubscription ID
void
Cleans up WebSocket connection resources. Removes all listeners and clears any associated timers for the provided WebSocket client.