[Freeswitch-users] Javascript Outbound Event Socket - Linger Command

Sara Higfler sarahig1985 at gmail.com
Sat May 5 23:54:19 MSD 2012


Hi,

I'm a newbie to developing an outbound event handler for Freeswitch.  I'm
looking to use the Javascript ESL implemention (using node.js) and have
managed to get basic scenarios working, including digit collection and
checking against a MySQL database.  One problem I have is the capture of
call termination events in my script.  Having read around a lot, I know
that I'm meant to use the Linger command, but cannot find any examples of
how to do this with a Javascript outbound handler.  I've included the rough
structure of my code below (details removed for brevity) - I would really
appreciate if someone could help show me how I would implement the linger
command to ensure I capture all call termination events.

Kind regards.

(function()
{
        var server, esl;

        esl = require('esl');
        util = require('util');

        server = esl.createCallServer();

 server.on('CONNECT', function(req, res)
 {
         var uri, channel_data, unique_id;

         channel_data = req.body;
         unique_id = channel_data['Unique-ID'];

         req.execute('answer');

         req.execute('playback', 'hello.wav');

                req.on('DTMF', function(req)
                {
                        var digit;
                        var channel_data;
                        channel_data = req.body;

                        digit = channel_data['DTMF-Digit'];
                        console.log('DTMF Received=' + digit);
                        return util.log('DTMF Received');
                });

                req.on('CHANNEL_ANSWER', function(req)
                {
                        return util.log('Call was answered');
                });

                req.on('CHANNEL_HANGUP', function(req)
                {
                        console.log('CHANNEL_HANGUP');
                        return util.log('CHANNEL_HANGUP');
                });
                req.on('CHANNEL_HANGUP_COMPLETE', function(req)
                {
                        console.log('CHANNEL_HANGUP_COMPLETE');
                        return util.log('CHANNEL_HANGUP_COMPLETE');
                });

                req.on('DISCONNECT', function(req)
                {
                         console.log('DISCONNECT');
                         return util.log('DISCONNECT');
                })

      });
      return util.log('CONNECT received');
 });

 server.listen(9123);
}).call(this);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120505/a239b483/attachment.html 


Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list