function buildContext
Since 0.1.0
buildContext(
request: Request,
protocol: string | undefined,
principal?: IPrincipal
): WebSocketConnectionContext

Builds the context handed to onOpen from the upgrade request.

Parameters

request: Request

The upgrade request

protocol: string | undefined

The negotiated subprotocol, when one was selected

optional
principal: IPrincipal

The authenticated principal, when one authenticated the upgrade. When absent the user key is omitted entirely rather than set to undefined, keeping the context exactOptionalPropertyTypes-clean: 'user' in context is false for an anonymous connection.

Return Type

The connection context

Usage

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