Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
To FreeSWITCH Users, See below for a sample template for a Lua Service Script running inside FreeSWITCH. The issue I have is fairly straightforward. I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end. The problem I am having is if the caller hangs up during the playback of "intro.wav" (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play "info.wav", unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call. My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc.... So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time! I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution. FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use "if (session:ready()) then ...." or "if (not session:ready()) then goto HANGUPEXIT end" makes the code ugly. Thanks in advance, Andrew Keil Visytel Pty Ltd ------------------------------------------------------------------------------ Sample Lua Service ----------------------------------------------------------------------- -- Lua template for FreeSWITCH service -- By: Andrew Keil (Visytel Pty Ltd) -- Email: support@visytel.com -- Setup script wide variables here function PreAnswer() freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n"); -- Add your pre answer code from here -- End of your pre answer code freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n"); end function AnswerCaller() session:answer() session:sleep(1000) end function MainService() freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n"); if (session:ready()) then -- Note (1): If you wish to end the call then simply use: goto ENDSERVICE -- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end -- Add your main service code from here (caller would have been answered) session:streamFile("intro.wav") if (not session:ready()) then goto HANGUPEXIT end session:streamFile("info.wav") if (not session:ready()) then goto HANGUPEXIT end session:streamFile("outro.wav") if (not session:ready()) then goto HANGUPEXIT end -- End of your main service code end ::ENDSERVICE:: if (session:ready()) then -- End of service so hangup session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage end goto END ::HANGUPEXIT:: freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n"); ::END:: freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n"); end function CleanUp() freeswitch.consoleLog("INFO", "CLEANUP SECTION\n"); -- Add your cleanup code from here (caller would have been disconnected) -- End of your cleanup code freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n"); end function myHangupHook(s, status, arg) session:hangup() CleanUp() -- Run CleanUp function now since the caller has disconnected end -- Setup Hangup event handler here v_hangup = "HANGUP" session:setHangupHook("myHangupHook", "v_hangup") -- Call service functions in order PreAnswer() AnswerCaller() MainService() -- End of Lua service
See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back. On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
To FreeSWITCH Users,
See below for a sample template for a Lua Service Script running inside FreeSWITCH.
The issue I have is fairly straightforward.
I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end.
The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call.
My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc….
So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time!
I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution.
FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “*if (session:ready()) then ….”* or “*if (not session:ready()) then goto HANGUPEXIT end”* makes the code ugly.
Thanks in advance,
Andrew Keil
*Visytel Pty Ltd*
------------------------------------------------------------------------------ Sample Lua Service -----------------------------------------------------------------------
-- Lua template for FreeSWITCH service
-- By: Andrew Keil (Visytel Pty Ltd)
-- Email: support@visytel.com
-- Setup script wide variables here
function PreAnswer()
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n");
-- Add your pre answer code from here
-- End of your pre answer code
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n");
end
function AnswerCaller()
session:answer()
session:sleep(1000)
end
function MainService()
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n");
if (session:ready()) then
-- Note (1): If you wish to end the call then simply use: goto ENDSERVICE
-- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end
-- Add your main service code from here (caller would have been answered)
session:streamFile("intro.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("info.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("outro.wav")
if (not session:ready()) then goto HANGUPEXIT end
-- End of your main service code
end
::ENDSERVICE::
if (session:ready()) then
-- End of service so hangup
session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage
end
goto END
::HANGUPEXIT::
freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n");
::END::
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n");
end
function CleanUp()
freeswitch.consoleLog("INFO", "CLEANUP SECTION\n");
-- Add your cleanup code from here (caller would have been disconnected)
-- End of your cleanup code
freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n");
end
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
-- Call service functions in order
PreAnswer()
AnswerCaller()
MainService()
-- End of Lua service
_________________________________________________________________________ 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
Thanks for your response. I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script. I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great. Andrew From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Abaci B Sent: Saturday, 27 February 2016 1:29 AM To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back. On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com<mailto:andrew.keil@visytel.com>> wrote: To FreeSWITCH Users, See below for a sample template for a Lua Service Script running inside FreeSWITCH. The issue I have is fairly straightforward. I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end. The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call. My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc…. So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time! I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution. FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “if (session:ready()) then ….” or “if (not session:ready()) then goto HANGUPEXIT end” makes the code ugly. Thanks in advance, Andrew Keil Visytel Pty Ltd ------------------------------------------------------------------------------ Sample Lua Service ----------------------------------------------------------------------- -- Lua template for FreeSWITCH service -- By: Andrew Keil (Visytel Pty Ltd) -- Email: support@visytel.com<mailto:support@visytel.com> -- Setup script wide variables here function PreAnswer() freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n"); -- Add your pre answer code from here -- End of your pre answer code freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n"); end function AnswerCaller() session:answer() session:sleep(1000) end function MainService() freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n"); if (session:ready()) then -- Note (1): If you wish to end the call then simply use: goto ENDSERVICE -- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end -- Add your main service code from here (caller would have been answered) session:streamFile("intro.wav") if (not session:ready()) then goto HANGUPEXIT end session:streamFile("info.wav") if (not session:ready()) then goto HANGUPEXIT end session:streamFile("outro.wav") if (not session:ready()) then goto HANGUPEXIT end -- End of your main service code end ::ENDSERVICE:: if (session:ready()) then -- End of service so hangup session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage end goto END ::HANGUPEXIT:: freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n"); ::END:: freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n"); end function CleanUp() freeswitch.consoleLog("INFO", "CLEANUP SECTION\n"); -- Add your cleanup code from here (caller would have been disconnected) -- End of your cleanup code freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n"); end function myHangupHook(s, status, arg) session:hangup() CleanUp() -- Run CleanUp function now since the caller has disconnected end -- Setup Hangup event handler here v_hangup = "HANGUP" session:setHangupHook("myHangupHook", "v_hangup") -- Call service functions in order PreAnswer() AnswerCaller() MainService() -- End of Lua service _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org<mailto: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<mailto: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
That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way. On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil <andrew.keil@visytel.com> wrote:
Thanks for your response.
I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script.
I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great.
Andrew
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Abaci B *Sent:* Saturday, 27 February 2016 1:29 AM *To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back.
On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
To FreeSWITCH Users,
See below for a sample template for a Lua Service Script running inside FreeSWITCH.
The issue I have is fairly straightforward.
I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end.
The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call.
My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc….
So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time!
I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution.
FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “*if (session:ready()) then ….”* or “*if (not session:ready()) then goto HANGUPEXIT end”* makes the code ugly.
Thanks in advance,
Andrew Keil
*Visytel Pty Ltd*
------------------------------------------------------------------------------ Sample Lua Service -----------------------------------------------------------------------
-- Lua template for FreeSWITCH service
-- By: Andrew Keil (Visytel Pty Ltd)
-- Email: support@visytel.com
-- Setup script wide variables here
function PreAnswer()
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n");
-- Add your pre answer code from here
-- End of your pre answer code
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n");
end
function AnswerCaller()
session:answer()
session:sleep(1000)
end
function MainService()
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n");
if (session:ready()) then
-- Note (1): If you wish to end the call then simply use: goto ENDSERVICE
-- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end
-- Add your main service code from here (caller would have been answered)
session:streamFile("intro.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("info.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("outro.wav")
if (not session:ready()) then goto HANGUPEXIT end
-- End of your main service code
end
::ENDSERVICE::
if (session:ready()) then
-- End of service so hangup
session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage
end
goto END
::HANGUPEXIT::
freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n");
::END::
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n");
end
function CleanUp()
freeswitch.consoleLog("INFO", "CLEANUP SECTION\n");
-- Add your cleanup code from here (caller would have been disconnected)
-- End of your cleanup code
freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n");
end
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
-- Call service functions in order
PreAnswer()
AnswerCaller()
MainService()
-- End of Lua service
_________________________________________________________________________ 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
_________________________________________________________________________ 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
I don't see in your example above where you have a return "exit" in your hangup hook function see https://freeswitch.org/jira/browse/FS-3841 seems like the "exit" or "die" needs to be returned directly from the hanguphook function so try from that function (not cleanup function) to return "exit" or "dye", also it seems On Mon, Feb 29, 2016 at 10:53 AM, Abaci B <abaci64@gmail.com> wrote:
That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way.
On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil <andrew.keil@visytel.com> wrote:
Thanks for your response.
I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script.
I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great.
Andrew
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Abaci B *Sent:* Saturday, 27 February 2016 1:29 AM *To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back.
On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
To FreeSWITCH Users,
See below for a sample template for a Lua Service Script running inside FreeSWITCH.
The issue I have is fairly straightforward.
I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end.
The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call.
My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc….
So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time!
I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution.
FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “*if (session:ready()) then ….”* or “*if (not session:ready()) then goto HANGUPEXIT end”* makes the code ugly.
Thanks in advance,
Andrew Keil
*Visytel Pty Ltd*
------------------------------------------------------------------------------ Sample Lua Service -----------------------------------------------------------------------
-- Lua template for FreeSWITCH service
-- By: Andrew Keil (Visytel Pty Ltd)
-- Email: support@visytel.com
-- Setup script wide variables here
function PreAnswer()
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n");
-- Add your pre answer code from here
-- End of your pre answer code
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n");
end
function AnswerCaller()
session:answer()
session:sleep(1000)
end
function MainService()
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n");
if (session:ready()) then
-- Note (1): If you wish to end the call then simply use: goto ENDSERVICE
-- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end
-- Add your main service code from here (caller would have been answered)
session:streamFile("intro.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("info.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("outro.wav")
if (not session:ready()) then goto HANGUPEXIT end
-- End of your main service code
end
::ENDSERVICE::
if (session:ready()) then
-- End of service so hangup
session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage
end
goto END
::HANGUPEXIT::
freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n");
::END::
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n");
end
function CleanUp()
freeswitch.consoleLog("INFO", "CLEANUP SECTION\n");
-- Add your cleanup code from here (caller would have been disconnected)
-- End of your cleanup code
freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n");
end
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
-- Call service functions in order
PreAnswer()
AnswerCaller()
MainService()
-- End of Lua service
_________________________________________________________________________ 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
_________________________________________________________________________ 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
On Mon, Feb 29, 2016 at 8:15 AM, Abaci B <abaci64@gmail.com> wrote:
I don't see in your example above where you have a return "exit" in your hangup hook function see https://freeswitch.org/jira/browse/FS-3841 seems like the "exit" or "die" needs to be returned directly from the hanguphook function so try from that function (not cleanup function) to return "exit" or "dye", also it seems
On Mon, Feb 29, 2016 at 10:53 AM, Abaci B <abaci64@gmail.com> wrote:
That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way.
On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil <andrew.keil@visytel.com> wrote:
Thanks for your response.
I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script.
I was not able to get session:destroy() to crash freeswitch using latest 1.7. However, it does not appear you need to explicitly destroy the session. I suggest doing what Abaci recommends with the 'return "exit"' at the end of myHangupHook right after the call to CleanUp().
-MC
Abaci B, Thanks so much for sourcing the JIRA topic! You were right, by placing the return “exit” inside the hanguphook handler then the sript does stop and abort with an error. I have made this cleaner by adding debug.traceback=nil just prior. So now my hangup hook handler looks like this: function myHangupHook(s, status, arg) session:hangup() CleanUp() -- Run CleanUp function now since the caller has disconnected debug.traceback=nil return "exit" end Obviously this generates the message: “2016-03-01 09:01:18.625809 [ERR] mod_lua.cpp:203 exit” in the console, but this I can live with especially to avoid the goto statements throughout the code after every audio related function. Thanks again. Andrew Keil Visytel Pty Ltd From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Abaci B Sent: Tuesday, 1 March 2016 3:16 AM To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function I don't see in your example above where you have a return "exit" in your hangup hook function see https://freeswitch.org/jira/browse/FS-3841 seems like the "exit" or "die" needs to be returned directly from the hanguphook function so try from that function (not cleanup function) to return "exit" or "dye", also it seems On Mon, Feb 29, 2016 at 10:53 AM, Abaci B <abaci64@gmail.com<mailto:abaci64@gmail.com>> wrote: That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way. On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil <andrew.keil@visytel.com<mailto:andrew.keil@visytel.com>> wrote: Thanks for your response. I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script. I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great. Andrew From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Abaci B Sent: Saturday, 27 February 2016 1:29 AM To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org>> Subject: Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back. On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com<mailto:andrew.keil@visytel.com>> wrote: To FreeSWITCH Users, See below for a sample template for a Lua Service Script running inside FreeSWITCH. The issue I have is fairly straightforward. I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end. The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call. My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc…. So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time! I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution. FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “if (session:ready()) then ….” or “if (not session:ready()) then goto HANGUPEXIT end” makes the code ugly. Thanks in advance, Andrew Keil Visytel Pty Ltd ------------------------------------------------------------------------------ Sample Lua Service ----------------------------------------------------------------------- -- Lua template for FreeSWITCH service -- By: Andrew Keil (Visytel Pty Ltd) -- Email: support@visytel.com<mailto:support@visytel.com> -- Setup script wide variables here function PreAnswer() freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n"); -- Add your pre answer code from here -- End of your pre answer code freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n"); end function AnswerCaller() session:answer() session:sleep(1000) end function MainService() freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n"); if (session:ready()) then -- Note (1): If you wish to end the call then simply use: goto ENDSERVICE -- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end -- Add your main service code from here (caller would have been answered) session:streamFile("intro.wav") if (not session:ready()) then goto HANGUPEXIT end session:streamFile("info.wav") if (not session:ready()) then goto HANGUPEXIT end session:streamFile("outro.wav") if (not session:ready()) then goto HANGUPEXIT end -- End of your main service code end ::ENDSERVICE:: if (session:ready()) then -- End of service so hangup session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage end goto END ::HANGUPEXIT:: freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n"); ::END:: freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n"); end function CleanUp() freeswitch.consoleLog("INFO", "CLEANUP SECTION\n"); -- Add your cleanup code from here (caller would have been disconnected) -- End of your cleanup code freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n"); end function myHangupHook(s, status, arg) session:hangup() CleanUp() -- Run CleanUp function now since the caller has disconnected end -- Setup Hangup event handler here v_hangup = "HANGUP" session:setHangupHook("myHangupHook", "v_hangup") -- Call service functions in order PreAnswer() AnswerCaller() MainService() -- End of Lua service _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org<mailto: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<mailto: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 _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org<mailto: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<mailto: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
I still think there should be a way to exit a lua script without calling a hangup hook, this is needed for lua scripts with no session and even in some scenarios where there is a session. I think I'll open a feature request on Jira for that, unless someone knows a way to do this? On Mon, Feb 29, 2016 at 5:09 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
Abaci B,
Thanks so much for sourcing the JIRA topic!
You were right, by placing the return “exit” inside the hanguphook handler then the sript does stop and abort with an error. I have made this cleaner by adding debug.traceback=nil just prior.
So now my hangup hook handler looks like this:
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
debug.traceback=nil
return "exit"
end
Obviously this generates the message: “2016-03-01 09:01:18.625809 [ERR] mod_lua.cpp:203 exit”
in the console, but this I can live with especially to avoid the goto statements throughout the code after every audio related function.
Thanks again.
Andrew Keil
*Visytel Pty Ltd*
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Abaci B *Sent:* Tuesday, 1 March 2016 3:16 AM
*To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
I don't see in your example above where you have a return "exit" in your hangup hook function
see https://freeswitch.org/jira/browse/FS-3841
seems like the "exit" or "die" needs to be returned directly from the hanguphook function so try from that function (not cleanup function) to return "exit" or "dye", also it seems
On Mon, Feb 29, 2016 at 10:53 AM, Abaci B <abaci64@gmail.com> wrote:
That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way.
On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil <andrew.keil@visytel.com> wrote:
Thanks for your response.
I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script.
I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great.
Andrew
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Abaci B *Sent:* Saturday, 27 February 2016 1:29 AM *To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back.
On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
To FreeSWITCH Users,
See below for a sample template for a Lua Service Script running inside FreeSWITCH.
The issue I have is fairly straightforward.
I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end.
The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call.
My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc….
So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time!
I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution.
FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “*if (session:ready()) then ….”* or “*if (not session:ready()) then goto HANGUPEXIT end”* makes the code ugly.
Thanks in advance,
Andrew Keil
*Visytel Pty Ltd*
------------------------------------------------------------------------------ Sample Lua Service -----------------------------------------------------------------------
-- Lua template for FreeSWITCH service
-- By: Andrew Keil (Visytel Pty Ltd)
-- Email: support@visytel.com
-- Setup script wide variables here
function PreAnswer()
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n");
-- Add your pre answer code from here
-- End of your pre answer code
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n");
end
function AnswerCaller()
session:answer()
session:sleep(1000)
end
function MainService()
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n");
if (session:ready()) then
-- Note (1): If you wish to end the call then simply use: goto ENDSERVICE
-- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end
-- Add your main service code from here (caller would have been answered)
session:streamFile("intro.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("info.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("outro.wav")
if (not session:ready()) then goto HANGUPEXIT end
-- End of your main service code
end
::ENDSERVICE::
if (session:ready()) then
-- End of service so hangup
session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage
end
goto END
::HANGUPEXIT::
freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n");
::END::
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n");
end
function CleanUp()
freeswitch.consoleLog("INFO", "CLEANUP SECTION\n");
-- Add your cleanup code from here (caller would have been disconnected)
-- End of your cleanup code
freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n");
end
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
-- Call service functions in order
PreAnswer()
AnswerCaller()
MainService()
-- End of Lua service
_________________________________________________________________________ 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
_________________________________________________________________________ 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
_________________________________________________________________________ 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
In cases where I've run Lua scripts on startup, I'll use a global variable, and periodically check it like so: kill_script = api:executeString("global_getvar custom_lua_kill_script") If the variable is set to a specified value, then I take steps to end the script, which usually just means breaking out of an infinite loop. This variable can be adjusted in a number of ways, including another Lua script, directly from CLI, or even by setting a timer using the schedule API in the same script: command = string.format([[sched_api %d none global_setvar custom_lua_kill_script=true]], shutdown_stamp) api:executeString(command) Not the most elegant solution, but it works. On Fri, Mar 4, 2016 at 5:55 AM, Abaci B <abaci64@gmail.com> wrote:
I still think there should be a way to exit a lua script without calling a hangup hook, this is needed for lua scripts with no session and even in some scenarios where there is a session. I think I'll open a feature request on Jira for that, unless someone knows a way to do this?
On Mon, Feb 29, 2016 at 5:09 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
Abaci B,
Thanks so much for sourcing the JIRA topic!
You were right, by placing the return “exit” inside the hanguphook handler then the sript does stop and abort with an error. I have made this cleaner by adding debug.traceback=nil just prior.
So now my hangup hook handler looks like this:
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
debug.traceback=nil
return "exit"
end
Obviously this generates the message: “2016-03-01 09:01:18.625809 [ERR] mod_lua.cpp:203 exit”
in the console, but this I can live with especially to avoid the goto statements throughout the code after every audio related function.
Thanks again.
Andrew Keil
*Visytel Pty Ltd*
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Abaci B *Sent:* Tuesday, 1 March 2016 3:16 AM
*To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
I don't see in your example above where you have a return "exit" in your hangup hook function
see https://freeswitch.org/jira/browse/FS-3841
seems like the "exit" or "die" needs to be returned directly from the hanguphook function so try from that function (not cleanup function) to return "exit" or "dye", also it seems
On Mon, Feb 29, 2016 at 10:53 AM, Abaci B <abaci64@gmail.com> wrote:
That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way.
On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil <andrew.keil@visytel.com> wrote:
Thanks for your response.
I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script.
I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great.
Andrew
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Abaci B *Sent:* Saturday, 27 February 2016 1:29 AM *To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back.
On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
To FreeSWITCH Users,
See below for a sample template for a Lua Service Script running inside FreeSWITCH.
The issue I have is fairly straightforward.
I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end.
The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call.
My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc….
So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time!
I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution.
FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “*if (session:ready()) then ….”* or “*if (not session:ready()) then goto HANGUPEXIT end”* makes the code ugly.
Thanks in advance,
Andrew Keil
*Visytel Pty Ltd*
------------------------------------------------------------------------------ Sample Lua Service -----------------------------------------------------------------------
-- Lua template for FreeSWITCH service
-- By: Andrew Keil (Visytel Pty Ltd)
-- Email: support@visytel.com
-- Setup script wide variables here
function PreAnswer()
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n");
-- Add your pre answer code from here
-- End of your pre answer code
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n");
end
function AnswerCaller()
session:answer()
session:sleep(1000)
end
function MainService()
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n");
if (session:ready()) then
-- Note (1): If you wish to end the call then simply use: goto ENDSERVICE
-- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end
-- Add your main service code from here (caller would have been answered)
session:streamFile("intro.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("info.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("outro.wav")
if (not session:ready()) then goto HANGUPEXIT end
-- End of your main service code
end
::ENDSERVICE::
if (session:ready()) then
-- End of service so hangup
session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage
end
goto END
::HANGUPEXIT::
freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n");
::END::
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n");
end
function CleanUp()
freeswitch.consoleLog("INFO", "CLEANUP SECTION\n");
-- Add your cleanup code from here (caller would have been disconnected)
-- End of your cleanup code
freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n");
end
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
-- Call service functions in order
PreAnswer()
AnswerCaller()
MainService()
-- End of Lua service
_________________________________________________________________________ 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
_________________________________________________________________________ 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
_________________________________________________________________________ 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
_________________________________________________________________________ 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
The question is not how to figure out when to exit the lua script, the question is *how to exit the lua script*, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook. On Fri, Mar 4, 2016 at 11:56 AM, Chad Phillips <chad@apartmentlines.com> wrote:
In cases where I've run Lua scripts on startup, I'll use a global variable, and periodically check it like so:
kill_script = api:executeString("global_getvar custom_lua_kill_script")
If the variable is set to a specified value, then I take steps to end the script, which usually just means breaking out of an infinite loop.
This variable can be adjusted in a number of ways, including another Lua script, directly from CLI, or even by setting a timer using the schedule API in the same script:
command = string.format([[sched_api %d none global_setvar custom_lua_kill_script=true]], shutdown_stamp) api:executeString(command)
Not the most elegant solution, but it works.
On Fri, Mar 4, 2016 at 5:55 AM, Abaci B <abaci64@gmail.com> wrote:
I still think there should be a way to exit a lua script without calling a hangup hook, this is needed for lua scripts with no session and even in some scenarios where there is a session. I think I'll open a feature request on Jira for that, unless someone knows a way to do this?
On Mon, Feb 29, 2016 at 5:09 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
Abaci B,
Thanks so much for sourcing the JIRA topic!
You were right, by placing the return “exit” inside the hanguphook handler then the sript does stop and abort with an error. I have made this cleaner by adding debug.traceback=nil just prior.
So now my hangup hook handler looks like this:
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
debug.traceback=nil
return "exit"
end
Obviously this generates the message: “2016-03-01 09:01:18.625809 [ERR] mod_lua.cpp:203 exit”
in the console, but this I can live with especially to avoid the goto statements throughout the code after every audio related function.
Thanks again.
Andrew Keil
*Visytel Pty Ltd*
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Abaci B *Sent:* Tuesday, 1 March 2016 3:16 AM
*To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
I don't see in your example above where you have a return "exit" in your hangup hook function
see https://freeswitch.org/jira/browse/FS-3841
seems like the "exit" or "die" needs to be returned directly from the hanguphook function so try from that function (not cleanup function) to return "exit" or "dye", also it seems
On Mon, Feb 29, 2016 at 10:53 AM, Abaci B <abaci64@gmail.com> wrote:
That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way.
On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil <andrew.keil@visytel.com> wrote:
Thanks for your response.
I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script.
I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great.
Andrew
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Abaci B *Sent:* Saturday, 27 February 2016 1:29 AM *To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back.
On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
To FreeSWITCH Users,
See below for a sample template for a Lua Service Script running inside FreeSWITCH.
The issue I have is fairly straightforward.
I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end.
The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call.
My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc….
So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time!
I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution.
FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “*if (session:ready()) then ….”* or “*if (not session:ready()) then goto HANGUPEXIT end”* makes the code ugly.
Thanks in advance,
Andrew Keil
*Visytel Pty Ltd*
------------------------------------------------------------------------------ Sample Lua Service -----------------------------------------------------------------------
-- Lua template for FreeSWITCH service
-- By: Andrew Keil (Visytel Pty Ltd)
-- Email: support@visytel.com
-- Setup script wide variables here
function PreAnswer()
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n");
-- Add your pre answer code from here
-- End of your pre answer code
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n");
end
function AnswerCaller()
session:answer()
session:sleep(1000)
end
function MainService()
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n");
if (session:ready()) then
-- Note (1): If you wish to end the call then simply use: goto ENDSERVICE
-- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end
-- Add your main service code from here (caller would have been answered)
session:streamFile("intro.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("info.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("outro.wav")
if (not session:ready()) then goto HANGUPEXIT end
-- End of your main service code
end
::ENDSERVICE::
if (session:ready()) then
-- End of service so hangup
session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage
end
goto END
::HANGUPEXIT::
freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n");
::END::
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n");
end
function CleanUp()
freeswitch.consoleLog("INFO", "CLEANUP SECTION\n");
-- Add your cleanup code from here (caller would have been disconnected)
-- End of your cleanup code
freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n");
end
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
-- Call service functions in order
PreAnswer()
AnswerCaller()
MainService()
-- End of Lua service
_________________________________________________________________________ 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
_________________________________________________________________________ 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
_________________________________________________________________________ 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
_________________________________________________________________________ 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
_________________________________________________________________________ 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
On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <abaci64@gmail.com> wrote:
The question is not how to figure out when to exit the lua script, the question is *how to exit the lua script*, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook.
Are you positive that it works only from a hangup hook? It seems to work at the end of any loop: -- testing exit (no session, call with luarun) freeswitch.consoleLog('INFO',"Starting infinite loop...\n") while(1) do freeswitch.consoleLog('WARNING',"Before exit...\n") return "exit" end freeswitch.consoleLog('INFO',"All done!\n") Or with a session: -- test exit with session, no hangup hook session:answer() freeswitch.consoleLog('INFO',"Entering main loop...\n") while ( session:ready() == true ) do freeswitch.consoleLog('WARNING',"Inside loop...\n") return "exit" end freeswitch.consoleLog('INFO',"All done!\n") In both cases I never see "All done!" at the CLI. Can you try it and see if there's a scenario where it does not exit as expected? -MC
Michael, I have just run some more tests and you are correct that calling it inside a while loop like what you explained below does work outside of the hangup hook handler. Thanks for providing this extra information. It should be noted that it does not work on its own simply at the bottom of a Lua function (ie. as the last statement without a while loop) - except as the last statement inside the hangup hook function. ie. This works: ---------------------------------------------------------------- function CleanUp() freeswitch.consoleLog("CLEANUP SECTION\n") freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n") end function myHangupHook(s, status, arg) freeswitch.consoleLog(string.format("%s DETECTED\n",arg)) session:hangup() -- Run CleanUp function now since the caller has disconnected CleanUp() -- Abort Lua script here to avoid returning to MainService() return "exit" end -- Setup Hangup event handler here v_hangup = "HANGUP" session:setHangupHook("myHangupHook", "v_hangup") Whereas this does not work: ---------------------------------------------------------------- function CleanUp() freeswitch.consoleLog("CLEANUP SECTION\n") freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n") return "exit" end function myHangupHook(s, status, arg) freeswitch.consoleLog(string.format("%s DETECTED\n",arg)) session:hangup() -- Run CleanUp function now since the caller has disconnected CleanUp() end -- Setup Hangup event handler here v_hangup = "HANGUP" session:setHangupHook("myHangupHook", "v_hangup") Regards, Andrew From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Michael Collins Sent: Saturday, 5 March 2016 8:11 AM To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <abaci64@gmail.com<mailto:abaci64@gmail.com>> wrote: The question is not how to figure out when to exit the lua script, the question is how to exit the lua script, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook. Are you positive that it works only from a hangup hook? It seems to work at the end of any loop: -- testing exit (no session, call with luarun) freeswitch.consoleLog('INFO',"Starting infinite loop...\n") while(1) do freeswitch.consoleLog('WARNING',"Before exit...\n") return "exit" end freeswitch.consoleLog('INFO',"All done!\n") Or with a session: -- test exit with session, no hangup hook session:answer() freeswitch.consoleLog('INFO',"Entering main loop...\n") while ( session:ready() == true ) do freeswitch.consoleLog('WARNING',"Inside loop...\n") return "exit" end freeswitch.consoleLog('INFO',"All done!\n") In both cases I never see "All done!" at the CLI. Can you try it and see if there's a scenario where it does not exit as expected? -MC
Andrew, Curious if this structure will work at the bottom of either a a Lua script or Lua function: do return "exit" end I seem to recall that being a trick that helped for weird 'return' cases. Chad On Tue, Mar 8, 2016 at 12:54 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
Michael,
I have just run some more tests and you are correct that calling it inside a while loop like what you explained below does work outside of the hangup hook handler. Thanks for providing this extra information.
It should be noted that it does not work on its own simply at the bottom of a Lua function (ie. as the last statement without a while loop) - except as the last statement inside the hangup hook function.
ie. This works:
----------------------------------------------------------------
function CleanUp()
freeswitch.consoleLog("CLEANUP SECTION\n")
freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
end
function myHangupHook(s, status, arg)
freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
session:hangup()
-- Run CleanUp function now since the caller has disconnected
CleanUp()
-- Abort Lua script here to avoid returning to MainService()
return "exit"
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
Whereas this does not work:
----------------------------------------------------------------
function CleanUp()
freeswitch.consoleLog("CLEANUP SECTION\n")
freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
return "exit"
end
function myHangupHook(s, status, arg)
freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
session:hangup()
-- Run CleanUp function now since the caller has disconnected
CleanUp()
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
Regards,
Andrew
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Michael Collins *Sent:* Saturday, 5 March 2016 8:11 AM *To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <abaci64@gmail.com> wrote:
The question is not how to figure out when to exit the lua script, the question is *how to exit the lua script*, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook.
Are you positive that it works only from a hangup hook? It seems to work at the end of any loop:
-- testing exit (no session, call with luarun)
freeswitch.consoleLog('INFO',"Starting infinite loop...\n")
while(1) do
freeswitch.consoleLog('WARNING',"Before exit...\n")
return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")
Or with a session:
-- test exit with session, no hangup hook
session:answer()
freeswitch.consoleLog('INFO',"Entering main loop...\n")
while ( session:ready() == true ) do
freeswitch.consoleLog('WARNING',"Inside loop...\n")
return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")
In both cases I never see "All done!" at the CLI. Can you try it and see if there's a scenario where it does not exit as expected?
-MC
_________________________________________________________________________ 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
I would expect to be able to exit from a lua script without a while loop, should I open a feature request on Jira for that? On Wed, Mar 9, 2016 at 1:20 AM, Chad Phillips <chad@apartmentlines.com> wrote:
Andrew,
Curious if this structure will work at the bottom of either a a Lua script or Lua function:
do return "exit" end
I seem to recall that being a trick that helped for weird 'return' cases.
Chad
On Tue, Mar 8, 2016 at 12:54 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
Michael,
I have just run some more tests and you are correct that calling it inside a while loop like what you explained below does work outside of the hangup hook handler. Thanks for providing this extra information.
It should be noted that it does not work on its own simply at the bottom of a Lua function (ie. as the last statement without a while loop) - except as the last statement inside the hangup hook function.
ie. This works:
----------------------------------------------------------------
function CleanUp()
freeswitch.consoleLog("CLEANUP SECTION\n")
freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
end
function myHangupHook(s, status, arg)
freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
session:hangup()
-- Run CleanUp function now since the caller has disconnected
CleanUp()
-- Abort Lua script here to avoid returning to MainService()
return "exit"
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
Whereas this does not work:
----------------------------------------------------------------
function CleanUp()
freeswitch.consoleLog("CLEANUP SECTION\n")
freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
return "exit"
end
function myHangupHook(s, status, arg)
freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
session:hangup()
-- Run CleanUp function now since the caller has disconnected
CleanUp()
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
Regards,
Andrew
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Michael Collins *Sent:* Saturday, 5 March 2016 8:11 AM *To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <abaci64@gmail.com> wrote:
The question is not how to figure out when to exit the lua script, the question is *how to exit the lua script*, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook.
Are you positive that it works only from a hangup hook? It seems to work at the end of any loop:
-- testing exit (no session, call with luarun)
freeswitch.consoleLog('INFO',"Starting infinite loop...\n")
while(1) do
freeswitch.consoleLog('WARNING',"Before exit...\n")
return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")
Or with a session:
-- test exit with session, no hangup hook
session:answer()
freeswitch.consoleLog('INFO',"Entering main loop...\n")
while ( session:ready() == true ) do
freeswitch.consoleLog('WARNING',"Inside loop...\n")
return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")
In both cases I never see "All done!" at the CLI. Can you try it and see if there's a scenario where it does not exit as expected?
-MC
_________________________________________________________________________ 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
_________________________________________________________________________ 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
I just got around to test this again and here is what I found. from within the hangup hook you can exit using return "exit" and as noted by Andrew it will exit with an error unless you set debug.traceback=nil from the main code (not within a function) you can exit by using return "exit" (or return anything else) which is just lua exiting but it has to be at the end of a block (wither a loop or you can just return "exit" end). from within a function there seems to be no way to exit the lua script, for scripts that are session based you can probably use session:hangup() along with calling return "exit" from the hangup hook, but on any other lua scripts (api, event hooks, dialplan hook, startup) there seems to be no way. So my question is if anyone know another way to exit a lua script from within a function or if I should open a Jira. On Thu, Mar 10, 2016 at 4:21 PM, Abaci B <abaci64@gmail.com> wrote:
I would expect to be able to exit from a lua script without a while loop, should I open a feature request on Jira for that?
On Wed, Mar 9, 2016 at 1:20 AM, Chad Phillips <chad@apartmentlines.com> wrote:
Andrew,
Curious if this structure will work at the bottom of either a a Lua script or Lua function:
do return "exit" end
I seem to recall that being a trick that helped for weird 'return' cases.
Chad
On Tue, Mar 8, 2016 at 12:54 PM, Andrew Keil <andrew.keil@visytel.com> wrote:
Michael,
I have just run some more tests and you are correct that calling it inside a while loop like what you explained below does work outside of the hangup hook handler. Thanks for providing this extra information.
It should be noted that it does not work on its own simply at the bottom of a Lua function (ie. as the last statement without a while loop) - except as the last statement inside the hangup hook function.
ie. This works:
----------------------------------------------------------------
function CleanUp()
freeswitch.consoleLog("CLEANUP SECTION\n")
freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
end
function myHangupHook(s, status, arg)
freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
session:hangup()
-- Run CleanUp function now since the caller has disconnected
CleanUp()
-- Abort Lua script here to avoid returning to MainService()
return "exit"
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
Whereas this does not work:
----------------------------------------------------------------
function CleanUp()
freeswitch.consoleLog("CLEANUP SECTION\n")
freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
return "exit"
end
function myHangupHook(s, status, arg)
freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
session:hangup()
-- Run CleanUp function now since the caller has disconnected
CleanUp()
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
Regards,
Andrew
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Michael Collins *Sent:* Saturday, 5 March 2016 8:11 AM *To:* FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <abaci64@gmail.com> wrote:
The question is not how to figure out when to exit the lua script, the question is *how to exit the lua script*, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook.
Are you positive that it works only from a hangup hook? It seems to work at the end of any loop:
-- testing exit (no session, call with luarun)
freeswitch.consoleLog('INFO',"Starting infinite loop...\n")
while(1) do
freeswitch.consoleLog('WARNING',"Before exit...\n")
return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")
Or with a session:
-- test exit with session, no hangup hook
session:answer()
freeswitch.consoleLog('INFO',"Entering main loop...\n")
while ( session:ready() == true ) do
freeswitch.consoleLog('WARNING',"Inside loop...\n")
return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")
In both cases I never see "All done!" at the CLI. Can you try it and see if there's a scenario where it does not exit as expected?
-MC
_________________________________________________________________________ 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
_________________________________________________________________________ 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
Just returning a value from any random function won't have any effect. The return from hangup hook is special as thats a function we call from the c code. Its probably possible to add a method that you could run that would terminate the script, but I don't think there is any way to do that currently. On quick review, it looks like the way "exit" return from hangup hook is implemented is by way of calling lua_error from the c code, which would cause the script to terminate. Other than that, as was said above, the way to end a script is by way of returning from the body of it.
On Jul 7, 2016, at 7:20 PM, Abaci B <abaci64@gmail.com> wrote:
I just got around to test this again and here is what I found. from within the hangup hook you can exit using return "exit" and as noted by Andrew it will exit with an error unless you set debug.traceback=nil from the main code (not within a function) you can exit by using return "exit" (or return anything else) which is just lua exiting but it has to be at the end of a block (wither a loop or you can just return "exit" end). from within a function there seems to be no way to exit the lua script, for scripts that are session based you can probably use session:hangup() along with calling return "exit" from the hangup hook, but on any other lua scripts (api, event hooks, dialplan hook, startup) there seems to be no way. So my question is if anyone know another way to exit a lua script from within a function or if I should open a Jira.
On Thu, Mar 10, 2016 at 4:21 PM, Abaci B <abaci64@gmail.com <mailto:abaci64@gmail.com>> wrote: I would expect to be able to exit from a lua script without a while loop, should I open a feature request on Jira for that?
On Wed, Mar 9, 2016 at 1:20 AM, Chad Phillips <chad@apartmentlines.com <mailto:chad@apartmentlines.com>> wrote: Andrew,
Curious if this structure will work at the bottom of either a a Lua script or Lua function:
do return "exit" end
I seem to recall that being a trick that helped for weird 'return' cases.
Chad
On Tue, Mar 8, 2016 at 12:54 PM, Andrew Keil <andrew.keil@visytel.com <mailto:andrew.keil@visytel.com>> wrote: Michael,
I have just run some more tests and you are correct that calling it inside a while loop like what you explained below does work outside of the hangup hook handler. Thanks for providing this extra information.
It should be noted that it does not work on its own simply at the bottom of a Lua function (ie. as the last statement without a while loop) - except as the last statement inside the hangup hook function.
ie. This works:
----------------------------------------------------------------
function CleanUp()
freeswitch.consoleLog("CLEANUP SECTION\n")
freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
end
function myHangupHook(s, status, arg)
freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
session:hangup()
-- Run CleanUp function now since the caller has disconnected
CleanUp()
-- Abort Lua script here to avoid returning to MainService()
return "exit"
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
Whereas this does not work:
----------------------------------------------------------------
function CleanUp()
freeswitch.consoleLog("CLEANUP SECTION\n")
freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
return "exit"
end
function myHangupHook(s, status, arg)
freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
session:hangup()
-- Run CleanUp function now since the caller has disconnected
CleanUp()
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
Regards, <>
Andrew
From: freeswitch-users-bounces@lists.freeswitch.org <mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org <mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Michael Collins Sent: Saturday, 5 March 2016 8:11 AM To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org <mailto:freeswitch-users@lists.freeswitch.org>> Subject: Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <abaci64@gmail.com <mailto:abaci64@gmail.com>> wrote:
The question is not how to figure out when to exit the lua script, the question is how to exit the lua script, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook.
Are you positive that it works only from a hangup hook? It seems to work at the end of any loop:
-- testing exit (no session, call with luarun)
freeswitch.consoleLog('INFO',"Starting infinite loop...\n")
while(1) do
freeswitch.consoleLog('WARNING',"Before exit...\n")
return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")
Or with a session:
-- test exit with session, no hangup hook
session:answer()
freeswitch.consoleLog('INFO',"Entering main loop...\n")
while ( session:ready() == true ) do
freeswitch.consoleLog('WARNING',"Inside loop...\n")
return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")
In both cases I never see "All done!" at the CLI. Can you try it and see if there's a scenario where it does not exit as expected?
-MC
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org <mailto:consulting@freeswitch.org> http://www.freeswitchsolutions.com <http://www.freeswitchsolutions.com/>
Official FreeSWITCH Sites http://www.freeswitch.org <http://www.freeswitch.org/> http://confluence.freeswitch.org <http://confluence.freeswitch.org/> http://www.cluecon.com <http://www.cluecon.com/>
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org <mailto:FreeSWITCH-users@lists.freeswitch.org> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users <http://lists.freeswitch.org/mailman/listinfo/freeswitch-users> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users <http://lists.freeswitch.org/mailman/options/freeswitch-users> http://www.freeswitch.org <http://www.freeswitch.org/>
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org <mailto:consulting@freeswitch.org> http://www.freeswitchsolutions.com <http://www.freeswitchsolutions.com/>
Official FreeSWITCH Sites http://www.freeswitch.org <http://www.freeswitch.org/> http://confluence.freeswitch.org <http://confluence.freeswitch.org/> http://www.cluecon.com <http://www.cluecon.com/>
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org <mailto:FreeSWITCH-users@lists.freeswitch.org> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users <http://lists.freeswitch.org/mailman/listinfo/freeswitch-users> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users <http://lists.freeswitch.org/mailman/options/freeswitch-users> http://www.freeswitch.org <http://www.freeswitch.org/>
_________________________________________________________________________ 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
I have to double check, but this may leak memory...
On Mar 4, 2016, at 11:56 AM, Chad Phillips <chad@apartmentlines.com> wrote:
In cases where I've run Lua scripts on startup, I'll use a global variable, and periodically check it like so:
kill_script = api:executeString("global_getvar custom_lua_kill_script")
If the variable is set to a specified value, then I take steps to end the script, which usually just means breaking out of an infinite loop.
This variable can be adjusted in a number of ways, including another Lua script, directly from CLI, or even by setting a timer using the schedule API in the same script:
command = string.format([[sched_api %d none global_setvar custom_lua_kill_script=true]], shutdown_stamp) api:executeString(command)
Not the most elegant solution, but it works.
On Fri, Mar 4, 2016 at 5:55 AM, Abaci B <abaci64@gmail.com <mailto:abaci64@gmail.com>> wrote: I still think there should be a way to exit a lua script without calling a hangup hook, this is needed for lua scripts with no session and even in some scenarios where there is a session. I think I'll open a feature request on Jira for that, unless someone knows a way to do this?
On Mon, Feb 29, 2016 at 5:09 PM, Andrew Keil <andrew.keil@visytel.com <mailto:andrew.keil@visytel.com>> wrote: Abaci B,
Thanks so much for sourcing the JIRA topic!
You were right, by placing the return “exit” inside the hanguphook handler then the sript does stop and abort with an error. I have made this cleaner by adding debug.traceback=nil just prior.
So now my hangup hook handler looks like this:
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
debug.traceback=nil
return "exit"
end
Obviously this generates the message: “2016-03-01 09:01:18.625809 [ERR] mod_lua.cpp:203 exit” <> in the console, but this I can live with especially to avoid the goto statements throughout the code after every audio related function.
Thanks again.
Andrew Keil
Visytel Pty Ltd
From: freeswitch-users-bounces@lists.freeswitch.org <mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org <mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Abaci B Sent: Tuesday, 1 March 2016 3:16 AM
To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org <mailto:freeswitch-users@lists.freeswitch.org>> Subject: Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
I don't see in your example above where you have a return "exit" in your hangup hook function
see https://freeswitch.org/jira/browse/FS-3841 <https://freeswitch.org/jira/browse/FS-3841> seems like the "exit" or "die" needs to be returned directly from the hanguphook function so try from that function (not cleanup function) to return "exit" or "dye", also it seems
On Mon, Feb 29, 2016 at 10:53 AM, Abaci B <abaci64@gmail.com <mailto:abaci64@gmail.com>> wrote:
That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way.
On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil <andrew.keil@visytel.com <mailto:andrew.keil@visytel.com>> wrote:
Thanks for your response.
I have gone through these with no luck. Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore off the list. The rest simply interrupt the current function and do no end the script.
I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great.
Andrew
<> From: freeswitch-users-bounces@lists.freeswitch.org <mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org <mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Abaci B Sent: Saturday, 27 February 2016 1:29 AM To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org <mailto:freeswitch-users@lists.freeswitch.org>> Subject: Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
See https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAP... <https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAPIReference-session:setHangupHook> for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back.
On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil <andrew.keil@visytel.com <mailto:andrew.keil@visytel.com>> wrote:
To FreeSWITCH Users,
See below for a sample template for a Lua Service Script running inside FreeSWITCH.
The issue I have is fairly straightforward.
I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script. This function is CleanUp(). Then I would like the service to end.
The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()). What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call.
My aim is to reduce extra code and to make the Lua script simpler and easier to read. Also I would like to try and avoid goto statements, which I know can be done with if (session:ready()) etc….
So is there a way to stop a Lua script running inside FreeSWITCH cleanly? I have tried the os.exit() this is barred from use by FreeSWITCH. I have also tried session:destroy() which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time!
I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution.
FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “if (session:ready()) then ….” or “if (not session:ready()) then goto HANGUPEXIT end” makes the code ugly.
Thanks in advance,
Andrew Keil
Visytel Pty Ltd
------------------------------------------------------------------------------ Sample Lua Service -----------------------------------------------------------------------
-- Lua template for FreeSWITCH service
-- By: Andrew Keil (Visytel Pty Ltd)
-- Email: support@visytel.com <mailto:support@visytel.com>
-- Setup script wide variables here
function PreAnswer()
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n");
-- Add your pre answer code from here
-- End of your pre answer code
freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n");
end
function AnswerCaller()
session:answer()
session:sleep(1000)
end
function MainService()
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n");
if (session:ready()) then
-- Note (1): If you wish to end the call then simply use: goto ENDSERVICE
-- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end
-- Add your main service code from here (caller would have been answered)
session:streamFile("intro.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("info.wav")
if (not session:ready()) then goto HANGUPEXIT end
session:streamFile("outro.wav")
if (not session:ready()) then goto HANGUPEXIT end
-- End of your main service code
end
::ENDSERVICE::
if (session:ready()) then
-- End of service so hangup
session:hangup() -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage
end
goto END
::HANGUPEXIT::
freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n");
::END::
freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n");
end
function CleanUp()
freeswitch.consoleLog("INFO", "CLEANUP SECTION\n");
-- Add your cleanup code from here (caller would have been disconnected)
-- End of your cleanup code
freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n");
end
function myHangupHook(s, status, arg)
session:hangup()
CleanUp() -- Run CleanUp function now since the caller has disconnected
end
-- Setup Hangup event handler here
v_hangup = "HANGUP"
session:setHangupHook("myHangupHook", "v_hangup")
-- Call service functions in order
PreAnswer()
AnswerCaller()
MainService()
-- End of Lua service
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org <mailto:consulting@freeswitch.org> http://www.freeswitchsolutions.com <http://www.freeswitchsolutions.com/>
Official FreeSWITCH Sites http://www.freeswitch.org <http://www.freeswitch.org/> http://confluence.freeswitch.org <http://confluence.freeswitch.org/> http://www.cluecon.com <http://www.cluecon.com/>
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org <mailto:FreeSWITCH-users@lists.freeswitch.org> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users <http://lists.freeswitch.org/mailman/listinfo/freeswitch-users> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users <http://lists.freeswitch.org/mailman/options/freeswitch-users> http://www.freeswitch.org <http://www.freeswitch.org/>
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org <mailto:consulting@freeswitch.org> http://www.freeswitchsolutions.com <http://www.freeswitchsolutions.com/>
Official FreeSWITCH Sites http://www.freeswitch.org <http://www.freeswitch.org/> http://confluence.freeswitch.org <http://confluence.freeswitch.org/> http://www.cluecon.com <http://www.cluecon.com/>
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org <mailto:FreeSWITCH-users@lists.freeswitch.org> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users <http://lists.freeswitch.org/mailman/listinfo/freeswitch-users> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users <http://lists.freeswitch.org/mailman/options/freeswitch-users> http://www.freeswitch.org <http://www.freeswitch.org/>
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org <mailto:consulting@freeswitch.org> http://www.freeswitchsolutions.com <http://www.freeswitchsolutions.com/>
Official FreeSWITCH Sites http://www.freeswitch.org <http://www.freeswitch.org/> http://confluence.freeswitch.org <http://confluence.freeswitch.org/> http://www.cluecon.com <http://www.cluecon.com/>
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org <mailto:FreeSWITCH-users@lists.freeswitch.org> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users <http://lists.freeswitch.org/mailman/listinfo/freeswitch-users> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users <http://lists.freeswitch.org/mailman/options/freeswitch-users> http://www.freeswitch.org <http://www.freeswitch.org/>
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org <mailto:consulting@freeswitch.org> http://www.freeswitchsolutions.com <http://www.freeswitchsolutions.com/>
Official FreeSWITCH Sites http://www.freeswitch.org <http://www.freeswitch.org/> http://confluence.freeswitch.org <http://confluence.freeswitch.org/> http://www.cluecon.com <http://www.cluecon.com/>
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org <mailto:FreeSWITCH-users@lists.freeswitch.org> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users <http://lists.freeswitch.org/mailman/listinfo/freeswitch-users> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users <http://lists.freeswitch.org/mailman/options/freeswitch-users> http://www.freeswitch.org <http://www.freeswitch.org/>
_________________________________________________________________________ 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
participants (5)
-
Abaci B
-
Andrew Keil
-
Chad Phillips
-
Michael Collins
-
Michael Jerris