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@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@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@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@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org