englercj / node-esl

FreeSWITCH ESL implementation for Node.js; implements the full Event Socket Library specified in: http://wiki.freeswitch.org/wiki/Esl
http://englercj.github.com/node-esl/
MIT License
170 stars 111 forks source link

Either a problem with event subscriptions or a help request #49

Closed lafar6502 closed 8 years ago

lafar6502 commented 8 years ago

I have some strange problem with receiving events from Freeswitch. The code below is not going to receive any events, apart from CHANNEL_EXECUTE_COMPLETE (which is used internally by the library) I have to change this line

conn.events('json', ['CUSTOM', 'CHANNEL_ANSWER', 'CHANNEL_HANGUP', 'CHANNEL_DESTROY'], function() { }

into

conn.events('json', 'all', function() {}

in order to be able to receive any of the events listed above. But with 'all' i'm getting all other, unnecessary events which is just wasting the CPU/network bandwidth. Can you please tell me what is the cause of events not being received when subscribing only to some types, and how to do it correctly?

Here's the code

var conn = new esl.Connection(cfg.fsAddress, cfg.fsPort, cfg.fsPassword);
var evcnt = 0;
conn.on('esl::ready', function() {
    log.info('ESL Connected', arguments);
    conn.events('json', ['CUSTOM', 'CHANNEL_ANSWER', 'CHANNEL_HANGUP', 'CHANNEL_DESTROY'], function() {
        log.info('Subscribed to some events', arguments);
    });

    _conn = conn;
    me.emit('connected', me);
})
.on('esl::end', function() {
        console.log('**** CONNECTION END END ****', arguments);
        log.info('CONNECTION END', arguments);
        conn.disconnect();
        _conn = null; 
        if (!retryScheduled) {
            setTimeout(initConn, 15000);
            retryScheduled = true;
        };
        me.emit('disconnected', me);
})
.on('error', function() {
    console.log('**** CONNECTION ERROR, WILL RETRY **** ', arguments);
    log.info('CONNECTION ERROR ', arguments);
    _conn = null;
    if (!retryScheduled) {
        setTimeout(initConn, 15000);
        retryScheduled = true;
    };
    me.emit('disconnected', me);
})
.on('esl::event::**', function(ev,h,bd) {
    var id = evcnt++;
    var n = ev.getHeader('Event-Name');
    log.info('ESL EVT', id, n);
    handleFSEvent(ev, conn);
});
lafar6502 commented 8 years ago

FYI the problem was in the CUSTOM event - it requires a subclass CHANNEL_ANSWER', 'CHANNEL_HANGUP', 'CHANNEL_DESTROY', 'CHANNEL_ORIGINATE', 'CUSTOM MyEvents::DTMFConfirm