I checked from swagger http://ari.asterisk.org/ that the GET and POST methods are working
but the StasisStart event can not be started in any way. I have tried running code samples given by @vallo earlier, For example, I get below output if I run the channel-dump code by running command: node example.js:
root@Sandeep-PC:/var/www/html/ari/channel-dump# node example.js
[ 'This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info' ]
No channels currently :-(
Unhandled rejection Error: Connection attempts exceeded WebSocketMaxRetries. unexpected server response (404)
at reconnect (/var/www/html/ari/node_modules/ari-client/lib/client.js:539:16)
at WebSocket.processError (/var/www/html/ari/node_modules/ari-client/lib/client.js:522:7)
at emitOne (events.js:116:13)
at WebSocket.emit (events.js:211:7)
at ClientRequest.response (/var/www/html/ari/node_modules/ws/lib/WebSocket.js:721:12)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:544:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:117:17)
at Socket.socketOnData (_http_client.js:440:20)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
example.js file:
/*jshint node:true*/
'use strict';
var ari = require('ari-client');
var util = require('util');
ari.connect('http://localhost:8088', 'asterisk', 'asterisk', clientLoaded);
// handler for client being loaded
function clientLoaded (err, client) {
if (err) {
throw err;
}
client.channels.list(function(err, channels) {
if (!channels.length) {
console.log('No channels currently :-(');
} else {
console.log('Current channels:');
channels.forEach(function(channel) {
console.log(channel.name);
});
}
});
// handler for StasisStart event
function stasisStart(event, channel) {
console.log(util.format(
'Channel %s has entered the application', channel.name));
// use keys on event since channel will also contain channel operations
Object.keys(event.channel).forEach(function(key) {
console.log(util.format('%s: %s', key, JSON.stringify(channel[key])));
});
}
// handler for StasisEnd event
function stasisEnd(event, channel) {
console.log(util.format(
'Channel %s has left the application', channel.name));
}
client.on('StasisStart', stasisStart);
client.on('StasisEnd', stasisEnd);
client.start('channel-dump');
}
The output I get in asterisk console is as below:
<--- Sending ARI response to 127.0.0.1:33728 --->
404 Not Found
<--- ARI request received from: 127.0.0.1:33728 --->
Connection: Upgrade
Upgrade: websocket
Content-type: application/json
Host: localhost:8088
{
Sec-WebSocket-Version: 13
"message": "Resource not found"
Sec-WebSocket-Key: MTMtMTU0MTg3ODcyMTY1MA==
}
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
app: channel-dump
api_key: asterisk:asterisk
body:
<--- Sending ARI response to 127.0.0.1:33728 --->
404 Not Found
Content-type: application/json
{
"message": "Resource not found"
}
Sandeep-PC*CLI>
my extension.conf contains:
[default]
exten => 1000,1,NoOp()
same => n,Answer()
same => n,Playback(hello-world)
same => n,Stasis(channel-dump)
same => n,Hangup()