Documentation
Interfaces
server.WebSocket

Interface: WebSocket

server.WebSocket

Properties

protocol

Readonly protocol: string

The subprotocol of the WebSocket. Will be used to validate against the supported ones.

Defined in

src/server.ts:429

Methods

close

close(code?, reason?): void | Promise<void>

Closes the socket gracefully. Will always provide the appropriate code and close reason. onDisconnect callback will be called.

The returned promise is used to control the graceful closure.

Parameters

NameType
code?number
reason?string

Returns

void | Promise<void>

Defined in

src/server.ts:450


onMessage

onMessage(cb): void

Called when message is received. The library requires the data to be a string.

All operations requested from the client will block the promise until completed, this means that the callback will not resolve until all subscription events have been emitted (or until the client has completed the stream), or until the query/mutation resolves.

Exceptions raised during any phase of operation processing will reject the callback’s promise, catch them and communicate them to your clients however you wish.

Parameters

NameType
cb(data: string) => Promise<void>

Returns

void

Defined in

src/server.ts:464


onPing

onPing(payload): void | Promise<void>

Implement a listener for the PingMessage sent from the client to the server. If the client sent the ping with a payload, it will be passed through the first argument.

If this listener is implemented, the server will NOT automatically reply to any pings from the client. Implementing it makes it your responsibility to decide how and when to respond.

Parameters

NameType
payloadundefined | Record<string, unknown>

Returns

void | Promise<void>

Defined in

src/server.ts:474


onPong

onPong(payload): void | Promise<void>

Implement a listener for the PongMessage sent from the client to the server. If the client sent the pong with a payload, it will be passed through the first argument.

Parameters

NameType
payloadundefined | Record<string, unknown>

Returns

void | Promise<void>

Defined in

src/server.ts:480


send

send(data): void | Promise<void>

Sends a message through the socket. Will always provide a string message.

Please take care that the send is ready. Meaning, only provide a truly OPEN socket through the opened method of the Server.

The returned promise is used to control the flow of data (like handling backpressure).

Parameters

NameType
datastring

Returns

void | Promise<void>

Defined in

src/server.ts:441