Connector

connector~ Connector

new Connector()

Creates a connection and setups listeners. Also reads options from json file.
Source:

Members

URLString :string

The url to the server
Source:
Type:
  • string

ws :WebSocket

The websocket interface.
Source:
Type:
  • WebSocket

Methods

addEventListener(type, callback)

Add event listener to the websocket interface.
Source:
See:
Parameters:
Name Type Description
type string A websocket event type.
callback connectorCallback The listener that is called when the specified event happens.

close(code, reason)

Closes connection to websocket server
Source:
Parameters:
Name Type Default Description
code number 1000 Status code of why the connection is closing.
reason string I am done. A human readable reason of why the connection is closing.

getURLString()

Return the String of the URL
Source:

isOpen() → {Boolean}

Check if connection is open.
Source:
Returns:
Type:
Boolean
True if websocket is open, otherwise False.

listenToMsg(type, listener)

A method to listen to a specific message type.
Source:
Parameters:
Name Type Description
type string The message type to listen to.
listener connectorCallback The function to call.

reload(newPathString)

Change the server URL
Source:
Parameters:
Name Type Description
newPathString string string with path for new url

removeEventListener(type, callback)

Removes a listener.
Source:
Parameters:
Name Type Description
type string The type of the event.
callback connectorCallback The function to stop listening to the specific event.

request(requestType, responseType, content) → {Promise.<Object>}

Sends a message and listens for the response. A helper method for messages with a request-response structure.
Source:
Parameters:
Name Type Description
requestType string The type of the message send.
responseType string The type of the message to receive.
content Object The payload to send.
Returns:
Type:
Promise.<Object>
- A promise with the response content/

send(type, content, senderopt, prefDestopt)

Send some content to the websocket server.
Source:
Parameters:
Name Type Attributes Default Description
type string The type of the message.
content Object The payload of the message.
sender string <optional>
CLIENT The identifier of the sender.
prefDest string <optional>
null The destination where the message should preferable go.

setUp(pathString)

Sets up the connector.
Source:
Parameters:
Name Type Description
pathString string string of URL for websocket.

waitUntillOpen(callback)

Got form: https://stackoverflow.com/questions/13546424/how-to-wait-for-a-websockets-readystate-to-change
Source:
Parameters:
Name Type Description
callback function is called when websocket is open