<div dir="ltr"><div>Hello,</div><div><br></div><div>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.</div>
<div><br></div><div>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.</div><div><br>
</div><div>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.</div>
<div><br></div><div>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?</div><div>
<br></div><div>Any guidance, sample client code, or web reference would be most welcome.</div><div><br></div><div>Thanks.<br></div><div><br></div><div>Jim</div><div><br></div><div>Node.js client connecting to ARI events:</div>
<div><br></div><div> // app.js</div><div><br></div><div> var WebSocket = require('ws');</div><div><br></div><div> var ws = new WebSocket('ws://<a href="http://192.168.1.125:8088/ari/events?app=node-client">192.168.1.125:8088/ari/events?app=node-client</a>',</div>
<div> { headers: {</div><div> Authorization: 'Basic Y29tZXQ6MTIzNA=='</div><div> },</div><div> protocol: 'ari',</div><div> });</div><div><br></div><div> ws.on('open', function() {</div>
<div> console.log('connected');</div><div> });</div><div><br></div><div> ws.on('message', function(message) {</div><div> console.log('received: %s', message);</div><div> });</div><div><br>
</div><div> ws.on('error', function(err) {</div><div> console.log(err);</div><div> });</div><div><br></div><div>It runs and indicates a successful connection:</div><div><br></div><div> $ node app.js </div><div>
connected</div><div><br></div><div>The Asterisk CLI logs the successful connection:</div><div><br></div><div> == WebSocket connection from '<a href="http://192.168.1.125:34792">192.168.1.125:34792</a>' for protocol 'ari' accepted using version '13'</div>
<div> Creating Stasis app 'node-client'</div><div><br></div></div>