Skip to content

WebSocketHandlers

Defined in: src/websocket.ts:11

WebSocket lifecycle handlers

T extends Record<string, any> = any

Property Type Description Defined in

onClose?

(ctx, ws, code?, reason?) => void | Promise<void>

Called when WebSocket connection is closed.

src/websocket.ts:38

onError?

(ctx, ws, error) => void | Promise<void>

Called when an error occurs.

src/websocket.ts:43

onEvent?

(ctx, ws, event, data) => boolean | void | Promise<boolean | void>

Called before routing to event handlers. Return false or throw to prevent event routing.

src/websocket.ts:28

onMessage?

(ctx, ws, message) => void | Promise<void>

Called for every message (before event parsing/routing).

src/websocket.ts:33

onOpen?

(ctx, ws) => any

Called after WebSocket connection is established. Return value is automatically set to both ws.data and ctx.state.

src/websocket.ts:22

onStop?

(app) => void | Promise<void>

Called when the server is stopped.

src/websocket.ts:48

onUpgrade?

(ctx) => boolean | void | Promise<boolean | void>

Called when HTTP upgrade request is received (before WebSocket connection). Return false to reject the upgrade.

src/websocket.ts:16