[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freeswitch-users
Subject:    Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to han
From:       Andrew Keil <andrew.keil () visytel ! com>
Date:       2016-02-29 22:09:53
Message-ID: SY3PR01MB015684B091D197327ED38E92F3BA0 () SY3PR01MB0156 ! ausprd01 ! prod ! outlook ! com
[Download RAW message or body]

[Attachment #2 (text/plain)]

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<mailto:abaci64@gmail.com>> wrote: 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<mailto:andrew.keil@visytel.com>> wrote: 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> \
[mailto: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<mailto: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<mailto:andrew.keil@visytel.com>> wrote: 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<mailto: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<mailto: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<mailto: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<mailto: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<mailto: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


[Attachment #3 (text/html)]

<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=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@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:12.0pt;
	font-family:"Times New Roman",serif;}
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.msonormal0, li.msonormal0, div.msonormal0
	{mso-style-name:msonormal;
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
span.EmailStyle18
	{mso-style-type:personal-reply;
	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:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></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="EN-AU" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">Abaci \
B,<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">Thanks \
so much for sourcing the JIRA topic!<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">You \
were right, by placing the return "exit" inside the hanguphook handler then the sript \
does stop and abort with an error.&nbsp; I have made this cleaner  by adding \
debug.traceback=nil just prior.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">So \
now my hangup hook handler looks like this:<o:p></o:p></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">function \
myHangupHook(s, status, arg)<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp; \
session:hangup()<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp; \
CleanUp() -- Run CleanUp function now since the caller has \
disconnected<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp; \
debug.traceback=nil<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp; \
return &quot;exit&quot;&nbsp; <o:p></o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">end<o:p></o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><a name="_MailEndCompose"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">Obviously \
this generates the message: "2016-03-01 09:01:18.625809 [ERR] mod_lua.cpp:203 \
exit"<o:p></o:p></span></a></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">in \
the console, but this I can live with especially to avoid the goto statements \
throughout the code after every audio related function.<o:p></o:p></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">Thanks \
again.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">Andrew \
Keil<o:p></o:p></span></p> <p class="MsoNormal"><b><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US">Visytel \
Pty Ltd<o:p></o:p></span></b></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><b><span lang="EN-US" \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span \
lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> \
freeswitch-users-bounces@lists.freeswitch.org \
[mailto:freeswitch-users-bounces@lists.freeswitch.org] <b>On Behalf Of </b>Abaci \
B<br> <b>Sent:</b> Tuesday, 1 March 2016 3:16 AM<br>
<b>To:</b> FreeSWITCH Users Help &lt;freeswitch-users@lists.freeswitch.org&gt;<br>
<b>Subject:</b> Re: [Freeswitch-users] Re- End Lua script after HangupHook handled \
without all the extra code to handle the return to the function<o:p></o:p></span></p> \
<p class="MsoNormal"><o:p>&nbsp;</o:p></p> <div>
<div>
<p class="MsoNormal">I don't see in your example above where you have a return \
&quot;exit&quot; in your hangup hook function<o:p></o:p></p> </div>
<div>
<p class="MsoNormal">see <a \
href="https://freeswitch.org/jira/browse/FS-3841">https://freeswitch.org/jira/browse/FS-3841</a><o:p></o:p></p>
 </div>
<div>
<p class="MsoNormal">seems like the &quot;exit&quot; or &quot;die&quot; needs to be \
returned directly from the hanguphook function so try from that function (not cleanup \
function) to return &quot;exit&quot; or &quot;dye&quot;, also it seems \
<o:p></o:p></p> </div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">On Mon, Feb 29, 2016 at 10:53 AM, Abaci B &lt;<a \
href="mailto:abaci64@gmail.com" target="_blank">abaci64@gmail.com</a>&gt; \
wrote:<o:p></o:p></p> <blockquote style="border:none;border-left:solid #CCCCCC \
1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"> <div>
<p class="MsoNormal">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.<o:p></o:p></p> </div>
<div>
<div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil &lt;<a \
href="mailto:andrew.keil@visytel.com" target="_blank">andrew.keil@visytel.com</a>&gt; \
wrote:<o:p></o:p></p> <blockquote style="border:none;border-left:solid #CCCCCC \
1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"> <div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">Thanks for your \
response.</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&nbsp;</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">I have gone \
through these with no luck. &nbsp;&nbsp;Like I said the session:destroy("…") \
crashes FreeSWITCH, which is therefore  off the list.&nbsp; The rest simply interrupt \
the current function and do no end the script.</span><o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&nbsp;</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">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.</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&nbsp;</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">Andrew</span><o:p></o:p></p>
 <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><a \
name="-69840466_-1874271269__MailEndCompose"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&nbsp;</span></a><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span lang="EN-US" \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span \
lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> <a \
href="mailto:freeswitch-users-bounces@lists.freeswitch.org" \
target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a \
href="mailto:freeswitch-users-bounces@lists.freeswitch.org" \
target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>] <b>On Behalf Of \
</b>Abaci B<br> <b>Sent:</b> Saturday, 27 February 2016 1:29 AM<br>
<b>To:</b> FreeSWITCH Users Help &lt;<a \
href="mailto:freeswitch-users@lists.freeswitch.org" \
target="_blank">freeswitch-users@lists.freeswitch.org</a>&gt;<br> <b>Subject:</b> Re: \
[Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra \
code to handle the return to the function</span><o:p></o:p></p> <div>
<div>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> \
<div> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">See <a \
href="https://freeswitch.org/confluence/display/FREESWITCH/Lua&#43;API&#43;Reference#LuaAPIReference-session:setHangupHook" \
target="_blank"> https://freeswitch.org/confluence/display/FREESWITCH/Lua&#43;API&#43;Reference#LuaAPIReference-session:setHangupHook</a> \
for a few ways to exit the lua script (error(), return &quot;exit&quot;, return \
&quot;die&quot;, s:destroy(&quot;error message&quot;)). I personally tried return \
&quot;exit&quot; 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.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> \
<div> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">On Thu, Feb 25, 2016 at \
9:33 PM, Andrew Keil &lt;<a href="mailto:andrew.keil@visytel.com" \
target="_blank">andrew.keil@visytel.com</a>&gt; wrote:<o:p></o:p></p> <blockquote \
style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm \
6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt"> <div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">To \
FreeSWITCH Users,<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">See \
below for a sample template for a Lua Service Script running inside \
FreeSWITCH.<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">The \
issue I have is fairly straightforward.<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.&nbsp; This function is \
CleanUp().&nbsp; Then I would  like the service to end.<o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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()).&nbsp; 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.<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
 <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">My \
aim is to reduce extra code and to make the Lua script simpler and easier to \
read.&nbsp; Also I would like to try and avoid goto statements, which I know can be \
done with if (session:ready())  etc….<o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">So is \
there a way to stop a Lua script running inside FreeSWITCH cleanly?&nbsp; I have \
tried the os.exit() this is barred from use by FreeSWITCH.&nbsp; 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!<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">FYI: \
Obviously the script below is simple, however I am sure that you understand if the \
script was complicated having to use "<b>if (session:ready()) then …."</b> or \
"<b>if (not  session:ready()) then goto HANGUPEXIT end"</b> makes the code \
ugly.<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thanks \
in advance,<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Andrew \
Keil<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b>Visytel Pty \
Ltd</b><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">------------------------------------------------------------------------------&nbsp; \
Sample Lua Service -----------------------------------------------------------------------<o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">-- Lua \
template for FreeSWITCH service<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">-- By: Andrew Keil \
(Visytel Pty Ltd)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">-- Email: <a \
href="mailto:support@visytel.com" target="_blank">support@visytel.com</a> <o:p> \
</o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">-- Setup \
script wide variables here<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">function \
PreAnswer()<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
freeswitch.consoleLog(&quot;INFO&quot;, &quot;PRE ANSWER \
SECTION\n&quot;);<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- Add your pre answer code from here<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- End of your pre answer code<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
freeswitch.consoleLog(&quot;INFO&quot;, &quot;PRE ANSWER SECTION \
COMPLETE\n&quot;);&nbsp; <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">function \
AnswerCaller()<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
session:answer()<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
session:sleep(1000)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">function \
MainService()<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
freeswitch.consoleLog(&quot;INFO&quot;, &quot;MAIN SERVICE \
SECTION\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
if (session:ready()) then<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- Note (1): If you wish to end the call then simply use: goto \
ENDSERVICE<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- Note (2): To terminate the service sooner when HANGUP is detected use: if (not \
session:ready()) then goto HANGUPEXIT end<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- Add your main service code from \
here&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
(caller would have been answered)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
session:streamFile(&quot;intro.wav&quot;)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
if (not session:ready()) then goto HANGUPEXIT end<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
session:streamFile(&quot;info.wav&quot;)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
if (not session:ready()) then goto HANGUPEXIT end<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
session:streamFile(&quot;outro.wav&quot;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
if (not session:ready()) then goto HANGUPEXIT end<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- End of your main service code <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
end<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
::ENDSERVICE::<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
if (session:ready()) then<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- End of service so hangup<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nb \
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
session:hangup()&nbsp; -- Should automatically jump to CleanUp() via hangup handler \
if caller still online at this stage<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
end<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
goto END<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
::HANGUPEXIT::<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
freeswitch.consoleLog(&quot;INFO&quot;, &quot;END OF SERVICE (HANGUP \
DETECTED)\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
::END::&nbsp; <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
freeswitch.consoleLog(&quot;INFO&quot;, &quot;MAIN SERVICE SECTION \
COMPLETE\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">end<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">function \
CleanUp()<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
freeswitch.consoleLog(&quot;INFO&quot;, &quot;CLEANUP SECTION\n&quot;); \
<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- Add your cleanup code from here (caller would have been \
disconnected)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
-- End of your cleanup code<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
freeswitch.consoleLog(&quot;INFO&quot;, &quot;CLEANUP SECTION \
COMPLETE\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">function \
myHangupHook(s, status, arg)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
session:hangup()<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
CleanUp() -- Run CleanUp function now since the caller has \
disconnected<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">end<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
 <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">-- \
Setup Hangup event handler here<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">v_hangup = \
&quot;HANGUP&quot;<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">session:setHangupHook(&quot;myHangupHook&quot;, \
&quot;v_hangup&quot;)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">-- Call \
service functions in order<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">PreAnswer()<o:p></o:p></p> \
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">AnswerCaller()<o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">MainService()<o:p></o:p></p>
 <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">-- \
End of Lua service<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
 </div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><br>
_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" \
target="_blank">consulting@freeswitch.org</a><br> <a \
href="http://www.freeswitchsolutions.com" \
target="_blank">http://www.freeswitchsolutions.com</a><br> <br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" \
target="_blank">http://confluence.freeswitch.org</a><br> <a \
href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br> <br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" \
target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br> <a \
href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" \
target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br> \
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" \
target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br> \
<a href="http://www.freeswitch.org" \
target="_blank">http://www.freeswitch.org</a><o:p></o:p></p> </blockquote>
</div>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> \
</div> </div>
</div>
</div>
</div>
<p class="MsoNormal"><br>
_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" \
target="_blank">consulting@freeswitch.org</a><br> <a \
href="http://www.freeswitchsolutions.com" \
target="_blank">http://www.freeswitchsolutions.com</a><br> <br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" \
target="_blank">http://confluence.freeswitch.org</a><br> <a \
href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br> <br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" \
target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br> <a \
href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" \
target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br> \
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" \
target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br> \
<a href="http://www.freeswitch.org" \
target="_blank">http://www.freeswitch.org</a><o:p></o:p></p> </blockquote>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
</body>
</html>



_________________________________________________________________________
Professional FreeSWITCH Consulting Services: 
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
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
--===============4586135281760174202==--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic