This version (v0.7) has not been published to npm yet.
Skip to content

Reference / @getenginex/sdk / WebSocketLikeInstance

WebSocketLikeInstance ​

Socket opened by a WebSocketLike: the subset of the browser WebSocket that realtime uses. The browser WebSocket, the Node 22+ global and the one from the ws package are compatible (outside the browser, with the Origin header: see WebSocketLike).

Extended by ​

Properties ​

readyState ​

readonly readyState: number

Connection state: 1 when open (WebSocket.OPEN).

Methods ​

addEventListener() ​

addEventListener(type, listener): void

Subscribes to open, message (with event.data as text), close and error. Realtime subscribes to all four; reconnection is driven by close (error is subscribed only so it is not left without a listener).

Parameters ​

type ​

"message" | "error" | "close" | "open"

Event name.

listener ​

(event) => void

Called on each event.

Returns ​

void


close() ​

close(code?, reason?): void

Closes the connection.

Parameters ​

code? ​

number

reason? ​

string

Returns ​

void


send() ​

send(data): void

Sends a text frame.

Parameters ​

data ​

string

Returns ​

void