ari.once('StasisStart', listener not working second time

I found this example here:

This example shows how a call can be originated from a channel entering a
Stasis application to an endpoint. The endpoint channel will then enter the
Stasis application and the 2 channels will be placed into a mixing bridge.

It works, but the problem is after I hangup the extension, if I try to call again, then nothing happens because the event StasisStart listener is unregistered.

How can I change that so that if I call again, StasisStart will fire again? Should I try ari.on instead of ari.once? Ideas please.

client.connect(‘http://localhost:8088’, ‘asterisk’, ‘asterisk’,

function (err, ari) {

// Use once to start the application to ensure this listener will only run
// for the incoming channel
ari.once(‘StasisStart’,
/**
* Once the incoming channel has entered Stasis, answer it and originate
* call to the endpoint (outgoing channel).
*/
function (event, incoming) {

incoming.answer(function (err) {
  originate(incoming);
});

});

I think I figured out.

Instead of .once, use .on
And inside ari StasisStart callback, add a check if (event.args[0] != ‘dialed’) { to make sure endpoint is valid.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.