Get current state.
Check if currently connected (handshaking or later).
Check if ready for requests.
Transition to connecting (convenience method).
Transition to handshaking (convenience method).
Transition to authenticating (convenience method).
Transition to ready (convenience method).
Transition to reconnecting (convenience method).
Transition to disconnected (convenience method).
Close connection (terminal state).
Reset to disconnected state.
Set a callback for handling errors thrown by state change listeners.
By default, listener errors are silently ignored to prevent one buggy listener from breaking the entire state machine flow. Use this method to customize error handling (e.g., logging to error tracking service).
Callback function to handle listener errors
Connection state machine with valid transition enforcement.
States:
disconnected: Initial state, no connectionconnecting: TCP/TLS connection in progresshandshaking: Protocol handshake in progressauthenticating: Authentication in progressready: Fully connected and authenticatedreconnecting: Attempting to reconnect after disconnectclosed: Connection closed (terminal state)