FYI,<br><br>I did a POC on this:<br><br><span style="font-family: courier new,monospace;">&lt;extension name=&quot;crazy_callback&quot;&gt;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  &lt;condition field=&quot;destination_number&quot; expression=&quot;^(\d{10})$&quot;&gt;</span><br style="font-family: courier new,monospace;">
<font face="courier new,monospace">    &lt;action application=&quot;set&quot; data=&quot;luarun dump_arg.lua ${caller_id_number} ${caller_id_name}&quot;/&gt;<br style="font-family: courier new,monospace;"></font><span style="font-family: courier new,monospace;">  &lt;/condition&gt;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&lt;/extension&gt;</span><br style="font-family: courier new,monospace;"><br>dump_arg.lua:<br><br><span style="font-family: courier new,monospace;">-- dump_args.lua                                                                                                                                                </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">-- print out the args                                                                                                                                           </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                                                                                                                                                                </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">freeswitch.consoleLog(&quot;info&quot;, &quot;Arg1: &quot; .. argv[1] .. \n&quot;)                                                                                                      </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">freeswitch.consoleLog(&quot;info&quot;, &quot;Arg2: &quot; .. argv[2] .. &quot;\n&quot;)                                                                                                      </span><br style="font-family: courier new,monospace;">
 <br><br>From there you can do whatever you want in the target script. I&#39;m sure perlrun, pyrun, and jsrun are all the same in terms of accepting args and running whatever you want, like generating an originate API, etc. Just remember that the caller needs to hangup before you can call him back. :)<br>
