Skip to content

Instantly share code, notes, and snippets.

@dougbtv
Created April 7, 2017 17:50
Show Gist options
  • Save dougbtv/bef8c442f47c432147ffd9c511d435ca to your computer and use it in GitHub Desktop.
Save dougbtv/bef8c442f47c432147ffd9c511d435ca to your computer and use it in GitHub Desktop.
ARI monkey demo failboat

So here's my results generally.... Using the below extensions.conf and JS file. It's based entirely on the example monkeys playback demo

I originate the call...

0fa669f1fad8*CLI> channel originate LOCAL/123@inbound application wait 1  
    -- Called 123@inbound
    -- Executing [123@inbound:1] NoOp("Local/123@inbound-00000010;2", "Inbound call") in new stack

    -- Executing [123@inbound:2] Answer("Local/123@inbound-00000010;2", "") in new stack

    -- Local/123@inbound-00000010;1 answered

    -- Executing [123@inbound:3] Stasis("Local/123@inbound-00000010;2", "inbound") in new stack

    -- <Local/123@inbound-00000010;2> Playing 'tt-monkeys.ulaw' (language 'en')

[Apr  7 17:46:28] WARNING[459][C-00000011]: res_stasis_playback.c:277 playback_final_update: 1491587187.65: Playback failed for sound:tt-monkeys

[Apr  7 17:46:28] WARNING[455]: res_http_websocket.c:519 ws_safe_read: Web socket closed abruptly
[Apr  7 17:46:28] WARNING[455]: ari/ari_websockets.c:128 ast_ari_websocket_session_read: WebSocket read error: Success
 Deactivating Stasis app 'inbound'
 Shutting down application 'inbound'

  == WebSocket connection from '172.19.0.1:57720' closed

 Destroying Stasis app inbound

And you can see the javascript application totally fails...

$ node check.js 
[ 'This API is using a deprecated version of Swagger!  Please see http://github.com/wordnik/swagger-core/wiki for more info' ]
Monkeys! Attack Local/123@inbound-00000010;2!
Monkeys successfully vanquished Local/123@inbound-00000010;2; hanging them up
Channel Local/123@inbound-00000010;2 just left our application
/home/doug/codebase/vnf-asterisk-controller/node_modules/ari-client/node_modules/bluebird/js/main/async.js:43
        fn = function () { throw arg; };
                           ^

Error: {"message":"Channel not found"}
    at SwaggerRequest.swaggerError [as errorCallback] (/home/doug/codebase/vnf-asterisk-controller/node_modules/ari-client/lib/resources.js:944:19)
    at Object.error (/home/doug/codebase/vnf-asterisk-controller/node_modules/swagger-client/lib/swagger.js:1077:24)
    at EventEmitter.error (/home/doug/codebase/vnf-asterisk-controller/node_modules/swagger-client/lib/swagger.js:1296:19)
    at emitOne (events.js:96:13)
    at EventEmitter.emit (events.js:188:7)
    at emit (/home/doug/codebase/vnf-asterisk-controller/node_modules/shred/lib/shred/request.js:454:21)
    at /home/doug/codebase/vnf-asterisk-controller/node_modules/shred/lib/shred/request.js:473:9
    at setBodyAndFinish (/home/doug/codebase/vnf-asterisk-controller/node_modules/shred/lib/shred/response.js:103:7)
    at IncomingMessage.<anonymous> (/home/doug/codebase/vnf-asterisk-controller/node_modules/shred/lib/shred/response.js:120:7)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

If you originate the call with say application wait 120 -- it works. It's just when the channel is no longer available because the calling party hung up first.

How does one properly handle this case?

/*jshint node: true*/
'use strict';
var ari = require('ari-client');
var util = require('util');
ari.connect('http://172.19.0.3:8088', 'asterisk', 'asterisk', clientLoaded);
// handler for client being loaded
function clientLoaded (err, client) {
if (err) {
throw err;
}
// handler for StasisStart event
function stasisStart(event, channel) {
console.log(util.format(
'Monkeys! Attack %s!', channel.name));
var playback = client.Playback();
channel.play({media: 'sound:tt-monkeys'},
playback, function(err, newPlayback) {
if (err) {
throw err;
}
});
playback.on('PlaybackFinished', playbackFinished);
function playbackFinished(event, completedPlayback) {
console.log(util.format(
'Monkeys successfully vanquished %s; hanging them up',
channel.name));
channel.hangup(function(err) {
if (err) {
throw err;
}
});
}
}
// handler for StasisEnd event
function stasisEnd(event, channel) {
console.log(util.format(
'Channel %s just left our application', channel.name));
}
client.on('StasisStart', stasisStart);
client.on('StasisEnd', stasisEnd);
client.start('inbound');
}
[inbound]
exten => _X.,1,Noop(Inbound call)
same => n,Answer()
same => n,stasis(inbound)
same => n,MixMonitor(test.ulaw)
same => n,Playback(demo-congrats)
same => n,Hangup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment