Establishes a WebSocket connection to the specified server and handles various connection events such as open, close, error, and message. This method also manages automatic reconnections with backoff in case of disconnections.
Resolves when the connection is successfully established or rejects with an error if the connection fails.
Emits an event through the socket connection with the specified event name and data.
Registers an internal event handler for either 'open' or 'close' events.
A function that can be called to unregister the handler.
Registers an event handler for a specified socket event name.
The name of the socket event to register the handler for.
The handler function to be executed when the event is triggered.
The
SocketHandler
class manages a WebSocket connection, including connection, reconnection, and event subscription mechanisms.