[Freeswitch-users] exit lua script in hangup hook

Michael Collins msc at freeswitch.org
Tue Jan 31 22:44:04 MSK 2012


Gerald,

This is a feature/quirk of Lua. There is no explicit exit command. The
script keeps running until there are no more commands. You'll need to
restructure your loops so that when someone hangups it breaks out of the
outermost loop and then has nothing left to execute.

-MC

On Wed, Jan 25, 2012 at 3:17 AM, Gerald Weber <gerald.weber at besharp.at>wrote:

> Hello,****
>
> ** **
>
> i’m trying to exit my lua script (called from dialplan) to exit in the the
> hanguphook:****
>
> ** **
>
> function on_hangup(s,status)****
>
>         freeswitch.consoleLog("NOTICE","---- on_hangup: "..status.."\n");*
> ***
>
>         error(); ****
>
> end****
>
> ** **
>
> freeswitch.consoleLog("NOTICE","---- ANSWER:\n");****
>
> session:answer();****
>
> freeswitch.consoleLog("NOTICE","---- SETHOOK: \n");****
>
> session:setHangupHook("on_hangup");****
>
> ** **
>
> while (session:ready() == true) do****
>
>         freeswitch.consoleLog("NOTICE","---- START OF LOOP \n");****
>
>         freeswitch.consoleLog("NOTICE","---- STREAMFILE \n");****
>
>
> session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav");
> ****
>
>         freeswitch.consoleLog("NOTICE","---- END OF SCRIPT 1 -> HANGUP\n");
> ****
>
> end****
>
> ** **
>
> freeswitch.consoleLog("NOTICE","---- END OF SCRIPT 2 -> HANGUP\n");****
>
> session:hangup()****
>
> ** **
>
> When I hangup during the  streamFile Call, I geht the following output:***
> *
>
> ** **
>
> 2012-01-25 12:10:19.936097 [NOTICE] switch_channel.c:930 New Channel
> sofia/internal/2001 at 192.168.20.73 [2b1cd9f6-4745-11e1-8c71-0d2938abf0b5]**
> **
>
> 2012-01-25 12:10:19.936097 [INFO] mod_dialplan_xml.c:481 Processing
> B#-FS-2001 <2001>->3001 in context default****
>
> 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- ANSWER:****
>
> 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:599 Channel
> [sofia/internal/2001 at 192.168.20.73] has been answered****
>
> 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- SETHOOK:****
>
> 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- START OF LOOP
> ****
>
> 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- STREAMFILE***
> *
>
> 2012-01-25 12:10:21.116050 [NOTICE] sofia.c:624 Hangup sofia/internal/
> 2001 at 192.168.20.73 [CS_EXECUTE] [NORMAL_CLEARING]****
>
> 2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- on_hangup:
> hangup****
>
> 2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF
> SCRIPT 1 -> HANGUP****
>
> 2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF
> SCRIPT 2 -> HANGUP****
>
> 2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1398 Session 2
> (sofia/internal/2001 at 192.168.20.73) Ended****
>
> 2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1400 Close
> Channel sofia/internal/2001 at 192.168.20.73 [CS_DESTROY]****
>
> ** **
>
> Why does the hangup handler return and the rest of the script is executed ?
> ****
>
> I event tried “do return end;” , “exit;” ,” exit();” instead of “error();
> - none of them works.****
>
> ** **
>
> If i put the same logic into javascript, the hook works and the script is
> terminated:****
>
> ** **
>
> function on_hangup(s,status)****
>
> {****
>
>         console_log("NOTICE","---- hangup "+status+"\n");****
>
>         return "exit";****
>
> }****
>
> ** **
>
> console_log("NOTICE","---- ANSWER\n");****
>
> session.answer();****
>
> console_log("NOTICE","---- ANSWER\n");****
>
> session.setHangupHook(on_hangup);****
>
> ** **
>
> while(session.ready())****
>
> {****
>
>         console_log("NOTICE","---- START OF LOOP\n");****
>
>
> session.streamFile("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav");
> ****
>
>         console_log("NOTICE","---- END OF LOOP\n");****
>
> }****
>
> console_log("NOTICE","---- END OF SCRIPT\n");****
>
> session.hangup();****
>
> ** **
>
> ** **
>
> 2012-01-25 12:13:08.396041 [NOTICE] switch_channel.c:930 New Channel
> sofia/internal/2001 at 192.168.20.73 [8f85a15c-4745-11e1-8c76-0d2938abf0b5]**
> **
>
> 2012-01-25 12:13:08.396041 [INFO] mod_dialplan_xml.c:481 Processing
> B#-FS-2001 <2001>->3002 in context default****
>
> 2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER****
>
> 2012-01-25 12:13:08.396041 [NOTICE] mod_spidermonkey.c:2068 Channel
> [sofia/internal/2001 at 192.168.20.73] has been answered****
>
> 2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER****
>
> 2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- START OF LOOP****
>
> 2012-01-25 12:13:09.875996 [NOTICE] sofia.c:624 Hangup sofia/internal/
> 2001 at 192.168.20.73 [CS_EXECUTE] [NORMAL_CLEARING]****
>
> 2012-01-25 12:13:09.875996 [NOTICE] hangup.js:2 ---- hangup hangup****
>
> 2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1398 Session 3
> (sofia/internal/2001 at 192.168.20.73) Ended****
>
> 2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1400 Close
> Channel sofia/internal/2001 at 192.168.20.73 [CS_DESTROY]****
>
> ** **
>
> ** **
>
> Any suggestions ? Or do i miss something here ?****
>
> ** **
>
> The dialplan part:****
>
> ** **
>
>     <extension name="hanguptest">****
>
>      <condition field="destination_number" expression="^(3001)$">****
>
>         <action application="set" data="session_in_hangup_hook=true"/>****
>
>        <action application="lua" data="hangup.lua"/>****
>
>      </condition>****
>
>     </extension>****
>
> ** **
>
> (replace hangup.lua with hangup.js for the javascript version)****
>
> Freeswitch Version:****
>
> FreeSWITCH Version 1.0.head (git-9be51d5 2012-01-21 13-45-21 -0500)****
>
> ** **
>
> thx&regards,****
>
> gw****
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> 
> 
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120131/3639fb11/attachment-0001.html 


Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list