Skip to content

Instantly share code, notes, and snippets.

@ryanquinlan
Created January 11, 2019 18:19
Show Gist options
  • Save ryanquinlan/35724c07e5cc96ed8d77949ffa688446 to your computer and use it in GitHub Desktop.
Save ryanquinlan/35724c07e5cc96ed8d77949ffa688446 to your computer and use it in GitHub Desktop.
const WebSocket = require('ws');
const util = require('util')
console.log("Starting...")
const ws = new WebSocket('ws://localhost:10000',
{
rejectUnauthorized: false
});
const sub = {"type": "message","message": {"messageId": 8,"type": "subscribeRequest","subscriptions": [{"index": 3,"type": "calls","elements": ["name","participants"]}]}}
ws.on('connection', function (ws) {
console.log("WS Connected");
});
ws.on('open', function open() {
ws.send(JSON.stringify(sub));
});
ws.on('message', function incoming(data) {
console.log(data);
//Implement a function to ACK messages from server
});
ws.on('error', function incoming(error) {
console.log("ERROR!")
console.log(util.inspect(error, true, null));
});
@ngockham12312
Copy link

I want to monitor callRoster but i don't know the format of "const sub" . plz help me, I want one example.

@ryanquinlan
Copy link
Author

@ngockham12312

If you haven't looked already you'll want to check out the official docs here

Page 6. Starts the description of the three types you can subscribe to. callInfo, callRoster, and calls
Page 20. Actually has an example of a subscribe message that is subscribing to the callRoster for a call.

{
  "index": 1,
  "type": "callRoster",
  "call": "97c771ae-fc2e-4257-b129-30ee818e034b",
  "elements": [
    "name",
    "uri",
    "state",
    "importance"
  ]
}

The docs don't call out the model of the objects explicitly, but you can infer how to construct the subscribe messages by looking at the tables on Page 6. The table name is your type, all the types can be passed a call in the root of the object, and anything listed as "Subscribable elements" can be placed in the elements array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment