asterisk / node-ari-client

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

Issue in 'StasisStart' event #96

Closed mpbanna closed 6 years ago

mpbanna commented 6 years ago

Hello, I have face a new issue that is when i originate call by ari.channels.create() function then event named 'StasisStart' will fire when phone picked , But when i originate a call by create() + dial(), then event named 'StasisStart' will not fire when phone picked, but fired when dial() function execute.

matt-jordan commented 6 years ago

I don't understand your question. Can you provide some code that demonstrates the scenario?

mpbanna commented 6 years ago

'use strict'; var ari = require('ari-client'); var logger = require('mylogger'); var ARI_HOST = 'XXX.XXX.XXX.XXX'; var ARI_PORT = 8363; var ARI_USER = 'XXXXXXXX'; var ARI_PASS = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; var appName = '91XXXXXXXXX';

function loadProcess() {

ari.connect('http://' + ARI_HOST + ':' + ARI_PORT, ARI_USER, ARI_PASS, clientLoaded);
function clientLoaded(err, client) {
    if (err) {
        logger.error(err);
    }
    var agent_number = '946XXXXXXX';
    var channelMain1 = client.Channel();
    channelMain1.on('StasisStart', function (event, channel) {
        logger.log('statisStart actually 2')
    });
    channelMain1.create(
            {app: appName, endpoint: "SIP/V19/" + agent_number, callerId: '+911XXXXXXXX},
            function (err, channel) {

                logger.log('call originating with channelId:', channel.id);

                client.channels.dial(
                        {channelId: channel.id},
                        function (err) {
                            if (err) {
                                return logger.error('dial err:', err)
                            }
                            logger.log('call dialed sussccessfully.....')

                        }
                );

            }
    );
    client.on('StasisStart', function (event, channel) {
        logger.log('statisStart client')
    });
    client.on('StasisEnd', function (event, channel) {
        logger.info('statsis END  !!!!!!!!!!!!!!!!!!!!!')

    });

    client.start(appName);

}

}

loadProcess();

mpbanna commented 6 years ago

In above code 'StasiStart' event not fired when phone pick by user, as i know it should fired when phone pick.

mpbanna commented 6 years ago

is any solution found ??

jcolp commented 6 years ago

This is not a bug. Using the two stage dialing of creating and dialing immediately sends the channel into the Stasis application, even when they haven't answered. This allows you to do things to the channel before dialing it[1]. You would need to examine the events from the channel to know when it is answered or has been rejected.

[1] http://blogs.asterisk.org/2016/08/24/asterisk-14-ari-create-bridge-dial/

buscseik commented 6 years ago

Did you try to use channelMain1.originate() instead of create?