interface IWebSocketConnection
Since 0.2.0

A live WebSocket connection, as seen by application code.

Properties

readonly
id: string

Unique connection ID (from runtime.uuid()).

readonly
path: string

The path this connection was opened on.

Current lifecycle state.

readonly
isOpen: boolean

Whether the connection is still writable.

readonly
data: Map<string, unknown>

Per-connection application state, the socket-lifetime analogue of IRequestContext.state. Use it to attach an authenticated user id, a tenant, or any value later handlers and broadcasts need.

Methods

send(data: string | Uint8Array): void

Sends a frame to this peer.

sendJson<T>(payload: T): void

Serializes a value to JSON and sends it as a text frame.

close(
code?: number,
reason?: string
): void

Closes the connection. Idempotent.

Usage

import { type IWebSocketConnection } from "common/src/index.ts";