<div dir="ltr">Sorry, jumped the gun a little based on the subject.<div><br></div><div>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.</div><div><br></div><div>Is it perhaps possible to subscribe to the hangup event and process it asyncronously?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 26 February 2015 at 23:32, Steven Ayre <span dir="ltr"><<a href="mailto:steveayre@gmail.com" target="_blank">steveayre@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">CDR processing should be done in the reporting not hangup state.</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 26 February 2015 at 22:50, Andrew Keil <span dir="ltr"><<a href="mailto:andrew.keil@visytel.com" target="_blank">andrew.keil@visytel.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div lang="EN-AU" link="#0563C1" vlink="#954F72">
<div>
<p class="MsoNormal">To FreeSWITCH users,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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).<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">See below for my simple Lua script called from a diaplan as follows:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><include><u></u><u></u></p>
<p class="MsoNormal"> <!-- To test Lua script --><u></u><u></u></p>
<p class="MsoNormal"> <extension name="ivr_demo"><u></u><u></u></p>
<p class="MsoNormal"> <condition field="destination_number" expression="^(9101)$"><u></u><u></u></p>
<p class="MsoNormal"> <action application="lua" data="myservice.lua"/>
<u></u><u></u></p>
<p class="MsoNormal"> </condition><u></u><u></u></p>
<p class="MsoNormal"> </extension><u></u><u></u></p>
<p class="MsoNormal"></include><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">My question is since FreeSWITCH knows that the HANGUP has taken place why is the ${billsec} not correct (ie. should be 3 seconds)?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I tried adding “session:hangup()” as the first line inside my hangup handler (function myHangupHook(s, status, arg)) and this made no difference.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks in advance for any assistance with this.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Regards,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Andrew Keil<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Simple Lua Script:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-- myservice.lua<u></u><u></u></p>
<p class="MsoNormal">-- To test a simple service<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">function MainService()<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n")<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> -- answer the call<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "ANSWER CALLER\n")<u></u><u></u></p>
<p class="MsoNormal"> session:answer();<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> -- sleep a second<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Sleep for 1000ms\n")<u></u><u></u></p>
<p class="MsoNormal"> session:sleep(1000);<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Playing 12345\n")<u></u><u></u></p>
<p class="MsoNormal"> session:say("12345", "en", "number", "pronounced");<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Finished playing 12345\n")<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> if (session:ready()) then<u></u><u></u></p>
<p class="MsoNormal"> -- hangup<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "HANGUP\n")<u></u><u></u></p>
<p class="MsoNormal"> session:hangup() <u></u><u></u></p>
<p class="MsoNormal"> end<u></u><u></u></p>
<p class="MsoNormal">end<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">--------------------------------------------------------------------------------------------<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-- Functions section …<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">function myHangupHook(s, status, arg)<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "myHangupHook: " .. status .. "\n")<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> -- send hangup event test (after caller hangs up)<u></u><u></u></p>
<p class="MsoNormal"> local event = freeswitch.Event("CUSTOM", "visytel::HANGUP?")<u></u><u></u></p>
<p class="MsoNormal"> event:addHeader("hi", "there")<u></u><u></u></p>
<p class="MsoNormal"> event:addHeader("channel-uuid", channeluuid)<u></u><u></u></p>
<p class="MsoNormal"> -- Add Event consumer if a response is required!<u></u><u></u></p>
<p class="MsoNormal"> local con = freeswitch.EventConsumer("CUSTOM", "visytel::HANGUP!")<u></u><u></u></p>
<p class="MsoNormal"> -- fire event<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Fire HANGUP event\n")
<u></u><u></u></p>
<p class="MsoNormal"> event:fire() <u></u><u></u></p>
<p class="MsoNormal"> -- Wait for 5000ms to test response<u></u><u></u></p>
<p class="MsoNormal"> local retevent = con:pop(1, 5000)<u></u><u></u></p>
<p class="MsoNormal"> if retevent then<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Reply received!\n")<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", string.format("Reply received: %s\n",retevent:getHeader("Result")))<u></u><u></u></p>
<p class="MsoNormal"> end<u></u><u></u></p>
<p class="MsoNormal">end<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-- Setup handlers here<u></u><u></u></p>
<p class="MsoNormal">myparam="empty";<u></u><u></u></p>
<p class="MsoNormal">session:setHangupHook("myHangupHook", "myparam")<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-- Source channel-uuid here {used inside myHangupHook handler and for all fired events inside the header<u></u><u></u></p>
<p class="MsoNormal">channeluuid = session:getVariable("uuid");<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">MainService()<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-- End of lua script<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<br></div></div>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br></blockquote></div><br></div>
</blockquote></div><br></div>