[Freeswitch-users] Re- FreeSWITCH CDRs ${billsec} not correct when using Lua scripts and running a hangup handler with any delays inside it

Andrew Keil andrew.keil at visytel.com
Fri Feb 27 05:27:27 MSK 2015


Steven,

Many thanks for your fast response.  I understand what you are saying, however even when I add “session:hangup()” as the first line inside my hangup handler (function myHangupHook(s, status, arg)), that is prior to the pause of 5 seconds waiting for an event that never comes (at the moment) the resulting CDRs are based on when the Lua script completes (it seems) and not when the call disconnects.  I fully understand that this is a two way conversation (ie. Remote Disconnect received then Release sent and Release Complete received).

Does this mean there is no way (within Lua under FreeSWITCH) to clear up a call correctly, then complete some extra code within the Lua script, then end the Lua script and generate correct CDRs from within FreeSWITCH?

Regarding subscribing to the HANGUP event or using the Lua script to fire events to a third party application I will be looking into this, however I thought I would first ask if I was missing something within FreeSWITCH.

One more question is there a FreeSWITCH action to correctly release the call apart from session:hangup() {which obviously does not work when the remote end disconnects first}?

I am more than happy to experiment with any ideas.

Andrew

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Steven Ayre
Sent: Friday, 27 February 2015 10:47 AM
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] Re- FreeSWITCH CDRs ${billsec} not correct when using Lua scripts and running a hangup handler with any delays inside it

Sorry, jumped the gun a little based on the subject.

A more relevant answer is that during the hangup state the call is still in the process of hanging up, it isn't hung up and ended until the hangup_complete event. So your 5s sleep is extending the life of the call.

Is it perhaps possible to subscribe to the hangup event and process it asyncronously?

On 26 February 2015 at 23:32, Steven Ayre <steveayre at gmail.com<mailto:steveayre at gmail.com>> wrote:
CDR processing should be done in the reporting not hangup state.

On 26 February 2015 at 22:50, Andrew Keil <andrew.keil at visytel.com<mailto:andrew.keil at visytel.com>> wrote:
To FreeSWITCH users,

I am currently experimenting with Lua scripts on FreeSWITCH (latest build) and found an interesting issue with FreeSWITCH default CDRs (inside log/cdr-csv/1000.csv).

See below for my simple Lua script called from a diaplan as follows:

<include>
    <!-- To test Lua script  -->
    <extension name="ivr_demo">
      <condition field="destination_number" expression="^(9101)$">
                                <action application="lua" data="myservice.lua"/>
      </condition>
    </extension>
</include>

What I noticed is that placing a call into FreeSWITCH via a SIP phone (calling 9101) and landing on myservice.lua everything processes as expected.  If I hangup after 3 seconds then I should expect the CDR to show ${billsec} = 3.  However this is not the case since both ${duration} and ${billsec} are actually set once the Lua script completes (not based on HANGUP).  So inside 1000.csv I see duration and billsec both having 8 seconds.

You will see below that inside my hangup handler (function myHangupHook(s, status, arg)) I fire an event and wait up to 5000ms for an event to be returned (currently I am not returning an event so the 5000ms will take place).  This explains the extra 5 seconds after the 3 seconds of the call.

My question is since FreeSWITCH knows that the HANGUP has taken place why is the ${billsec} not correct (ie. should be 3 seconds)?

I tried adding “session:hangup()” as the first line inside my hangup handler (function myHangupHook(s, status, arg)) and this made no difference.

Is there a solution to this issue?  Perhaps there is a different CDR variable that will contain the correct duration based on when HANGUP was actually received.

Thanks in advance for any assistance with this.

Regards,

Andrew Keil


Simple Lua Script:

-- myservice.lua
-- To test a simple service

function MainService()
                freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n")

                -- answer the call
                freeswitch.consoleLog("INFO", "ANSWER CALLER\n")
                session:answer();

                -- sleep a second
                freeswitch.consoleLog("INFO", "Sleep for 1000ms\n")
                session:sleep(1000);

                freeswitch.consoleLog("INFO", "Playing 12345\n")
                session:say("12345", "en", "number", "pronounced");
                freeswitch.consoleLog("INFO", "Finished playing 12345\n")

                if (session:ready()) then
                                -- hangup
                                freeswitch.consoleLog("INFO", "HANGUP\n")
                                session:hangup()
                end
end


--------------------------------------------------------------------------------------------


-- Functions section …

function myHangupHook(s, status, arg)
    freeswitch.consoleLog("INFO", "myHangupHook: " .. status .. "\n")

    -- send hangup event test (after caller hangs up)
    local event = freeswitch.Event("CUSTOM", "visytel::HANGUP?")
                event:addHeader("hi", "there")
                event:addHeader("channel-uuid", channeluuid)
                -- Add Event consumer if a response is required!
                local con = freeswitch.EventConsumer("CUSTOM", "visytel::HANGUP!")
    -- fire event
    freeswitch.consoleLog("INFO", "Fire HANGUP event\n")
    event:fire()
                -- Wait for 5000ms to test response
                local retevent = con:pop(1, 5000)
                if retevent then
                                freeswitch.consoleLog("INFO", "Reply received!\n")
                                freeswitch.consoleLog("INFO",  string.format("Reply received: %s\n",retevent:getHeader("Result")))
                end
end

-- Setup handlers here
myparam="empty";
session:setHangupHook("myHangupHook", "myparam")

-- Source channel-uuid here {used inside myHangupHook handler and for all fired events inside the header
channeluuid = session:getVariable("uuid");

MainService()


-- End of lua script


_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting at freeswitch.org<mailto:consulting at freeswitch.org>
http://www.freeswitchsolutions.com

Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org<mailto: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/20150227/f715a4c9/attachment-0001.html 


Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list