Skip to main content
Version: 2x

Class: WebSocketServer

Abstract class for providing common logic (eg routing) for all WebSocket servers.

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new WebSocketServer(fastify, path, wssOptions?)

Create a new instance of the WebSocketServer. Any logging information, will be passed through standard fastify.log API.

Parameters

NameTypeDescription
fastifyFastifyDevServerFastify instance to which the WebSocket will be attached to.
pathstring | string[]Path on which this WebSocketServer will be accepting connections.
wssOptionsOmit<ServerOptions, "host" | "port" | "noServer" | "server" | "path">WebSocket Server options.

Defined in

packages/repack/src/server/ws/WebSocketServer.ts:28

Properties

fastify

Protected fastify: FastifyDevServer

Fastify instance from which server will receive upgrade connections.

Defined in

packages/repack/src/server/ws/WebSocketServer.ts:16


paths

Readonly paths: string[]

Defined in

packages/repack/src/server/ws/WebSocketServer.ts:18


server

Readonly server: Server

An instance of the underlying WebSocket server.

Defined in

packages/repack/src/server/ws/WebSocketServer.ts:13

Methods

onConnection

Abstract onConnection(socket, request): void

Process incoming WebSocket connection.

Parameters

NameTypeDescription
socketWebSocketIncoming WebSocket connection.
requestIncomingMessageUpgrade request for the connection.

Returns

void

Defined in

packages/repack/src/server/ws/WebSocketServer.ts:61


shouldUpgrade

shouldUpgrade(pathname): boolean

Parameters

NameType
pathnamestring

Returns

boolean

Defined in

packages/repack/src/server/ws/WebSocketServer.ts:45


upgrade

upgrade(request, socket, head): void

Parameters

NameType
requestIncomingMessage
socketSocket
headBuffer

Returns

void

Defined in

packages/repack/src/server/ws/WebSocketServer.ts:49