Skip to content

Class: WebSocketConnection

@kortexya/reasoninglayer


@kortexya/reasoninglayer / WebSocketConnection

Defined in: src/websocket.ts:18

An active WebSocket connection with auto-reconnect.

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.

get connected(): boolean

Defined in: src/websocket.ts:53

Whether the WebSocket is currently connected.

boolean

close(): void

Defined in: src/websocket.ts:100

Close the WebSocket connection.

void

Once closed, the connection will not attempt to reconnect.


onClose(handler): void

Defined in: src/websocket.ts:81

Register a handler for connection close events.

() => void

Called when the connection closes.

void


onError(handler): void

Defined in: src/websocket.ts:90

Register a handler for connection errors.

(error) => void

Called with the error.

void


onMessage<T>(handler): void

Defined in: src/websocket.ts:62

Register a handler for incoming messages.

T = unknown

MessageHandler<T>

Called with the parsed JSON message data.

void


onReconnect(handler): void

Defined in: src/websocket.ts:72

Register a handler for reconnection events.

ReconnectHandler

Called with the reconnection attempt number.

void