Interface: WebSocketClientOptions
On this page
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:39
Options for createWSClient.
See
https://trpc.io/docs/client/links/wsLink#wslink--createwsclient-options
Extends
UrlOptionsWithConnectionParams
Properties
connectionParams?
optionalconnectionParams:CallbackOrValue<null|Dict<string>>
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:30
Connection params that are available in createContext()
- For
wsLink/wsClient, these are sent as the first message - For
httpSubscriptionLink, these are serialized as part of the URL under theconnectionParamsquery
See
https://trpc.io/docs/server/websockets#connectionParams
Inherited from
UrlOptionsWithConnectionParams.connectionParams
experimental_encoder?
optionalexperimental_encoder:Encoder
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:101
Encodes and decodes messages on the wire, for example as a binary format.
Default
jsonEncoderkeepAlive?
optionalkeepAlive:object
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:81
Send ping messages to the server and kill the connection if no pong message is returned
enabled
enabled:
boolean
Default
falseintervalMs?
optionalintervalMs:number
Send a ping message every this many milliseconds
Default
5_000pongTimeoutMs?
optionalpongTimeoutMs:number
Close the WebSocket after this many milliseconds if the server does not respond
Default
1_000lazy?
optionallazy:object
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:66
Lazy mode will close the WebSocket automatically after a period of inactivity (no messages sent or received and no pending requests)
closeMs
closeMs:
number
Close the WebSocket after this many milliseconds
Default
0enabled
enabled:
boolean
Enable lazy mode
Default
falseonClose()?
optionalonClose: (cause?) =>void
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:60
Triggered when a WebSocket connection is closed
Parameters
| Parameter | Type |
|---|---|
cause? | { code: number; } |
cause.code? | number |
Returns
void
onError()?
optionalonError: (evt?) =>void
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:56
Triggered when a WebSocket connection encounters an error
Parameters
| Parameter | Type |
|---|---|
evt? | Event |
Returns
void
onOpen()?
optionalonOpen: () =>void
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:52
Triggered when a WebSocket connection is established
Returns
void
retryDelayMs()?
optionalretryDelayMs: (attemptIndex) =>number
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:48
The number of milliseconds before a reconnect is attempted.
Parameters
| Parameter | Type |
|---|---|
attemptIndex | number |
Returns
number
Default
exponentialBackoff
url
url:
CallbackOrValue<string>
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:23
The URL to connect to (can be a function that returns a URL)
Inherited from
UrlOptionsWithConnectionParams.url
WebSocket()?
optionalWebSocket: (url,protocols?) =>WebSocket
Defined in: packages/client/dist/wsLink-Cjetil1Z.d.mts:43
The WebSocket class to use, for runtimes that don't have one.
Parameters
| Parameter | Type |
|---|---|
url | string | URL |
protocols? | string | string[] |
Returns
WebSocket