WebSocketClientOptions
Options of createWebSocketClient.
Options of createWebSocketClient.
Import#
ts
import type { WebSocketClientOptions } from "@shadow-js/dusk/client";
Signature#
ts
interface WebSocketClientOptions<T> {
/** The socket URL (`ws://`, `wss://`, or a path resolved against the page). */
readonly url: string;
/** Turns a text message into a value. Default: JSON, or the text when it is not JSON. Binary is passed as is. */
readonly parse?: (raw: string) => T;
/** Receives each message. */
readonly onMessage: (data: T | ArrayBuffer) => void;
/** Receives each change of status. */
readonly onStatus?: (status: StreamStatus) => void;
/** Subprotocols to offer. */
readonly protocols?: string | readonly string[];
/** Reconnection policy. */
readonly reconnect?: ReconnectOptions;
/** The socket constructor. Default: the global `WebSocket`. */
readonly WebSocket?: typeof WebSocket;
/** Receives a failure of the client's own code (a `parse` or `onMessage` that threw). Default: `console.error`. */
readonly onError?: (error: unknown) => void;
}
Members#
| Name | Type | Description |
|---|---|---|
T |
T |
|
url |
readonly url: string |
The socket URL (ws://, wss://, or a path resolved against the page). |
parse? |
readonly parse?: (raw: string) => T |
Turns a text message into a value. Default: JSON, or the text when it is not JSON. Binary is passed as is. |
onMessage |
readonly onMessage: (data: T | ArrayBuffer) => void |
Receives each message. |
onStatus? |
readonly onStatus?: (status: StreamStatus) => void |
Receives each change of status. |
protocols? |
readonly protocols?: string | readonly string[] |
Subprotocols to offer. |
reconnect? |
readonly reconnect?: ReconnectOptions |
Reconnection policy. |
WebSocket? |
readonly WebSocket?: typeof WebSocket |
The socket constructor. Default: the global WebSocket. |
onError? |
readonly onError?: (error: unknown) => void |
Receives a failure of the client's own code (a parse or onMessage that threw). Default: console.error. |