[HC3] Quick Apps – WebSocket client

FIBARO Home Center 3 can act as a WebSocket or WebSocket Secure client.

WARNING: this function is available only on Home Center 3 with firmware 5.041 or higher.

WebSocket class methods

net.WebSocketClient(options)

WebSocketClient class constructor.
WebSocketClient handles ws (WebSocket) connections.

Example

net.WebSocketClientTls(options)

WebSocketClientTls class constructor.
WebSocketClientTls handles wss (WebSocket Secure) connections.

Example

WebSocketClient.addEventListener(eventName, callback), WebSocketClientTls.addEventListener(eventName, callback)

Add a listener for WebSocket events.

Parameters

  • eventName – string with the name of the event to listen to. Possible events names: connected, disconnected, error, dataReceived. Events description is available in the ‘WebSocket events’ section.
  • callback – function that will be called when the event occurs.

Example

WebSocketClient.connect(url), WebSocketClientTls.connect(url)

The method establishes the connection to the specified url.

Parameters

  • url – string containing the URL of the server.

Example

WebSocketClient.send(data), WebSocketClientTls.send(data)

The method for sending data. The connection must be correctly established for proper operation.

Parameters

  • url – string containing url of the server

Example

WebSocketClient.isOpen(), WebSocketClientTls.isOpen()

The method returns true if the socket is open or false if the socket is closed.

Example

WebSocketClient.close(address), WebSocketClientTls.close()

The method closes the connection to the server.

Example

WebSocket events

connected

The event is emitted when the connection is properly established.

Example

disconnected

The event is emitted when either the client or the server closes the socket.

Example

error

The event is emitted when an error occurs. An error can occur while connecting or sending data to the server. The error message is passed as a string to the callback function.

Example

dataReceived

The event is emitted when any data is received by the socket. Received data is passed as a string to the callback function.

Example

October 5, 2020   3527    Tutorials    
Total 5 Votes:
1

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Comments are closed.