Code Monkey home page Code Monkey logo

Comments (3)

samuelg avatar samuelg commented on September 26, 2024

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?

from node-ari-client.

mpbanna avatar mpbanna commented on September 26, 2024

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)
    }
); 

}

from node-ari-client.

samuelg avatar samuelg commented on September 26, 2024

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

from node-ari-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.