class NodeUpgradeCoordinator
Since 0.2.0

Owns the ws server for one Node HTTP adapter and performs the handshake.

Split out of the adapter so the adapter keeps its single responsibility (mapping HTTP) and so the handshake's branches are measurable in isolation. The ws server is created on the first accepted upgrade — a plain HTTP application therefore never loads the optional dependency at all.

Constructors

NodeUpgradeCoordinator(module?: WsModuleLike)

Creates the coordinator.

Parameters
optional
module: WsModuleLike

An injected ws module; omit to load it lazily

Properties

readonly
hasServer: boolean

Whether a ws server has been created yet.

Methods

close(): void

Shuts down the ws server, when one was ever created.

handshake(
socket: unknown,
head: unknown,
sink: WebSocketEventSink,
protocol?: string
): Promise<void>

Completes the RFC 6455 handshake over an already-accepted TCP connection and binds the resulting socket to the decision's sink.

Usage

import { NodeUpgradeCoordinator } from "runtime/src/index.ts";