Skip to content

API reference

Oğuz Eroğlu edited this page Dec 31, 2019 · 1 revision

API reference

Public APIs:

init

Parameter is an object containing these properties:

protocolDefinitionPath

Path of the protocol definition JSON file. Mandatory for both server and client.

workerPath

Path of the RhubarbWorker JS file. Mandatory for client.

isServer

A boolean specifies wheter the Rhubarb will be used a server or a client. Default is false.

serverAddress

The WebSocket URL of the server. Mandatory for client.

serverListenPort

The port which the server listens. Mandatory for server.

onReady

A callback function executed when the Rhubarb is initialized. Mandatory for client.

onError

A callback function executed with error parameter when an error occurs while initializing Rhubarb. Mandatory for client.

send

Expects three parameters:

protocolName

The protocol name as defined in protocol-definition JSON file. This parameter is mandatory

valuesByParameterName

An object containing values by parameter names as defined in protocol-definition JSON file. This parameter is mandatory

clientID

The ID of client which the server sends the message to. Mandatory for the server.

onReceived

Expects two parameters:

protocolName

The protocol name as defined in protocol-definition JSON file. This parameter is mandatory

callback

A callback function executed with getter and clientID parameters when the message is received:

  • getter: A function expects a protocol parameter name as input and returns received value for that parameter.
  • clientID: (For servers only): The unique client ID representing the client sent the message to server.

This parameter is mandatory.

onDisconnectedFromServer

Expects one parameter:

callback

A function that is executed when the client disconnects from a server.

onClientConnected

Expects one parameter:

callback

A function that is executed with clientID parameter when a client connects to the server. The clientID is the unique identifier of the connected client.

onClientDisconnected

Expects one parameter:

callback

A function that is executed with clientID parameter when a client disconnects from the server. The clientID is the unique identifier of the connected client.

onLatencyUpdated

Expects one parameter:

callback

A function that is executed with the new latency (a float) when the latency between the server and the client is updated.

destroy

Expects no parameter. Destroys the Rhubarb context and removes all connections.