<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:284392308;
        mso-list-type:hybrid;
        mso-list-template-ids:91142124 1647630836 201785347 201785349 201785345 201785347 201785349 201785345 201785347 201785349;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:\F06E;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:31.5pt;
        text-indent:-18.0pt;
        font-family:Wingdings;
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:67.5pt;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:103.5pt;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:139.5pt;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:175.5pt;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:211.5pt;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:247.5pt;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:10.0cm;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:319.5pt;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=DE-AT link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US>Hello,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>i’m trying to exit my lua script (called from dialplan) to exit in the the hanguphook:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>function on_hangup(s,status)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> freeswitch.consoleLog("NOTICE","---- on_hangup: "..status.."\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> error(); <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>end<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>freeswitch.consoleLog("NOTICE","---- ANSWER:\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>session:answer();<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>freeswitch.consoleLog("NOTICE","---- SETHOOK: \n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>session:setHangupHook("on_hangup");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>while (session:ready() == true) do<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> freeswitch.consoleLog("NOTICE","---- START OF LOOP \n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> freeswitch.consoleLog("NOTICE","---- STREAMFILE \n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> freeswitch.consoleLog("NOTICE","---- END OF SCRIPT 1 -> HANGUP\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>end<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>freeswitch.consoleLog("NOTICE","---- END OF SCRIPT 2 -> HANGUP\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>session:hangup()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>When I hangup during the streamFile Call, I geht the following output:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:19.936097 [NOTICE] switch_channel.c:930 New Channel sofia/internal/2001@192.168.20.73 [2b1cd9f6-4745-11e1-8c71-0d2938abf0b5]<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:19.936097 [INFO] mod_dialplan_xml.c:481 Processing B#-FS-2001 <2001>->3001 in context default<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- ANSWER:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:599 Channel [sofia/internal/2001@192.168.20.73] has been answered<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- SETHOOK:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- START OF LOOP<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- STREAMFILE<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:21.116050 [NOTICE] sofia.c:624 Hangup sofia/internal/2001@192.168.20.73 [CS_EXECUTE] [NORMAL_CLEARING]<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- on_hangup: hangup<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF SCRIPT 1 -> HANGUP<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF SCRIPT 2 -> HANGUP<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1398 Session 2 (sofia/internal/2001@192.168.20.73) Ended<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/2001@192.168.20.73 [CS_DESTROY]<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Why does the hangup handler return and the rest of the script is executed ?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>I event tried “do return end;” , “exit;” ,” exit();” instead of “error(); - none of them works.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>If i put the same logic into javascript, the hook works and the script is terminated:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>function on_hangup(s,status)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>{<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> console_log("NOTICE","---- hangup "+status+"\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> return "exit";<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>}<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>console_log("NOTICE","---- ANSWER\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>session.answer();<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>console_log("NOTICE","---- ANSWER\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>session.setHangupHook(on_hangup);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>while(session.ready())<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>{<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> console_log("NOTICE","---- START OF LOOP\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> session.streamFile("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> console_log("NOTICE","---- END OF LOOP\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>}<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>console_log("NOTICE","---- END OF SCRIPT\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>session.hangup();<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:08.396041 [NOTICE] switch_channel.c:930 New Channel sofia/internal/2001@192.168.20.73 [8f85a15c-4745-11e1-8c76-0d2938abf0b5]<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:08.396041 [INFO] mod_dialplan_xml.c:481 Processing B#-FS-2001 <2001>->3002 in context default<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:08.396041 [NOTICE] mod_spidermonkey.c:2068 Channel [sofia/internal/2001@192.168.20.73] has been answered<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- START OF LOOP<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:09.875996 [NOTICE] sofia.c:624 Hangup sofia/internal/2001@192.168.20.73 [CS_EXECUTE] [NORMAL_CLEARING]<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:09.875996 [NOTICE] hangup.js:2 ---- hangup hangup<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1398 Session 3 (sofia/internal/2001@192.168.20.73) Ended<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/2001@192.168.20.73 [CS_DESTROY]<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Any suggestions ? Or do i miss something here ?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>The dialplan part:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US> <extension name="hanguptest"><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> <condition field="destination_number" expression="^(3001)$"><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> <action application="set" data="session_in_hangup_hook=true"/><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> <action application="lua" data="hangup.lua"/><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> </condition><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> </extension><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>(replace hangup.lua with hangup.js for the javascript version)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>Freeswitch Version:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>FreeSWITCH Version 1.0.head (git-9be51d5 2012-01-21 13-45-21 -0500)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal>thx&regards,<o:p></o:p></p><p class=MsoNormal>gw<o:p></o:p></p></div></body></html>