Skip to main content

IWebSocketClient

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.

Methods

close()

close(): Promise<any>

Closes the WebSocket connection to the cloud node.

Returns

Promise<any>


connect()

connect(url, protocols, options?): 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.

options?

WebSocketOptions

Additional options for the WebSocket connection, such as headers.

Returns

Promise<void>

A promise that resolves when the connection is established.


read()

read(): Promise<Uint8Array>

Get a binary message from the WebSocket connection.

Returns

Promise<Uint8Array>

A promise that resolves to the received binary data.


reset()

reset(): void

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

Returns

void


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.


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.


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.