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

Andrew Keil andrew.keil at visytel.com
Wed Mar 9 01:54:55 MSK 2016


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 at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Michael Collins
Sent: Saturday, 5 March 2016 8:11 AM
To: FreeSWITCH Users Help <freeswitch-users at 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 at gmail.com<mailto:abaci64 at gmail.com>> wrote:
The question is not how to figure out when to exit the lua script, the question is how to exit the lua script, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook.

Are you positive that it works only from a hangup hook? It seems to work at the end of any loop:

-- testing exit (no session, call with luarun)
freeswitch.consoleLog('INFO',"Starting infinite loop...\n")
while(1) do
  freeswitch.consoleLog('WARNING',"Before exit...\n")
  return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")


Or with a session:
-- test exit with session, no hangup hook
session:answer()
freeswitch.consoleLog('INFO',"Entering main loop...\n")
while ( session:ready() == true ) do
  freeswitch.consoleLog('WARNING',"Inside loop...\n")
  return "exit"
end
freeswitch.consoleLog('INFO',"All done!\n")

In both cases I never see "All done!" at the CLI. Can you try it and see if there's a scenario where it does not exit as expected?

-MC

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20160308/c979d28d/attachment-0001.html 


Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list