interface WebSocketEventSink
Since 0.2.0

The callbacks an HTTP adapter drives once it has completed a handshake. The WebSocket plugin builds one sink per accepted upgrade and hands it to the adapter inside the accept decision; the adapter binds its native socket events to these methods.

This is the inversion that keeps runtime differences out of the plugin: the adapter knows how to listen, the sink knows what to do.

Methods

onOpen(transport: IWebSocketTransport): void

Called once, when the socket is live and writable.

onMessage(data: string | Uint8Array): void

Called for every inbound frame.

onClose(event: WebSocketCloseEvent): void

Called once, when the socket closes for any reason.

onError(error: Error): void

Called when the socket reports a transport-level error. A socket that errors is also expected to close, so implementations must tolerate WebSocketEventSink.onClose arriving afterwards.

Usage

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