1. Home
  2. Sorce Documentation
  3. Libraries
  4. Javascript – Core functions

Javascript – Core functions

RemoteMe class

 

Configuring, monitor connection, sending messages. These are the core functions and you should import all of dependencies at all your RemoteMe Pages.

The messages are sent and connection is established based on current session. If You want to use it without login, please checkout custom websocket URL [TODO address for websocket to connect using token]

sourceCode

Prepare:
Html imports
Constructor
constructor

params json file:

  • automaticlyConnectWS : true|false if weboscket should be automaticly connected
  • automaticlyConnectWebRTC: true|false if webrtc should be connected automaticly
  • webSocketConnectionChange : function(WebsocketConnectingStatusEnum)
  • webRtcConnectionChange: function(WebrtcConnectingStatusEnum)
  • onUserMessage:undefined: function(senderDeviceId,data)
  • onUserSyncMessage:undefined: function(senderDeviceId,data)
Example of use:

 

Structures
ConnectingStatusEnum

Enum to with webRTC and websocketstatuses

 

Functions
isWebSocketConnected()

returns true if websocket connection is open and ready for use, if not false

connectWebSocket()

connect websocket. This function its called automatically if configuration passed at constructor as

restartWebSocket()

if websocket connection is open then its disconnecting, and connecting again after 1s

if there is no open websocket connection, websocket connection is establishing

disconnectWebSocket()

disconnect websocket if its connected. Do nothing if there is no open websocket connection

isWebRTCConnected()

returns true if webrtc connection is open and ready for use, if not false

connectWebRTC()

 

established webrtc connections.

To call this function websocket connection has to be open and ready to use

This function its called automaticly if configuration passed at contructor has

restartWebRTC()

if webrtc connection is open then its disconnecting, and connecting again

disconnectWebRTC()

 

disconnect webrtc if its connected. Do nothing if there is no open websocket connection

sendUserMessage(receiveDeviceId, data)

its equal to method sendUserMessageByFasterChannel()

parameters:

  • receiveDeviceId deviceId where message should be sned
  • data – String , RemoteMeData, ArrayBuffer, Uint8Array or Arrays are can be used

check sendWebRtc or sendWebSocket

if there is direct connection its uses direct connection, if there is webrtc its using webrtc, then webscoekt is check and used and if there is noprevious connecitons its using rest api to send message.

If other then direct or webrtc connection is used, the max amount of send message is 90 per minute.

sendUserMessageWebsocket(receiveDeviceId, data)

parameters:

  • receiveDeviceId: deviceId where message should be delivered
  • data – String , RemoteMeData, ArrayBuffer, Uint8Array or Arrays are can be used

 

example of use:

Caution:

Do not call this function lot of times at short time period, for example at onMouseMove. For onMouseMove and similar cases please use  Control.js

sendUserMessageWebrtc(receiveDeviceId, data)

parameters:

  • receiveDeviceId: deviceID where message should be delivered
  • data: String , RemoteMeData, ArrayBuffer, Uint8Array or Arrays are can be used

sending user message (TODO add link to help) by webrtc connection

example of use:

checkout sendUserMessageWebsocket example of use

sendUserMessageRest(receiveDeviceId, data)

parameters:

  • receiveDeviceId: deviceId where message should be delivered
  • data: String , RemoteMeData, ArrayBuffer, Uint8Array or Arrays are can be used

sending user message (TODO add link to help) by REST API connection. There is no need to have open websocketConnection or webrtc, its sent using POST http method. Using REST API [TODO add link to rest api documentation]

example of use:

checkout sendUserMessageWebsocket example of use

sendUserSyncMessage(receiveDeviceId, data,responseFunction)

parameters:

  • receiveDeviceId: deviceId where message should be delivered
  • data: data to send it can be byteArray or Hex representation of message
  • responseFunction(output: Uint8Array)

sendUserSyncMessages and waits for reponse, if reponse is got responseFunction is called

afterWebSocketConneced(functionToCall)

parameters:

  • functionToCall: function to call if websocekt conenctions is established

If websocket is already established functionToCall is called by 0ms timeout

Events
webSocketConnectionChange : function(WebsocketConnectingStatusEnum)

this function is called with argument WebsocketConnectingStatusEnum  (describes above at structures paragraph ) whenever websocket connection has been changed – checkout constructor example above

webRtcConnectionChange : function(WebrtcConnectingStatusEnum)

this function is called with argument WebrtcConnectingStatusEnum  (describes above at structures paragraph ) whenever webRTC connection has been changed – checkout constructor example above

onUserMessage: function(senderDeviceId,data)

this function is called when userMessage will be sent to this script

parameters:

  • senderDeviceId: deviceID which sent message
  • data: massage data its byteArray

example of use:

 

onUserSyncMessage: function(senderDeviceId,data)

this function is called when userMessageSync will be sent to this script. Function needs to return data which will be passed to the caller

parameters:

  • senderDeviceId: deviceId which sent message
  • data: massage data its byteArray

example of use: