API reference › @evolu/common › WebSocket › WebSocketOptions
Defined in: packages/common/src/WebSocket.ts:219
Options for creating WebSocket.
Properties
binaryType?
readonly binaryType?: "blob" | "arraybuffer";
Defined in: packages/common/src/WebSocket.ts:224
Sets the binary type for the data being received.
healthyConnectionDuration?
readonly healthyConnectionDuration?: Duration;
Defined in: packages/common/src/WebSocket.ts:271
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 onClose?: (event: WebSocketCloseEvent) => void;
Defined in: packages/common/src/WebSocket.ts:233
Callback when the connection is closed.
onError?
readonly onError?: (error: WebSocketError) => void;
Defined in: packages/common/src/WebSocket.ts:230
Callback when an error occurs.
onMessage?
readonly onMessage?: (data:
| string
| ArrayBuffer
| Blob) => void;
Defined in: packages/common/src/WebSocket.ts:243
Callback when message data is received.
onOpen?
readonly onOpen?: () => void;
Defined in: packages/common/src/WebSocket.ts:227
Callback when the connection is established.
protocols?
readonly protocols?: string | readonly string[];
Defined in: packages/common/src/WebSocket.ts:221
Protocol(s) to use with the WebSocket connection.
schedule?
readonly schedule?: Schedule<number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative"> & Brand<"LessThan281474976710655"> & Brand<"Millis">, WebSocketRetryError>;
Defined in: packages/common/src/WebSocket.ts:249
Retry schedule for reconnection. Defaults to webSocketReconnectSchedule.
shouldRetryOnClose?
readonly shouldRetryOnClose?: (event: WebSocketCloseEvent) => boolean;
Defined in: packages/common/src/WebSocket.ts:240
Determines whether a closed connection should trigger a retry.
Return false to stop retrying, for example on auth errors or maintenance.
WebSocketConstructor?
readonly WebSocketConstructor?: {
new (url: string | URL, protocols?: string | string[]): WebSocket;
CLOSED: 3;
CLOSING: 2;
CONNECTING: 0;
OPEN: 1;
prototype: WebSocket;
};
Defined in: packages/common/src/WebSocket.ts:280
For custom WebSocket implementations.
This supports blob: