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

Sara Higfler sarahig1985 at gmail.com
Mon May 7 21:10:57 MSD 2012


Hi Michael,

Thanks for your feedback - I'm glad that I hadn't missed anything obvious
via google.    I think I've made good progress with this issue today.  It
seems I can use either of the following to fire the linger command:
       req.linger();
       req.send("linger");

Within the node debug logs I see the following, which confirms the request
was successful.

        7 May 12:55:44 - on_data(Content-Type: command/reply
        Reply-Text: +OK

        Content-Type: command/reply
        Reply-Text: +OK will linger 600 seconds

What has really had me confused was which callback event to be expecting in
the case of linger being invoked.  After further reviewing the partial
examples I could find and looking at the debug traces, it seems I have to
arm the callback on the "esl_disconnect_notice" event.  Within this
callback, I need to check the content-dispostion header to determine if it
is a disconnect or a linger.  I'm using the following code today, which
seems to pick up on every call termination.  It would be good if someone
can confirm if I'm cleaning up appropriately in the two cases (disconnect
and linger).

        req.on('esl_disconnect_notice', function(req)
        {
                switch (req.headers['Content-Disposition'])
                {
                        case 'disconnect':
                                req.end();
                                break;
                         case 'linger':
                                req.exit();
                                break;
                }

console.log('esl_disconnect_notice:'+req.headers['Content-Disposition']);
                return util.log('esl_disconnect_notice');
        });

Thanks again!

On Mon, May 7, 2012 at 3:14 AM, Michael Collins <msc at freeswitch.org> wrote:

> Hi Sara,
>
> Welcome to FreeSWITCH. You are quite right - there is not documentation on
> how to send the linger command with an ESL application. I grep'd around the
> libs/esl directory and found that fs_cli.c and esl.c have a function called
> esl_send_recv and a few occurrences of it used like this:
>
>  esl_send_recv(&handle, "linger");
>
> I'm no Javascript person but if I understand the syntax correctly you'd
> need to do something like this as soon as the call is connected, i.e. right
> before the req.execute("answer") line:
>
> req.send_recv("linger");
>
> Could you give that a try and let us know if it works? If it does we'd
> appreciate you updating the wiki. :)
>
> Thanks,
> MC
>
> On Sat, May 5, 2012 at 12:54 PM, Sara Higfler <sarahig1985 at gmail.com>wrote:
>
>> 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);
>>
>> _________________________________________________________________________
>> Professional FreeSWITCH Consulting Services:
>> consulting at freeswitch.org
>> http://www.freeswitchsolutions.com
>>
>> 
>> 
>>
>> Official FreeSWITCH Sites
>> http://www.freeswitch.org
>> http://wiki.freeswitch.org
>> http://www.cluecon.com
>>
>> FreeSWITCH-users mailing list
>> FreeSWITCH-users at lists.freeswitch.org
>> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
>> http://www.freeswitch.org
>>
>>
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> 
> 
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120507/2d2b32bb/attachment.html 


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