In my application, I seldom route calls. The task is to use FS as a automated business coordinator over phone. Users call the system to update their information and raise requests. The system collect these information and upload to database. With real-time data, FS make decision and give out instruction through SMS or out-going calls.<div>
In this interesting situation, Freeswitch become Never-Switch, because it takes the responsibility itself to communicate with each caller/callee instead of switching to others.</div><div>That&#39;s why my script become complex.<br>
<br><div class="gmail_quote">On Sat, Jul 24, 2010 at 8:03 AM, Sergey Okhapkin <span dir="ltr">&lt;<a href="mailto:sos@sokhapkin.dyndns.org">sos@sokhapkin.dyndns.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Which task do you want to accomplish? To me dynamic generation of FS dialplan<br>
from a script (language doesn&#39;t matter)  works better than realtime call flow<br>
control from a script, event socket etc. I do call routing, no PBX functions.<br>
<div><div></div><div class="h5"><br>
On Friday 23 July 2010, xuyan yang wrote:<br>
&gt; I know the solution of putting &quot;if(!session.ready())exit()&quot; to every check<br>
&gt; point. But as my script already has nearly 3000 lines, there are too<br>
&gt; many &quot;if(!session.ready())exit()&quot; to add.<br>
&gt;<br>
&gt; I tried error();  it works just because error is not defined. Using<br>
&gt; intentional mistake to force exit is creative but strange.<br>
&gt; After some thoughts I found that throw a user defined exception in the hook<br>
&gt; may be a better way to force exit without the red [ERR] line.<br>
&gt;<br>
&gt; By the way, I still feel that let exit() in the hook stop the whole script<br>
&gt; instead of the hook only seems to be more consistent because they are<br>
&gt; not executed in separate thread. Would you please consider this if it is<br>
&gt;  not difficult? Thanks.<br>
&gt;<br>
&gt;<br>
&gt; On Sat, Jul 24, 2010 at 6:17 AM, Anthony Minessale &lt;<br>
&gt;<br>
&gt; <a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>&gt; wrote:<br>
&gt; &gt; if session.ready is false it means the channel is hungup.<br>
&gt; &gt;<br>
&gt; &gt; error(); will exit your script.<br>
&gt; &gt;<br>
&gt; &gt; you can probably remove some of them if you are getting better results<br>
&gt; &gt; with the patch.<br>
&gt; &gt;<br>
&gt; &gt; On Fri, Jul 23, 2010 at 4:56 PM, xuyan yang &lt;<a href="mailto:xyangni@gmail.com">xyangni@gmail.com</a>&gt; wrote:<br>
&gt; &gt;&gt; Thanks for your update. I have tested it again base on the latest git<br>
&gt; &gt;&gt; tree, the hangup hook does work every time and the script continue to<br>
&gt; &gt;&gt; run without error message.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; But this behaviour change caused another problem as I still need to stop<br>
&gt; &gt;&gt; the script when the session is hangup.<br>
&gt; &gt;&gt; Adding if(session.ready()) to every line of my script does not seem to<br>
&gt; &gt;&gt; be a good solution. So I decided to call exit() in the hangup hook.<br>
&gt; &gt;&gt; However the test result is that exit() in hangup hook only works the<br>
&gt; &gt;&gt; same as &quot;return&quot;. That means exit() in hangup hook only stops the hook<br>
&gt; &gt;&gt; while the main program can not be stopped.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Is there any good solution to stop the script immediately when hangup?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; On Sat, Jul 24, 2010 at 3:13 AM, Anthony Minessale &lt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; <a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>&gt; wrote:<br>
&gt; &gt;&gt;&gt; give lastest HEAD a try, I pushed in some more checks and made calling<br>
&gt; &gt;&gt;&gt; session.hangup() nonfatal when it&#39;s already hungup.<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; On Fri, Jul 23, 2010 at 1:27 PM, xuyan yang &lt;<a href="mailto:xyangni@gmail.com">xyangni@gmail.com</a>&gt; wrote:<br>
&gt; &gt;&gt;&gt;&gt; I added many session.ready() as below and re-do the test again.<br>
&gt; &gt;&gt;&gt;&gt; the steps are:<br>
&gt; &gt;&gt;&gt;&gt; 1. type jsrun test.js   in fs_cli<br>
&gt; &gt;&gt;&gt;&gt; 2. answer the call in x-lite.<br>
&gt; &gt;&gt;&gt;&gt; 3. when I hear the speech, hangup the call in about 1 second.<br>
&gt; &gt;&gt;&gt;&gt; 4 check the log to find  &quot;hangup!!!!!!!!!!!!!&quot;<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; the result is that<br>
&gt; &gt;&gt;&gt;&gt;  about half of the test failed to call hangup hook.<br>
&gt; &gt;&gt;&gt;&gt; in all tests the script end up with [ERR] inline:1 Session is not<br>
&gt; &gt;&gt;&gt;&gt; active!    then the script stopped and session.ready() near the end<br>
&gt; &gt;&gt;&gt;&gt; can not get the chance to run.<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; ////test.js<br>
&gt; &gt;&gt;&gt;&gt; function on_hangup(session, how){<br>
&gt; &gt;&gt;&gt;&gt;  console_log(&quot;notice&quot;,&quot;hangup!!!!!!!!!!!!!\n&quot;);<br>
&gt; &gt;&gt;&gt;&gt; }<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; session = new Session(&quot;sofia/gateway/12voip-out/*********&quot;);<br>
&gt; &gt;&gt;&gt;&gt; session.waitForAnswer();<br>
&gt; &gt;&gt;&gt;&gt; session.ready();<br>
&gt; &gt;&gt;&gt;&gt; session.execute(&quot;set&quot;,&quot;continue_on_fail=true&quot;);<br>
&gt; &gt;&gt;&gt;&gt; var res=session.setHangupHook(on_hangup);<br>
&gt; &gt;&gt;&gt;&gt; console_log(&quot;notice&quot;,&quot;res:&quot;+res+&quot;\n&quot;);<br>
&gt; &gt;&gt;&gt;&gt; if(session.ready())session.execute(&quot;speak&quot;, &quot;This is an example of<br>
&gt; &gt;&gt;&gt;&gt; flite text to speech engine. We can test the work of hanguphook.&quot;);<br>
&gt; &gt;&gt;&gt;&gt; if(session.ready())session.execute(&quot;speak&quot;,&quot;you are calling from &quot; +<br>
&gt; &gt;&gt;&gt;&gt; session.caller_id_num + &quot; You are calling &quot; + session.destination );<br>
&gt; &gt;&gt;&gt;&gt; session.ready();<br>
&gt; &gt;&gt;&gt;&gt; session.hangup();<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; On Sat, Jul 24, 2010 at 1:08 AM, Anthony Minessale &lt;<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; <a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>&gt; wrote:<br>
&gt; &gt;&gt;&gt;&gt;&gt; It checks before and after blocking calls like that.<br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; On Jul 23, 2010 11:53 AM, &quot;Dan&quot; &lt;<a href="mailto:freeswitch-users@digitaldan.com">freeswitch-users@digitaldan.com</a>&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; wrote:<br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;  So If I call session.recordFile which blocks in code until the user<br>
&gt; &gt;&gt;&gt;&gt;&gt; hangs up, and can&#39;t make periodic calls to session.ready,  is the<br>
&gt; &gt;&gt;&gt;&gt;&gt; hangup hook not realiable in this scenario?<br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; ------------------------------<br>
&gt; &gt;&gt;&gt;&gt;&gt; *From: *&quot;Anthony Minessale&quot; &lt;<a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; *To: *&quot;FreeSWITCH Users Help&quot; &lt;<a href="mailto:freeswitch-users@lists.freeswitch.org">freeswitch-users@lists.freeswitch.org</a>&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; *Sent: *Thursday, July 22, 2010 10:30:48 AM<br>
&gt; &gt;&gt;&gt;&gt;&gt; *Subject: *Re: [Freeswitch-users] Unstable hangup hook in javascript<br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; You must make periodic calls to session.ready() or some other<br>
&gt; &gt;&gt;&gt;&gt;&gt; freeswitch api functions to trigger ...<br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt; &gt;&gt;&gt;&gt;&gt; FreeSWITCH-users mailing list<br>
&gt; &gt;&gt;&gt;&gt;&gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; &gt;&gt;&gt;&gt;&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt; &gt;&gt;&gt;&gt;&gt; UNSUBSCRIBE:<br>
&gt; &gt;&gt;&gt;&gt;&gt; <a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
&gt; &gt;&gt;&gt;&gt;&gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt; &gt;&gt;&gt;&gt;&gt; FreeSWITCH-users mailing list<br>
&gt; &gt;&gt;&gt;&gt;&gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; &gt;&gt;&gt;&gt;&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt; &gt;&gt;&gt;&gt;&gt; UNSUBSCRIBE:<br>
&gt; &gt;&gt;&gt;&gt;&gt; <a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
&gt; &gt;&gt;&gt;&gt;&gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; _______________________________________________<br>
&gt; &gt;&gt;&gt;&gt; FreeSWITCH-users mailing list<br>
&gt; &gt;&gt;&gt;&gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; &gt;&gt;&gt;&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt; &gt;&gt;&gt;&gt; UNSUBSCRIBE:<br>
&gt; &gt;&gt;&gt;&gt; <a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
&gt; &gt;&gt;&gt;&gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; --<br>
&gt; &gt;&gt;&gt; Anthony Minessale II<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>
&gt; &gt;&gt;&gt; ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
&gt; &gt;&gt;&gt; Twitter: <a href="http://twitter.com/FreeSWITCH_wire" target="_blank">http://twitter.com/FreeSWITCH_wire</a><br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; AIM: anthm<br>
</div></div>&gt; &gt;&gt;&gt; <a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a> &lt;<a href="mailto:MSN%253Aanthony_minessale@hotmail.com">MSN%3Aanthony_minessale@hotmail.com</a>&gt;<br>

&gt; &gt;&gt;&gt; GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a>&lt;PAYPAL%3Aanthony.miness<br>
<div class="im">&gt; &gt;&gt;&gt;<a href="mailto:ale@gmail.com">ale@gmail.com</a>&gt; IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; FreeSWITCH Developer Conference<br>
</div>&gt; &gt;&gt;&gt; <a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a> &lt;<a href="mailto:sip%253A888@conference.freeswitch.org">sip%3A888@conference.freeswitch.org</a>&gt;<br>

&gt; &gt;&gt;&gt; <a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a>&lt;googletalk%3Aconf%2B888@c<br>
<div class="im">&gt; &gt;&gt;&gt;<a href="http://onference.freeswitch.org" target="_blank">onference.freeswitch.org</a>&gt; pstn:+19193869900<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; _______________________________________________<br>
&gt; &gt;&gt;&gt; FreeSWITCH-users mailing list<br>
&gt; &gt;&gt;&gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; &gt;&gt;&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt; &gt;&gt;&gt; UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-user" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-user</a><br>
</div>&gt; &gt;&gt;&gt;s <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<div class="im">&gt; &gt;&gt;<br>
&gt; &gt;&gt; _______________________________________________<br>
&gt; &gt;&gt; FreeSWITCH-users mailing list<br>
&gt; &gt;&gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; &gt;&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt; &gt;&gt; UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
&gt; &gt;&gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt; &gt;<br>
&gt; &gt; --<br>
&gt; &gt; Anthony Minessale II<br>
&gt; &gt;<br>
&gt; &gt; FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>
&gt; &gt; ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
&gt; &gt; Twitter: <a href="http://twitter.com/FreeSWITCH_wire" target="_blank">http://twitter.com/FreeSWITCH_wire</a><br>
&gt; &gt;<br>
&gt; &gt; AIM: anthm<br>
</div>&gt; &gt; <a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a> &lt;<a href="mailto:MSN%253Aanthony_minessale@hotmail.com">MSN%3Aanthony_minessale@hotmail.com</a>&gt;<br>
&gt; &gt; GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a>&lt;PAYPAL%3Aanthony.minessal<br>
<div class="im">&gt; &gt;<a href="mailto:e@gmail.com">e@gmail.com</a>&gt; IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br>
&gt; &gt;<br>
&gt; &gt; FreeSWITCH Developer Conference<br>
</div>&gt; &gt; <a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a> &lt;<a href="mailto:sip%253A888@conference.freeswitch.org">sip%3A888@conference.freeswitch.org</a>&gt;<br>
&gt; &gt; <a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a>&lt;googletalk%3Aconf%2B888@con<br>
<div><div></div><div class="h5">&gt; &gt;<a href="http://ference.freeswitch.org" target="_blank">ference.freeswitch.org</a>&gt; pstn:+19193869900<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; FreeSWITCH-users mailing list<br>
&gt; &gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; &gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt; &gt; UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
&gt; &gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt;<br>
<br>
<br>
_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">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><br>
</div></div></blockquote></div><br></div>