A live WebSocket connection.
Tracks the monotonic timestamp of the last inbound frame so the heartbeat sweeper can find idle peers, and refuses writes once closed rather than failing deep inside a platform socket.
Creates a connection.
transport: IWebSocketTransport
The runtime-agnostic socket
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.
id: string
Unique connection ID (from runtime.uuid()).
isOpen: boolean
Whether the connection is still writable.
lastSeenAt: number
The monotonic timestamp of the most recent inbound frame. Compared against
another runtime.hrtime() reading — never against a wall clock.
participatesInHeartbeat: boolean
Whether the shared heartbeat sweeper should include this connection.
When false, the sweeper skips both the payload send and idle eviction.
path: string
The path this connection was opened on.
readyState: WebSocketReadyState
Current lifecycle state.
close(code?: number,reason?: string): void
Closes the connection. Idempotent.
markClosed(): void
Marks the connection closed without touching the transport — used when the peer closed first, so the socket is already gone.
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.
touch(now: number): void
Records that a frame arrived, resetting the idle countdown.