Skip to content

Interface: WebSocketOptions ​

Defined in: api/rust-fetch.d.ts:685

Properties ​

allowAbsoluteUrls? ​

optional allowAbsoluteUrls?: boolean

Defined in: api/rust-fetch.d.ts:709

Overrides the client's allowAbsoluteUrls


allowPrivateNetwork? ​

optional allowPrivateNetwork?: boolean

Defined in: api/rust-fetch.d.ts:716

Node.js: overrides the client's allowPrivateNetwork. With false, an IP address that is private or reserved throws a NetworkError from websocket(), and a host name is checked on every connection, reconnections included (a blocked one fails the attempt with "Blocked: …"). Can't be combined with dispatcher, and fails while another undici global dispatcher is installed. Browsers have their own rules.


dispatcher? ​

optional dispatcher?: object

Defined in: api/rust-fetch.d.ts:700

Node.js only: an undici dispatcher for the connection, e.g. new ProxyAgent('http://proxy:3128') from the undici package to connect through a proxy. Node's WebSocket doesn't use the client's proxy option.


headers? ​

optional headers?: HeadersLike

Defined in: api/rust-fetch.d.ts:695

Handshake headers, merged over the client's headers. Node.js only: browsers don't allow WebSocket headers, so there this rejects with an InvalidInputError (client headers are skipped).


idleTimeoutMs? ​

optional idleTimeoutMs?: number

Defined in: api/rust-fetch.d.ts:687

Maximum silence after open/between received messages. 0 disables; defaults to the client's idleTimeoutMs. No heartbeat messages are sent.


maxQueuedBytes? ​

optional maxQueuedBytes?: number

Defined in: api/rust-fetch.d.ts:727

The most bytes (UTF-8 for text, byteLength or size otherwise) send() queues while the connection isn't open yet. A message that would go over throws a NetworkError whose maxQueuedBytes is the limit, and isn't queued. Once open, messages go to the runtime's socket: watch bufferedAmount there. Default: no limit


maxQueuedMessages? ​

optional maxQueuedMessages?: number

Defined in: api/rust-fetch.d.ts:721

The most messages send() queues while the connection isn't open yet (connecting or reconnecting). One more throws a NetworkError whose maxQueuedMessages is the limit, and isn't queued. Default: no limit


messageType? ​

optional messageType?: "auto" | "json"

Defined in: api/rust-fetch.d.ts:731

auto (default): text messages as strings, binary ones as Uint8Array. json: text messages parsed as JSON


onClose? ​

optional onClose?: (info) => void

Defined in: api/rust-fetch.d.ts:740

Called once, when the connection is closed for good

Parameters ​

info ​

WebSocketCloseInfo

Returns ​

void


onError? ​

optional onError?: (error) => void

Defined in: api/rust-fetch.d.ts:736

Called on every failure: a failed or timed-out attempt, an unexpected drop, a message that isn't JSON

Parameters ​

error ​

RustFetchError

Returns ​

void


onMessage? ​

optional onMessage?: (data) => void

Defined in: api/rust-fetch.d.ts:734

Parameters ​

data ​

any

Returns ​

void


onOpen? ​

optional onOpen?: () => void

Defined in: api/rust-fetch.d.ts:733

Called each time a connection opens, including after reconnecting

Returns ​

void


onReconnect? ​

optional onReconnect?: (info) => void

Defined in: api/rust-fetch.d.ts:738

Called before waiting to reconnect

Parameters ​

info ​

WebSocketReconnectInfo

Returns ​

void


params? ​

optional params?: QueryParams

Defined in: api/rust-fetch.d.ts:690


protocols? ​

optional protocols?: string | string[]

Defined in: api/rust-fetch.d.ts:689

Subprotocols to offer


reconnect? ​

optional reconnect?: number | boolean | ReconnectOptions

Defined in: api/rust-fetch.d.ts:707

Reconnect when a connection fails or drops unexpectedly (close codes 1001, 1006, 1011-1014): true for the defaults, a maximum number of attempts in a row, or options. Default: off


signal? ​

optional signal?: AbortSignal

Defined in: api/rust-fetch.d.ts:729

Closes the connection and stops reconnecting when aborted


timeoutMs? ​

optional timeoutMs?: number

Defined in: api/rust-fetch.d.ts:702

Time allowed for each connection attempt, in ms. 0 disables it. Default: the client's timeoutMs

Released under the MIT or Apache-2.0 license.