interface WebSocketConnectionContext
Since 0.2.0

Details of the upgrade request that opened a connection, handed to WebSocketHandlers.onOpen.

Because WebSocket routes match on exact path, variable data travels in the query string and is exposed through WebSocketConnectionContext.query.

Properties

readonly
url: string

The full upgrade request URL.

readonly
path: string

The URL path component (no query string).

readonly
query: Readonly<Record<string, string>>

Query string parameters.

readonly
headers: Headers

The upgrade request headers — read these to authenticate the peer.

readonly
optional
protocol: string

The negotiated subprotocol, when one was selected.

Since 0.3.0
readonly
optional
user: IPrincipal

The authenticated principal, when one authenticated the upgrade. Populated by threading ctx.request.user through IWebSocketService.routeUpgrade; omitted when the upgrade was not authenticated. Read this in onOpen to identify the peer rather than re-deriving it from the headers.

Usage

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