Class: WebSocketConnection
@kortexya/reasoninglayer / WebSocketConnection
Class: WebSocketConnection
Section titled “Class: WebSocketConnection”Defined in: src/websocket.ts:18
An active WebSocket connection with auto-reconnect.
Remarks
Section titled “Remarks”Uses the native WebSocket API (Node 18+, browsers, Deno, Bun). Automatically reconnects with exponential backoff + jitter (1s -> 2s -> 4s -> … -> max 30s), up to 10 attempts.
Accessors
Section titled “Accessors”connected
Section titled “connected”Get Signature
Section titled “Get Signature”get connected():
boolean
Defined in: src/websocket.ts:53
Whether the WebSocket is currently connected.
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”close()
Section titled “close()”close():
void
Defined in: src/websocket.ts:100
Close the WebSocket connection.
Returns
Section titled “Returns”void
Remarks
Section titled “Remarks”Once closed, the connection will not attempt to reconnect.
onClose()
Section titled “onClose()”onClose(
handler):void
Defined in: src/websocket.ts:81
Register a handler for connection close events.
Parameters
Section titled “Parameters”handler
Section titled “handler”() => void
Called when the connection closes.
Returns
Section titled “Returns”void
onError()
Section titled “onError()”onError(
handler):void
Defined in: src/websocket.ts:90
Register a handler for connection errors.
Parameters
Section titled “Parameters”handler
Section titled “handler”(error) => void
Called with the error.
Returns
Section titled “Returns”void
onMessage()
Section titled “onMessage()”onMessage<
T>(handler):void
Defined in: src/websocket.ts:62
Register a handler for incoming messages.
Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”handler
Section titled “handler”MessageHandler<T>
Called with the parsed JSON message data.
Returns
Section titled “Returns”void
onReconnect()
Section titled “onReconnect()”onReconnect(
handler):void
Defined in: src/websocket.ts:72
Register a handler for reconnection events.
Parameters
Section titled “Parameters”handler
Section titled “handler”ReconnectHandler
Called with the reconnection attempt number.
Returns
Section titled “Returns”void