Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the fu


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users
View previous topic :: View next topic  
Author Message
andrew.keil at visytel...
Guest





PostPosted: Thu Feb 25, 2016 9:35 pm    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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
Back to top
abaci64 at gmail.com
Guest





PostPosted: Fri Feb 26, 2016 9:31 am    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

See 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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (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 (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
Back to top
andrew.keil at visytel...
Guest





PostPosted: Mon Feb 29, 2016 1:39 am    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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#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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (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 (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
Back to top
abaci64 at gmail.com
Guest





PostPosted: Mon Feb 29, 2016 10:55 am    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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#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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (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 (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 (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 (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
Back to top
abaci64 at gmail.com
Guest





PostPosted: Mon Feb 29, 2016 11:17 am    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (abaci64@gmail.com)> wrote:
Quote:
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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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#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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (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 (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 (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 (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





Back to top
msc at freeswitch.org
Guest





PostPosted: Mon Feb 29, 2016 5:06 pm    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

On Mon, Feb 29, 2016 at 8:15 AM, Abaci B <abaci64@gmail.com (abaci64@gmail.com)> wrote:
Quote:
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 (abaci64@gmail.com)> wrote:
Quote:
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 (andrew.keil@visytel.com)> wrote:
Quote:

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
Back to top
andrew.keil at visytel...
Guest





PostPosted: Mon Feb 29, 2016 5:11 pm    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (abaci64@gmail.com)> wrote:
Quote:

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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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#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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (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 (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 (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 (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





Back to top
abaci64 at gmail.com
Guest





PostPosted: Fri Mar 04, 2016 10:58 am    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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 (abaci64@gmail.com)> wrote:
Quote:

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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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#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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (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 (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 (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 (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 (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 (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
Back to top
chad at apartmentlines...
Guest





PostPosted: Fri Mar 04, 2016 11:58 am    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (abaci64@gmail.com)> wrote:
Quote:
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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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 (abaci64@gmail.com)> wrote:
Quote:

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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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#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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (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 (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 (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 (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 (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 (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 (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 (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
Back to top
abaci64 at gmail.com
Guest





PostPosted: Fri Mar 04, 2016 12:20 pm    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (chad@apartmentlines.com)> wrote:
Quote:
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 (abaci64@gmail.com)> wrote:
Quote:
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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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 (abaci64@gmail.com)> wrote:
Quote:

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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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#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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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
Back to top
msc at freeswitch.org
Guest





PostPosted: Fri Mar 04, 2016 4:13 pm    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <abaci64@gmail.com (abaci64@gmail.com)> wrote:
Quote:
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
 
Back to top
andrew.keil at visytel...
Guest





PostPosted: Tue Mar 08, 2016 5:57 pm    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (abaci64@gmail.com)> wrote:
Quote:

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
Back to top
chad at apartmentlines...
Guest





PostPosted: Wed Mar 09, 2016 1:23 am    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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 (abaci64@gmail.com)> wrote:
Quote:

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 (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 (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
Back to top
mike at jerris.com
Guest





PostPosted: Wed Mar 09, 2016 7:58 pm    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

I have to double check, but this may leak memory...
Quote:
On Mar 4, 2016, at 11:56 AM, Chad Phillips <chad@apartmentlines.com (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 (abaci64@gmail.com)> wrote:
Quote:
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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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 (abaci64@gmail.com)> wrote:
Quote:

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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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#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 (andrew.keil@visytel.com)> wrote:
Quote:

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 (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 (consulting@freeswitch.org) FreeSWITCH-users@lists.freeswitch.org (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 (consulting@freeswitch.org) FreeSWITCH-users@lists.freeswitch.org (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 (consulting@freeswitch.org) FreeSWITCH-users@lists.freeswitch.org (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 (consulting@freeswitch.org) FreeSWITCH-users@lists.freeswitch.org (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 (consulting@freeswitch.org)http://www.freeswitchsolutions.comOfficial FreeSWITCH Siteshttp://www.freeswitch.orghttp://confluence.freeswitch.orghttp://www.cluecon.comFreeSWITCH-users mailing listFreeSWITCH-users@lists.freeswitch.orghttp://lists.freeswitch.org/mailman/listinfo/freeswitch-usersUNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-usershttp://www.freeswitch.org
Back to top
abaci64 at gmail.com
Guest





PostPosted: Thu Mar 10, 2016 4:23 pm    Post subject: [Freeswitch-users] Re- End Lua script after HangupHook handl Reply with quote

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 (chad@apartmentlines.com)> wrote:
Quote:
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 (andrew.keil@visytel.com)> wrote:


Quote:

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 (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (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 (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 (abaci64@gmail.com)> wrote:
Quote:

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 (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 (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 (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 (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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services