function selectProtocol
Since 0.1.0
selectProtocol(
configured: readonly string[],
requested: readonly string[]
): string | undefined | false

Selects the subprotocol to echo for a route.

With no configured protocols, none is negotiated and none is echoed — echoing a protocol the client did not request breaks conformant clients. With configured protocols, the client's first requested protocol that the route accepts wins; if none match, the handshake is refused.

Parameters

configured: readonly string[]

The route's accepted protocols

requested: readonly string[]

The protocols the client asked for

Return Type

string | undefined | false

The selected protocol, undefined when none is negotiated, or false to refuse

Usage

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