RTC

In order to use Jexia's realtime functionality using the Websocket protocol, you will need to create a Websocket object. The Websocket constructor has one required parameter which is the URL. For further information about Websocket consult the Websocket documentation.

Creating a websocket object

In order to establish the Websocket connection,  create a Websocket object

let webSocket = new WebSocket("wss://YOUR_PROJECT_ID.app.jexia.com/rtc?access_token=YOUR_TOKEN");

Sending data to the server

Once the connection is established you can subscribe to events. Call the the Websocket object 's send() method in order to do this:

webSocket.send(  "type": "command",
  "data" : {
    "command":   "subscribe",
    "arguments": {
      "action":    [ "created", "updated", "deleted" ],
      "resource":  {
        "type":      "ds",
        "name":      "mydataset"
      }
    }
  }
})

Receiving the response

When messages are received, a message event is sent to the Websocket object. In order to listen to the event, use the onmessage event handler.

webSocket.onmessage = function(event) {
	console.log(event.data)
}

The output will be something like this. In this example the event fires when a new record is created in Dataset. For update and delete, the value of action will change to "updated" or "deleted" 

{
  "type": "event",
  "data": {
    "action": "created",
    "resource": {
      "name": "mydataset",
      "type": "ds"
    },
    "modifier": {
      "id": "cb3a519e-c173-4aee-a8e2-11b93cadc033"
    },
    "timestamp": "2019-02-12T13:34:29Z",
    "data": [{
      "id": "1603087e-44a5-4d19-bff0-6b5713845c15"
    }]
  }
}

It's not possible to subscribe to a related resource