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

Events function #31

Closed jasonmathew closed 10 years ago

jasonmathew commented 10 years ago

Hi,

Events function returns nothing.

var esl = require('modesl'), conn = new esl.Connection('127.0.0.1', 8021, 'ClueCon', function() {
conn.events('json','all',function(event) { console.log(event.getBody()); }); });

englercj commented 10 years ago

I'm nearly positive the event that comes back for that command has not body. Try outputing the actual event itself:

conn.events('json', 'all', function(event) {
    console.log(event);
});

Because I think it returns just headers and no body, since is it a command/reply event.

peili commented 10 years ago

So how can I listen to events like:

{ headers: [ { name: 'Event-Subclass', value: 'conference::maintenance' }, { name: 'Event-Name', value: 'CUSTOM' }, { name: 'Core-UUID', value: '1006f8f2-eb69-11e3-a55a-85b22b4ff597' }, { name: 'FreeSWITCH-Hostname', value: 'Ubuntu-1404-trusty-64-minimal' }, { name: 'FreeSWITCH-Switchname', value: 'Ubuntu-1404-trusty-64-minimal' }, { name: 'FreeSWITCH-IPv4', value: 'x.x.x.x }, { name: 'FreeSWITCH-IPv6', value: 'x.x.x.x' }, { name: 'Event-Date-Local', value: '2014-06-04 08:00:10' }, { name: 'Event-Date-GMT', value: 'Wed, 04 Jun 2014 06:00:10 GMT' }, { name: 'Event-Date-Timestamp', value: '1401861610613609' }, { name: 'Event-Calling-File', value: 'mod_conference.c' }, { name: 'Event-Calling-Function', value: 'conference_thread_run' }, { name: 'Event-Calling-Line-Number', value: '3060' }, { name: 'Event-Sequence', value: '18360' }, { name: 'Conference-Name', value: '6568068' }, { name: 'Conference-Size', value: '0' }, { name: 'Conference-Ghosts', value: '0' }, { name: 'Conference-Profile-Name', value: 'wideband' }, { name: 'Conference-Unique-ID', value: '7bf5f2ae-ebad-11e3-a703-85b22b4ff597' }, { name: 'Action', value: 'conference-destroy' } ], hPtr: null, type: 'CUSTOM', subclass: 'conference::maintenance', body: '' }

englercj commented 10 years ago

If you take a look at the Event API Wiki page it describes how messages from freeswitch are translated into listenable events.

What you are looking for is:

//tell the connection to send all events
conn.events('json', 'all');

//When an event named "CUSTOM" comes in
conn.on('esl::event::CUSTOM::*', function(event) {
    //do something with this custom event....
    //notice in your example evnet you pasted, that there is no body only headers.
});
peili commented 10 years ago

Thank you.