Core
withWebSocketBeforeConnect
Runs a hook before the initial WebSocket connect and before every reconnect.
@defjs/core · Function
Signature
function withWebSocketBeforeConnect( beforeConnect: ClientWebSocketOptions["beforeConnect"], ): ClientOption;
The hook type is:
(context: { attempt: number; signal: AbortSignal }) => void | Promise<void>attemptis0for the first connect and grows by one for each reconnect.- Pass
signalinto token refreshes and other async work so cancelling the session stops them. - If the hook throws, the attempt fails with an
EXT_HOOK_FAILEDfault. - A
beforeConnectin the request options replaces this one for that call.
Parameters
Prop
Type
beforeConnect ((context: { attempt: number; signal: AbortSignal; }) => void | Promise<void>) | undefinedHook receiving attempt index and abort signal.
Returns
An option that sets config.webSocket.beforeConnect.