<br>-MC<br><br><div class="gmail_quote">On Fri, Sep 18, 2009 at 7:53 AM, Anthony Minessale <span dir="ltr">&lt;<a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You could put an api_hangup_hook on the channel to jsrun your script.<br><br>What you want with javascript is not going to happen as long as you execute the script *WITH* the channel.<br>it&#39;s not a problem it&#39;s just misuse/misunderstanding on your part.<div>
<div></div><div class="h5"><br>
<br><br><br><div class="gmail_quote">On Fri, Sep 18, 2009 at 5:03 AM, Alberto Escudero <span dir="ltr">&lt;<a href="mailto:aep.lists@it46.se" target="_blank">aep.lists@it46.se</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Thanks for all the tips. I tried to run apiExecute(bgapi, jsrun originate)<br>
and still Javascript?? does not let the thread go.<br>
<br>
No matter the combination of session.hangup(), exit, apiExecute with or<br>
without bgapi, the state remains in CS_EXECUTE.<br>
<br>
So at the end i am triggering an event that i can later use to execute a<br>
originate callback. It is nicer with ESL but i still think that will be<br>
nice to have a real way to expunge a second Javascript and let the first<br>
one die.<br>
<br>
The GSM channel/modem needs to be free-free (as I am a serial port-free)<br>
to handle the outgoing call. The callback script worked perfect with SIP<br>
because it does not care how many sessions are running in parallel. It can<br>
always place a call back event the channel is not properly close.<br>
<br>
/aep<br>
<div><div></div><div><br>
<br>
--<br>
Stopping junk mailers is good for the environment<br>
<br>
&gt; So, what happens is that when you are executing an app, the state is<br>
&gt; CS_EXECUTE. Even if the session is hungup, the state machine doesn&#39;t go<br>
&gt; through all the hangup code until your app executes.<br>
&gt;<br>
&gt; The easiest workaround is probably to start a background api (bgapi?) call<br>
&gt; to a script. This will happen on another thread, then allow your current<br>
&gt; thread to execute and the hangup code will execute. This should work just<br>
&gt; fine, I think. (You can stop reading here.)<br>
&gt;<br>
&gt; But wait, there&#39;s even more fun! anthm recently checked in a change a<br>
&gt; couple days that lets you work around this. Don&#39;t call destroy, call<br>
&gt; hangup on the session, on that session&#39;s thread. This will perform a<br>
&gt; hangup, then progress the state machine. Then the session will truly be<br>
&gt; hungup. Maybe you need update your freeswitch code, if this is not<br>
&gt; happening for you.<br>
&gt;<br>
&gt; If you updated and hangup still isn&#39;t hanging up, you might want to ask<br>
&gt; specifically about that. Or, you may need to call<br>
&gt; switch_core_session_hangup_state directly -- just hangup alone might not<br>
&gt; do the trick. This is a C function, and not exposed to languages by<br>
&gt; default - you can either patch javascript plugin to expose this safely<br>
&gt; (and I have no idea what this means for the javascript runtime), or use a<br>
&gt; more capable plugin like mod_managed which _does_ expose all the C<br>
&gt; functions, and lets you call in and out of them as you please.<br>
&gt;<br>
&gt; And now, someone who knows what they&#39;re talking about will chime in and<br>
&gt; point out what I got wrong.<br>
&gt;<br>
&gt; Thanks,<br>
&gt; -Michael<br>
&gt;<br>
&gt; -----Original Message-----<br>
&gt; From: <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a><br>
&gt; [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>] On Behalf Of<br>
&gt; Alberto Escudero<br>
&gt; Sent: Thursday, September 17, 2009 3:20 PM<br>
&gt; To: <a href="mailto:freeswitch-users@lists.freeswitch.org" target="_blank">freeswitch-users@lists.freeswitch.org</a><br>
&gt; Subject: [Freeswitch-users] Callback in Javascript, session.destroy() does<br>
&gt; not free the channel!<br>
&gt;<br>
&gt; We are trying to create a callback application in Javascript. We get the<br>
&gt; callerid from the unanswered call and after destroying the session, we<br>
&gt; initiate a callback to the user to conenct it to a local extension in the<br>
&gt; dialplan.<br>
&gt;<br>
&gt; Although we have tried to destroy the first session, or even invoke a<br>
&gt; second script using apiExecute(&quot;jsrun&quot;,dialer.js&quot;), tried session.hangup()<br>
&gt; or exit()... the first session does not seem to close properly until the<br>
&gt; whole chain of scripts are completed.<br>
&gt;<br>
&gt; Here is a piece of code that shows the concept (yes!, the sleep function<br>
&gt; is far from ideal. CPU loves it! )<br>
&gt;<br>
&gt; function sleep(milliseconds) {<br>
&gt;   var start = new Date().getTime();<br>
&gt;   for (var i = 0; i &lt; 1e7; i++) {<br>
&gt;     if ((new Date().getTime() - start) &gt; milliseconds){<br>
&gt;       break;<br>
&gt;     }<br>
&gt;   }<br>
&gt; }<br>
&gt;<br>
&gt; if (session.ready()) {<br>
&gt;         //We catch the caller_id<br>
&gt;         caller_id_num = session.caller_id_num;<br>
&gt;<br>
&gt;         console_log(&quot;Now we got your Caller ID\n&quot;);<br>
&gt;<br>
&gt;         //How long we want to wait to trigger a call back<br>
&gt;         session.execute(&quot;sleep&quot;,5000);<br>
&gt;<br>
&gt;         console_log(&quot;We have waited a while... time to create the<br>
&gt; callback\n&quot;);<br>
&gt;<br>
&gt;         //apiExecute(&quot;jsrun&quot;, &quot;callback.js&quot;);<br>
&gt;         }<br>
&gt;<br>
&gt; //Destroy the session...<br>
&gt; session.destroy();<br>
&gt; session=undefined;<br>
&gt;<br>
&gt; sleep(10000);<br>
&gt;<br>
&gt; //Preparing callback<br>
&gt; session2 = new<br>
&gt; Session(&#39;{ignore_early_media=true}celliax/interface1/600464646&#39;);<br>
&gt; session2.setAutoHangup(false);<br>
&gt; session2.answer();<br>
&gt; exit();<br>
&gt;<br>
&gt; ++<br>
&gt; Wisdom thoughts?<br>
&gt;<br>
&gt; --<br>
&gt; Stopping junk mailers is good for the environment<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; FreeSWITCH-users mailing list<br>
&gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&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; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; FreeSWITCH-users mailing list<br>
&gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&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; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
<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><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div>-- <br>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>

Twitter: <a href="http://twitter.com/FreeSWITCH_wire" target="_blank">http://twitter.com/FreeSWITCH_wire</a><br><br>AIM: anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com" target="_blank">MSN:anthony_minessale@hotmail.com</a><br>
GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com" target="_blank">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br><br>FreeSWITCH Developer Conference<br><a href="mailto:sip%3A888@conference.freeswitch.org" target="_blank">sip:888@conference.freeswitch.org</a><br>
<a href="http://iax:guest@conference.freeswitch.org/888" target="_blank">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org" target="_blank">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:213-799-1400<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>
<br></blockquote></div><br>