asterisk / node-ari-client

Node.js client for ARI. This library is best effort with limited support.
Other
250 stars 98 forks source link

ChannelDestroyed does not work when originate sends to dialplan #97

Closed panitaxx closed 6 years ago

panitaxx commented 6 years ago

Hello,

I have an app that sends to ARI

    let chan = ari.Channel();
    context.channel = chan;
    chan.on('StasisStart', (event, channel) => {
      debug('entering dialplan');
      plan.initialStep.executeStep(context);
    });

    let hangupHandler = function(event){
      debug('channel hanged up %o',event);
      chan.removeAllListeners();
      context.channel = null;
    };
    ari.once('ChannelDestroyed',hangupHandler);
    chan.once('ChannelDestroyed',hangupHandler);
    chan.once('ChannelHangupRequest',hangupHandler);

    debug('Calling extension'+phone);
    chan.originate({
      endpoint: 'SIP/'+phone+'@provider',
      context: 'vcc',
      extension: '1000'
    }).catch((err) => {
      debug('Error originating %o',err);
      this.app.log.warn({ err }, 'Error originating call');
    });

extensions.conf:

[vcc]

exten=>1000,1,Noop()
exten=>1000,n,Stasis(vcc)

This is all done after ari.start resolves. None of the listener gets called when its busy or call is declined. But if originate like this:

chan.originate({
      endpoint: 'SIP/'+phone+'@provider',
      app: 'vcc'
    }

It does call the channel destroyed event listener.

Why is this and how can I make the first way notify of channel hangup?

matt-jordan commented 6 years ago

Channels are typically destroyed after they have left the Stasis dialplan application. By default, your subscription to a channel that enters through the dialplan application only lasts so long as the channel is in the Stasis dialplan application - once it leaves, your subscription is terminated with it. This is in contrast to channels you create yourself. You get a subscription to those that is not tied to the dialplan; hence, you get the destruction event.

If you want to get the ChannelDestroyed events for channels that enter in through the dialplan, you can 'bump' the subscription count using the /subscribe route.

You can find more information about subscribing to resources explicitly here: https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Applications+REST+API

And the wiki also discusses the implicit / explicit subscriptions here: https://wiki.asterisk.org/wiki/display/AST/Introduction+to+ARI+and+Channels#IntroductiontoARIandChannels-ChannelsinaStasisApplication

panitaxx commented 6 years ago

The call is not entering the dialplan. It originates in the Ari but dies there because busy tone. It does not get to the dialplan. Maybe I didn't explain myself but the call originates via originate in node then because it is busy, it does not enter the dialplan. I have a noop and it is not reached.