[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 01:50:36 MSK 2015
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20150226/48a00acc/attachment-0001.html
Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users
mailing list