[asterisk-users] How to get call progress events from WebSocket connected to Asterisk 12 ARI events API

Jim Fathman jfathman at esi-estech.com
Thu Sep 12 09:54:23 CDT 2013


Hello,

I am experimenting with Asterisk 12.0.0 alpha1.  I have a couple of SIP
phones working.  Good.  I can retrieve data using curl to interact with the
new Asterisk REST API (ARI).  Good.

Now I want to use the new ARI events API, which requires a WebSocket
connection.  I am using Node.js for the client, and have a stable
connection to ARI events on the Asterisk 12 server.

What I hope for is that my Node.js client will receive call related events
in JSON format messages as call activity occurs on the Asterisk server.
 But I don't know how to request this information via the API.

Do I need to specify something in the query string used for the initial
WebSocket connection?  Or do I need to send some kind of event subscription
messages within the WebSocket once connected?

Any guidance, sample client code, or web reference would be most welcome.

Thanks.

Jim

Node.js client connecting to ARI events:

  // app.js

  var WebSocket = require('ws');

  var ws = new WebSocket('ws://192.168.1.125:8088/ari/events?app=node-client
',
    { headers: {
        Authorization: 'Basic Y29tZXQ6MTIzNA=='
      },
      protocol: 'ari',
    });

  ws.on('open', function() {
    console.log('connected');
  });

  ws.on('message', function(message) {
    console.log('received: %s', message);
  });

  ws.on('error', function(err) {
    console.log(err);
  });

It runs and indicates a successful connection:

  $ node app.js
  connected

The Asterisk CLI logs the successful connection:

  == WebSocket connection from '192.168.1.125:34792' for protocol 'ari'
accepted using version '13'
  Creating Stasis app 'node-client'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20130912/d4814ddb/attachment.htm>


More information about the asterisk-users mailing list