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

esl connection event : "esl::event::**(evt {esl.Event})" doesn't return an esl.Event object in the callBack. #17

Closed yaducam2 closed 10 years ago

yaducam2 commented 11 years ago

Hi,

Looking at modesl documentation : https://github.com/englercj/node-esl/wiki/Event-API :

esl::event::**(evt {esl.Event})
esl::event::EVENT_NAME::*(evt {esl.Event}

The two "event catchers" have the same callback definition. However, when i try to use the serialize method on the esl.Event callback

conn.on('esl::event::*', function(e) { 
    console.log(''+e.serialize('json')+'\n');
});

..is processed correctly by the node engine

BUT..

conn.on('esl::event::**', function(e) { 
    console.log(''+e.serialize('json')+'\n');
});

...will return this error :

/home/freeswitch/nodejs_scripts/inbound_server.js:37
        console.log(''+e.serialize('json')+'\n');
                         ^
TypeError: Cannot call method 'serialize' of undefined
    at null.<anonymous> (/home/freeswitch/nodejs_scripts/inbound_server.js:37:19)
    at EventEmitter.emit (/home/freeswitch/node_modules/modesl/node_modules/eventemitter2/lib/eventemitter2.js:332:22)
    at null.<anonymous> (/home/freeswitch/node_modules/modesl/lib/esl/connection.js:503:18)
    at null.<anonymous> (/home/freeswitch/node_modules/modesl/lib/esl/connection.js:117:16)
    at EventEmitter.emit (/home/freeswitch/node_modules/modesl/node_modules/eventemitter2/lib/eventemitter2.js:332:22)
    at Connection._onEvent (/home/freeswitch/node_modules/modesl/lib/esl/connection.js:748:10)
    at EventEmitter.emit (events.js:106:17)
    at Parser._parseEvent (/home/freeswitch/node_modules/modesl/lib/esl/parser.js:190:10)
    at Parser._parseHeaders (/home/freeswitch/node_modules/modesl/lib/esl/parser.js:67:14)
    at Parser._onData (/home/freeswitch/node_modules/modesl/lib/esl/parser.js:34:21)

Is that an issue/regression ?

regards,

Julien

englercj commented 11 years ago

'esl::event::**' will catch auth success and error events, which do not send an event object with it. Maybe this is causing your issue?

EDIT: I have fixed those events to pass along their event objects as well in the latest master, mind trying that and seeing if it fixes the issue?

yaducam2 commented 11 years ago

Hi, thanks for the quick feedback, I would be happy to test.. But I'm pretty new to node.js and i don't know how to updload the latest master. I tried "npm update modesl" but this doesn't update connection.js with the latest changes.. If i manually download & replace connection.js will it be enough to test ?

englercj commented 11 years ago

npm only knows to use what is in the npm registry, what you can go is delete the one you have in your node modules, git clone from this repo into your node modules folder, and npm install the dependencies of the module:

cd node_modules/
rm -rf modesl
git clone https://github.com/englercj/node-esl.git modesl
cd modesl
npm install

You should be able to run normally after that

englercj commented 10 years ago

Closing since this should have been fixed by the change I made.