i'm unable to exit a lua script in the hangup handler.
Script:
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()
Output:
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]
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@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@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@192.168.20.73) Ended
2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/2001@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.
Also the following code does not work:
function on_hangup(s,status)
freeswitch.consoleLog("NOTICE","---- on_hangup: "..status.."\n");
if(session:ready() == false) then
freeswitch.consoleLog("NOTICE","---- SESSION NOT READY -> EXIT:\n");
--session:destroy();
--session:detach();
--error();
do return end;
end
freeswitch.consoleLog("NOTICE","---- END OF HANGUP\n");
end
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@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@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@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@192.168.20.73) Ended
2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/2001@192.168.20.73 [CS_DESTROY]