Defjs
Core

withWebSocketProtocols

Sets the WebSocket subprotocols offered during the handshake.

@defjs/core · Function

Signature

function withWebSocketProtocols(
  protocols: readonly string[],
): ClientOption;

They are passed as the second argument to the WebSocket constructor only when the list is not empty, so the platform can run the RFC 6455 subprotocol negotiation. They matter only when the server requires a specific subprotocol, for example ['json'] or ['v1'].

Precedence, highest first: the protocols request option, this client option, then protocols on the endpoint definition.

Parameters

Prop

Type

protocols readonly string[]

Subprotocol list for the WebSocket constructor.

Returns

An option that sets config.webSocket.protocols.

Edit this page on GitHub
Released under the MIT License. · Copyright © 2026 MunMunMiao