WsClient

WsClient

Class rapresenting the client connection

Constructor

# new WsClient(option, authenticationTokenopt)

Parameters:
Name Type Attributes Description
option Object
Properties
Name Type Attributes Description
url Url Url to websocket server (ws://x.x)
websocket WebSocket <optional>
Class rapresent the websocket connection, if you are on nodejs use ws otherwise leave blank
authenticationToken * <optional>
If you want to authenticate the user set this and validate it on server

Methods

# (async) connect() → {Promise}

Start ws connection, you need to call this method to make a connection
Returns:
resolve the promise when the connection is established
Type
Promise

# getTotMessages() → {Number}

Returns:
Total number of message sent
Type
Number

# onConnectionFailure(callback)

Set the callback to call when the connection goes down
Parameters:
Name Type Description
callback function zero parameter function called when connection is down

# onConnectionReestablished(callback)

Set the callback to call when the connection comes back online
Parameters:
Name Type Description
callback function zero parameter function called when the connection comes back online

# onMessage(channel, callback)

Set the callback to call when the user receive a message
Parameters:
Name Type Description
channel string Channel name to listen to
callback onMessageCallbackClient Callback where to receive the message

# (async) send(channel, data)

Send message to server
Parameters:
Name Type Description
channel string Channel name (server need to listen on it with onMessage() )
data * Data to be sent

# setAuthenticationToken()

use this to change your authenticationToken