asterisk / node-ari-client

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

Allow events of a child Local channel to fire the listeners registered on its parent #40

Open jaunis opened 8 years ago

jaunis commented 8 years ago

Hello,

I am having a problem with the handling of events triggered by a Local channel, which do not fire the listeners registered on its parent. The problem is a bit complex to explain, I will take an example:

var chan = ari.Channel();
chan.on('Dial', function(event) {
    console.log('Dial received!');
});
chan.originate({
    endpoint: 'Local/exten@context',
    app: 'myApp',
    appArgs: 'foo,bar'
});

The dialplan located at exten@context is doing a Dial to a SIP peer, so I would expect to see Dial received in the console, but it is not happening. However, I can see Dial events coming from the websocket.

After looking more closely at the events and digging through the code, I figured out that this has something to do with the fact that when we originate a Local endpoint, Asterisk actually creates two Local channels connected by a virtual endpoint. And my listener is registered on the first Local channel, but it is the second Local channel which triggers the Dial events.

To be more precise, I register the events on a channel named 123456.789 (for example), but the Dial events are bound to the "child" channel 123456.789;2.

As there is no way to retrieve a reference to the child channel and thus register event handlers on it, I suggest that events bound to the child channel should trigger the listeners registered on the parent channel.

What do you think of that ? I did this modification on my own, I may submit it as a pull request if you will.