interface WebSocketHandlers
Since 0.2.0

The lifecycle callbacks an application supplies per WebSocket route.

Every callback may be async; a rejected promise is routed to WebSocketHandlers.onError rather than becoming an unhandled rejection.

Methods

optional
onOpen(): void | Promise<void>

Called once per connection, after the handshake completes.

optional
onMessage(
data: string | Uint8Array
): void | Promise<void>

Called for every inbound frame.

optional
onClose(): void | Promise<void>

Called once, when the connection closes for any reason.

optional
onError(
error: Error
): void | Promise<void>

Called on a transport error, and on a rejected promise from any other callback.

Usage

import { type WebSocketHandlers } from "websocket-plugin/src/index.ts";