CloudWebSocketClient
CloudWebSocketClient is a class that handles the WebSocket communication with the cloud node. It is used to send
and receive messages from the cloud node
Import
import { CloudWebSocketClient } from '@silencelaboratories/silent-shard-sdk';
Usage
const couldClient = new CloudWebSocketClient(
'CLOUD_NODE_URL',
false, // boolean indicates if the connection is `WSS` or `WS`
);
Constructors
new CloudWebSocketClient()
new CloudWebSocketClient(
url,isSecure,wsClient?):CloudWebSocketClient
Constructor
Parameters
url
string
The URI of the cloud node.
isSecure
boolean
If the connection is TLS // WSS true / WS false.
wsClient?
The WebSocket client to use. Default is WebSocketClient. If you want to use a custom WebSocket client, you can implement the IWebSocketClient interface. Then you can pass here.
Returns
Accessors
isSecure
Get Signature
get isSecure():
boolean
Returns whether the connection over the TLS or not.
Returns
boolean
True if the connection is secure (WSS), false otherwise (WS).
url
Get Signature
get url():
string
Returns the URL of the cloud node.
Returns
string
The URL of the cloud node.
Methods
close()
close():
Promise<any>
Closes the WebSocket connection to the cloud node.
Returns
Promise<any>
A promise that resolves when the connection is closed.
connect()
connect(
action,options?):Promise<void>
Connects to the cloud node using the WebSocket protocol.
Parameters
action
WebSocketAction
The operation options containing algorithm, action, and protocol.
options?
WebSocketOptions
Additional WebSocket options, such as headers.
Returns
Promise<void>
A promise that resolves to the WebSocket client.
read()
read():
Promise<Uint8Array>
Reads binary data from the WebSocket connection.
Returns
Promise<Uint8Array>
A promise that resolves to the binary data read from the WebSocket connection.
reset()
reset():
void
Resets the WebSocket client, clearing any existing connection.
Returns
void
send()
send(
message):Promise<void>
Receive Base64 string and decode into binary. Sends a binary message to the WebSocket connection.
Parameters
message
string
The Base64 encoded message to send.
Returns
Promise<void>
A promise that resolves when the message is sent.
sendText()
sendText(
message):Promise<void>
Sends an 'utf-8' text message to the WebSocket connection.
Parameters
message
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.