API reference › @evolu/common › WebSocket › WebSocketOptions
Defined in: packages/common/src/WebSocket.ts:198
Options for creating WebSocket.
Properties
binaryType?
readonly optional binaryType?: "blob" | "arraybuffer";
Defined in: packages/common/src/WebSocket.ts:203
Sets the binary type for the data being received.
healthyConnectionDuration?
readonly optional healthyConnectionDuration?: Duration;
Defined in: packages/common/src/WebSocket.ts:250
How long a connection must stay open for its close to start WebSocketOptions.schedule over. Defaults to 30 seconds, the delay cap of webSocketReconnectSchedule.
The schedule is stateful and spans every reconnect, so without this a client that has disconnected often keeps waiting the longest backoff delay forever, even after hours of healthy connection. A connection that outlasts the longest delay the schedule can produce shows the endpoint works, so the next disconnect starts from the base delay again. Shorter connections reset nothing, so an endpoint that accepts and immediately drops connections still backs off.
Choose it with the schedule rather than on its own: it is the schedule's delay cap, which only the schedule knows. A schedule cannot be asked for that cap, which is why this is an option rather than something derived. The delays a schedule has already produced are no substitute, because a jittered one produces delays near zero early on, and a threshold that low would reset the backoff for exactly the endpoint it protects against.
onClose?
readonly optional onClose?: (event: WebSocketCloseEvent) => void;
Defined in: packages/common/src/WebSocket.ts:212
Callback when the connection is closed.
onError?
readonly optional onError?: (error: WebSocketError) => void;
Defined in: packages/common/src/WebSocket.ts:209
Callback when an error occurs.
onMessage?
readonly optional onMessage?: (data:
| string
| ArrayBuffer
| Blob) => void;
Defined in: packages/common/src/WebSocket.ts:222
Callback when message data is received.
onOpen?
readonly optional onOpen?: () => void;
Defined in: packages/common/src/WebSocket.ts:206
Callback when the connection is established.
protocols?
readonly optional protocols?: string | readonly string[];
Defined in: packages/common/src/WebSocket.ts:200
Protocol(s) to use with the WebSocket connection.
schedule?
readonly optional schedule?: Schedule<number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative"> & Brand<"LessThan281474976710655"> & Brand<"Millis">, WebSocketRetryError>;
Defined in: packages/common/src/WebSocket.ts:228
Retry schedule for reconnection. Defaults to webSocketReconnectSchedule.
shouldRetryOnClose?
readonly optional shouldRetryOnClose?: (event: WebSocketCloseEvent) => boolean;
Defined in: packages/common/src/WebSocket.ts:219
Determines whether a closed connection should trigger a retry.
Return false to stop retrying, for example on auth errors or maintenance.
WebSocketConstructor?
readonly optional WebSocketConstructor?: {
(url: string | URL, protocols?: string | string[]): WebSocket;
CLOSED: 3;
CLOSING: 2;
CONNECTING: 0;
OPEN: 1;
prototype: WebSocket;
};
Defined in: packages/common/src/WebSocket.ts:259
For custom WebSocket implementations.
This supports blob: