Qubicle Websockets Setup
Introduction
This document will get a basic Websockets connection set up to the Qubicle event feed.
Prerequisites
In order for the Websocket connections to work correctly, the Blackhole application must be started and the bh_qubicle module must be present and loaded.
Initiate Websocket connection
Set up the Websocket connection to Blackhole
var ws = new WebSocket("ws://{SERVER}:5555");
// Connection Open Callback
ws.onopen = function() {
console.log("Websocket connection is open.");
}
Subscribe to Qubicle events via Websocket
Once the connection is successfully opened you must use a valid auth token to subscribe to Qubicle events. In this example a convenience function is created to help with the JSON formatting.
// Log Websocket data to console
ws.onmessage = function(ws_data) {
var msg = JSON.parse(ws_data.data);
console.log(ws_data.data);
}
function send(json) {
ws.send(JSON.stringify(json));
}
// Subscribe for session events
send({"action":"subscribe", "auth_token": "{AUTH_TOKEN}", "data":{"account_id": "{ACCOUNT_ID}", "binding": "qubicle.session"}});
// Subscribe for recipient events
send({"action":"subscribe", "auth_token": "{AUTH_TOKEN}", "data":{"account_id": "{ACCOUNT_ID}", "binding": "qubicle.recipient"}});
// Subscribe for queue events
send({"action":"subscribe", "auth_token": "{AUTH_TOKEN}", "data":{"account_id": "{ACCOUNT_ID}", "binding": "qubicle.queue"}});