Skip to main content

SilentShardWebSocketClient

Interface for WebSocket client. If you need extra functionality or customize how a message is sent and received from the cloud node, you can implement this interface and pass to CloudWebSocketClient initialization.

Implements

Constructors

new SilentShardWebSocketClient()

new SilentShardWebSocketClient(): SilentShardWebSocketClient

Returns

SilentShardWebSocketClient

Properties

_closeEvent

_closeEvent: null | WebSocketCloseEvent = null

The close event that was received from the WebSocket server.


_closeWaitCompleter

_closeWaitCompleter: Promise<undefined | WebSocketCloseEvent>

A promise that resolves when the WebSocket closes.


_receiveCallbacksQueue

_receiveCallbacksQueue: object[] = []

A queue of pending read() callbacks. A way to make WebSocket client asynchronous.

reject()

reject: (reason) => void

Parameters
reason

any

Returns

void

resolve()

resolve: (data) => void

Parameters
data

any

Returns

void


_receiveDataQueue

_receiveDataQueue: any[] = []

A queue of received WebSocket messages.


_socket

_socket: null | WebSocket = null

The WebSocket client

Accessors

connected

Get Signature

get connected(): boolean

Checks if the WebSocket client is connected.

Returns

boolean

True if the WebSocket is connected, false otherwise.

Methods

close()

close(code?, reason?): Promise<any>

Closes the WebSocket connection to the cloud node.

Parameters

code?

number

reason?

string

Returns

Promise<any>

Implementation of

IWebSocketClient.close


connect()

connect(url, protocols): Promise<void>

Connects to the cloud node using the WebSocket protocol.

Parameters

url

string

The URI of the cloud node.

protocols

string[]

The protocols to use for the WebSocket connection.

Returns

Promise<void>

A promise that resolves when the connection is established.

Implementation of

IWebSocketClient.connect


read()

read(): Promise<Uint8Array>

Get a binary message from the WebSocket connection.

Returns

Promise<Uint8Array>

A promise that resolves to the received binary data.

Implementation of

IWebSocketClient.read


reset()

reset(): void

Resets the WebSocket client, clearing any pending messages and closing the connection.

Returns

void

Implementation of

IWebSocketClient.reset


send()

send(data): Promise<void>

Sends a binary message to the WebSocket connection.

Parameters

data

string

The Base64 encoded message to send.

Returns

Promise<void>

A promise that resolves when the message is sent.

Implementation of

IWebSocketClient.send


sendText()

sendText(data): Promise<void>

Sends an 'utf-8' text message to the WebSocket connection.

Parameters

data

string

An 'utf-8' text message to send.

Returns

Promise<void>

A promise that resolves when the message is sent.

Implementation of

IWebSocketClient.sendText


waitRemoteClose()

waitRemoteClose(): Promise<undefined | WebSocketCloseEvent>

Waits for the remote WebSocket connection to close.

Returns

Promise<undefined | WebSocketCloseEvent>

A promise that resolves when the remote connection is closed.

Implementation of

IWebSocketClient.waitRemoteClose