Closed mpbanna closed 7 years ago
Depending on the event and whether the channel has entered Stasis, you may have to register for events before they are automatically subscribed to. Can you provide more details or code to show what you are trying to accomplish?
I am trying to originate a call using originate() function, and i bind for 'channelStateChange' , i print originated channel state i.e. logger.log(channel.state) , it printing state as 'Rsrvd', but 'channelStateChange' not emitting . it emitting for some event like 'Ringing', 'Dialing' etc.
my code is :----->
'use strict'; var ari = require('ari-client'); var logger = require('mylogger'); var ARI_HOST = 'xxx.xxx.xxx.xxx'; var ARI_PORT = 1234; var ARI_USER = '***'; var ARI_PASS = '**'; var appName = 'app123'; function ChannelStateChange(event, channel) { logger.log('channel ChannelStateChange:---->', channel.id); logger.log('event:---->', channel.state); } ari.connect('http://' + ARI_HOST + ':' + ARI_PORT, ARI_USER, ARI_PASS, clientLoaded); function clientLoaded(err, client) { if (err) { logger.error(err); } client.on('StasisStart', function (event, channel) { if (channel.dialplan.exten != "") {
logger.log('statsis started !!!!!!!!!!!!!!!!!!!!!');
}
});
client.on('StasisEnd', function (event, channel) {
logger.info('statsis END !!!!!!!!!!!!!!!!!!!!!')
});
client.on('ChannelStateChange', ChannelStateChange);
client.start(appName);
client.channels.originate(
{endpoint: "DAHDI/g0/9876543210", app: appName, appArgs: 'dialed', callerId: '+12343567324'},
function (err, channel) {
if(err){
return console.log(err);
}
channel.on('StasisStart', function (event, channel) {
console.log('StasisStart channel.state:',channel.state);
});
channel.on('ChannelHangupRequest', function (event, channel) {
console.log('ChannelHangupRequest channel.state:',channel.state);
});
channel.on('ChannelDestroyed', function (event, channel) {
console.log('ChannelDestroyed channel.state:',channel.state);
});
console.log('channel-originate state:',channel.state)
console.log('channel-originate with channelId:',channel.id)
}
);
}
With originate
you won't see all events until the channel enters stasis.
You can use something like the following to register for events for the channel, but again, you have to wait for the channel to exist, so you might miss events in between the channel being created and you registering for events:
client.applications.subscribe({
applicationName: appName,
eventSource: 'channel:' + channel.id
})
Another option would be to use client.channels.create
[1] followed by client.channels.dial
[2]. This allows creating a channel which auto subscribes you to events. You can then listen for any event you wish before calling dial
to originate the call.
Feel free to reopen this issue if that doesn't fix your issues.
[1] https://github.com/asterisk/node-ari-client#create-1 [2] https://github.com/asterisk/node-ari-client#dial
'channelStateChange' not emmiting on channel-state-change for event 'Rsrvd' and such more events. Currently i am using Asterisk 14 and using node-ari-client 1.1.0, and also list events name for channelStateChange.
Thanks.