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

Only getting CHANNEL_EXECUTE_COMPLETE events #66

Closed kieranhackshall closed 7 years ago

kieranhackshall commented 7 years ago

We have been using node-esl on Debian without any issues, however, we needed to run one up on Ubuntu and when we do we are only getting back CHANNEL_EXECUTE_COMPLETE events from Freeswtich.

To start with am just trying to output all events to console via:

conn.on('esl::event::*::**', function(event) {
                eventName = event.getHeader('Event-Name');
                console.log(eventName);
});

The installed nodejs version is 4.2.6, Freeswitch 1.6 and Ubuntu 16.04

Any ideas as to what could be the issue?

englercj commented 7 years ago

Do you make an events call that specifies to FSW which events you want to receive? See #49 where someone had a similar issue.

kieranhackshall commented 7 years ago

Yes I tried conn.events('json', 'all')

Not too sure what was going on so changed line 59 of eslConnection.js to this.reqEvents = ['ALL'] and can see other events.

This is not critical just had to demo something on an Ubuntu server.

Thanks

englercj commented 7 years ago

Hard to say without seeing the full code example, glad you found a solution!

byoungdale commented 7 years ago

I ran into this same issue, and changing eslConnection.js to this.reqEvents = ['ALL'] fixed it. But, previously, I did not have to do this, so there must be something I did different this time. I'll take a look and see what I can find.

byoungdale commented 7 years ago

So, the issue I was having was that I was trying to subscribe or do an events call outside the scope of the new esl.Connection callback. Not sure if this is the same problem @kieranhackshall was having. But, this might help someone else.

If I do this:

const connection = new esl.Connection('127.0.0.1', 8021, 'ClueCon', () => {
  console.log('eslServer connected');
}); // connection

connection.events('json', 'HEARTBEAT');
connection.events('json', 'SESSION_HEARTBEAT');

connection.on('esl::event::HEARTBEAT::*', (evt) => {
  console.log(evt.getType());
});

connection.on('esl::event::SESSION_HEARTBEAT::*', (evt) => {
  console.log(evt.getType());
});

only CHANNEL_EXECUTE_COMPLETE shows up.

But, if I leave my events call inside the scope of the callback for the new esl.Connection connection, everything works. No need to change this.reqEvents to ['ALL'].

const connection = new esl.Connection('127.0.0.1', 8021, 'ClueCon', () => {
  console.log('eslServer connected');

  connection.events('json', 'HEARTBEAT');
  connection.events('json', 'SESSION_HEARTBEAT');

  connection.on('esl::event::HEARTBEAT::*', (evt) => {
    console.log(evt.getType());
  });

  connection.on('esl::event::SESSION_HEARTBEAT::*', (evt) => {
    console.log(evt.getType());
  });

}); // connection
englercj commented 7 years ago

Setting up the listeners (connection.on) outside the callback is totally fine as all that does is register a callback in JS land (no fsw interaction), but connection.events() send messages to freeswitch. If you aren't connected, it can't send those events, and therefore will not work before the ready callback is called.