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's not a problem it's just misuse/misunderstanding on your part.<br>
<br><br><br><div class="gmail_quote">On Fri, Sep 18, 2009 at 5:03 AM, Alberto Escudero <span dir="ltr"><<a href="mailto:aep.lists@it46.se">aep.lists@it46.se</a>></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 class="h5"><br>
<br>
--<br>
Stopping junk mailers is good for the environment<br>
<br>
> So, what happens is that when you are executing an app, the state is<br>
> CS_EXECUTE. Even if the session is hungup, the state machine doesn't go<br>
> through all the hangup code until your app executes.<br>
><br>
> The easiest workaround is probably to start a background api (bgapi?) call<br>
> to a script. This will happen on another thread, then allow your current<br>
> thread to execute and the hangup code will execute. This should work just<br>
> fine, I think. (You can stop reading here.)<br>
><br>
> But wait, there's even more fun! anthm recently checked in a change a<br>
> couple days that lets you work around this. Don't call destroy, call<br>
> hangup on the session, on that session's thread. This will perform a<br>
> hangup, then progress the state machine. Then the session will truly be<br>
> hungup. Maybe you need update your freeswitch code, if this is not<br>
> happening for you.<br>
><br>
> If you updated and hangup still isn't hanging up, you might want to ask<br>
> specifically about that. Or, you may need to call<br>
> switch_core_session_hangup_state directly -- just hangup alone might not<br>
> do the trick. This is a C function, and not exposed to languages by<br>
> default - you can either patch javascript plugin to expose this safely<br>
> (and I have no idea what this means for the javascript runtime), or use a<br>
> more capable plugin like mod_managed which _does_ expose all the C<br>
> functions, and lets you call in and out of them as you please.<br>
><br>
> And now, someone who knows what they're talking about will chime in and<br>
> point out what I got wrong.<br>
><br>
> Thanks,<br>
> -Michael<br>
><br>
> -----Original Message-----<br>
> From: <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org">freeswitch-users-bounces@lists.freeswitch.org</a><br>
> [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org">freeswitch-users-bounces@lists.freeswitch.org</a>] On Behalf Of<br>
> Alberto Escudero<br>
> Sent: Thursday, September 17, 2009 3:20 PM<br>
> To: <a href="mailto:freeswitch-users@lists.freeswitch.org">freeswitch-users@lists.freeswitch.org</a><br>
> Subject: [Freeswitch-users] Callback in Javascript, session.destroy() does<br>
> not free the channel!<br>
><br>
> We are trying to create a callback application in Javascript. We get the<br>
> callerid from the unanswered call and after destroying the session, we<br>
> initiate a callback to the user to conenct it to a local extension in the<br>
> dialplan.<br>
><br>
> Although we have tried to destroy the first session, or even invoke a<br>
> second script using apiExecute("jsrun",dialer.js"), tried session.hangup()<br>
> or exit()... the first session does not seem to close properly until the<br>
> whole chain of scripts are completed.<br>
><br>
> Here is a piece of code that shows the concept (yes!, the sleep function<br>
> is far from ideal. CPU loves it! )<br>
><br>
> function sleep(milliseconds) {<br>
> var start = new Date().getTime();<br>
> for (var i = 0; i < 1e7; i++) {<br>
> if ((new Date().getTime() - start) > milliseconds){<br>
> break;<br>
> }<br>
> }<br>
> }<br>
><br>
> if (session.ready()) {<br>
> //We catch the caller_id<br>
> caller_id_num = session.caller_id_num;<br>
><br>
> console_log("Now we got your Caller ID\n");<br>
><br>
> //How long we want to wait to trigger a call back<br>
> session.execute("sleep",5000);<br>
><br>
> console_log("We have waited a while... time to create the<br>
> callback\n");<br>
><br>
> //apiExecute("jsrun", "callback.js");<br>
> }<br>
><br>
> //Destroy the session...<br>
> session.destroy();<br>
> session=undefined;<br>
><br>
> sleep(10000);<br>
><br>
> //Preparing callback<br>
> session2 = new<br>
> Session('{ignore_early_media=true}celliax/interface1/600464646');<br>
> session2.setAutoHangup(false);<br>
> session2.answer();<br>
> exit();<br>
><br>
> ++<br>
> Wisdom thoughts?<br>
><br>
> --<br>
> Stopping junk mailers is good for the environment<br>
><br>
><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>
><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>
><br>
<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><br clear="all"><br>-- <br>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/">http://www.cluecon.com/</a><br>
Twitter: <a href="http://twitter.com/FreeSWITCH_wire">http://twitter.com/FreeSWITCH_wire</a><br><br>AIM: anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net">irc.freenode.net</a> #freeswitch<br><br>FreeSWITCH Developer Conference<br><a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br><a href="http://iax:guest@conference.freeswitch.org/888">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:213-799-1400<br>