WebSocket URL (ws:// or wss://).
OptionalprotocolsSubprotocols to negotiate during the handshake.
OptionalheadersHeaders to inject. On Deno/Bun/Node 22 these become real HTTP Upgrade request headers. On browsers the WS API does not allow custom headers; they are appended as URL query parameters instead.
OptionalmaxMaximum reconnect attempts before giving up. 0 = unlimited. Default: 10
OptionalreconnectBase delay ms for exponential back-off. Default: 1000
OptionalreconnectMaximum back-off cap ms. Default: 30_000
OptionalreconnectJitter factor 0–1. Applied multiplicatively to the capped delay so that each client re-connects at a slightly different time. delay = min(base * 2^n, max) * (1 + jitter * random) Default: 0.3
OptionalpingApplication-level ping interval ms. Every this many ms the client sends pingPayload over the socket. 0 = disabled. Default: 30_000
OptionalpingPayload sent as application-level ping. Default: "ping"
OptionalpongString or RegExp that identifies a pong reply to an application-level ping. When a matching message arrives, the pong-timeout timer is reset and the message is NOT dispatched to listeners. Default: undefined (pong checking disabled)
OptionalpongHow long ms to wait for a pong after a ping before treating the connection as dead and triggering reconnect. 0 = disabled. Default: 10_000
OptionalconnectMaximum ms to wait for the WebSocket handshake to complete. connect() rejects with WSConnectTimeoutError if this elapses. 0 = no limit. Default: 30_000
OptionalbufferBuffer outgoing messages sent while RECONNECTING. Default: true
OptionalmaxMaximum number of messages to buffer (oldest dropped when full). Default: 100
OptionalsignalAbortSignal — aborted closes permanently (code 1000, no reconnect).
OptionalhighBackpressure high-water mark in bytes.
When the outgoing buffer exceeds this threshold backpressure returns true
and send() will buffer rather than transmit.
Default: 65536 (64 KB)
OptionallowLow-water mark in bytes for backpressure release.
The drain() promise resolves when buffered bytes fall below this value.
Must be <= highWaterMark. Default: 16384 (16 KB)
OptionalmaxMaximum outbound message rate (messages per second). 0 = unlimited. Default: 0
OptionalroomsRooms to automatically join after connecting (and re-joining after reconnect). Each entry is a room name string.
OptionalkeepAutomatically re-join subscribed rooms after a reconnect. Default: true
OptionalonCalled when backpressure state changes. isBackpressured=true when the outgoing buffer exceeds highWaterMark.
OptionalonCalled when the socket transitions to OPEN
OptionalonCalled when a message is received
OptionalonCalled when the socket closes
OptionalonCalled on WebSocket error
OptionalonCalled before each reconnect attempt
OptionalonCalled when reconnection is permanently abandoned
Configuration for creating a WSClient instance. Controls connection parameters, reconnection strategy, ping/pong heartbeats, backpressure limits, and lifecycle callbacks.