Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[Freeswitch-users] Callback in Javascript, session.destroy() does not free the channel!


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users
View previous topic :: View next topic  
Author Message
pjintheusa at gmail.com
Guest





PostPosted: Thu Sep 17, 2009 4:59 pm    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

session.dispose();

???

On Thu, Sep 17, 2009 at 5:20 PM, Alberto Escudero <aep.lists@it46.se (aep.lists@it46.se)> wrote:
Quote:
We are trying to create a callback application in Javascript. We get the
callerid from the unanswered call and after destroying the session, we
initiate a callback to the user to conenct it to a local extension in the
dialplan.

Although we have tried to destroy the first session, or even invoke a
second script using apiExecute("jsrun",dialer.js"), tried session.hangup()
or exit()... the first session does not seem to close properly until the
whole chain of scripts are completed.

Here is a piece of code that shows the concept (yes!, the sleep function
is far from ideal. CPU loves it! )

function sleep(milliseconds) {
 var start = new Date().getTime();
 for (var i = 0; i < 1e7; i++) {
   if ((new Date().getTime() - start) > milliseconds){
     break;
   }
 }
}

if (session.ready()) {
       //We catch the caller_id
       caller_id_num = session.caller_id_num;

       console_log("Now we got your Caller ID\n");

       //How long we want to wait to trigger a call back
       session.execute("sleep",5000);

       console_log("We have waited a while... time to create the
callback\n");

       //apiExecute("jsrun", "callback.js");
       }

//Destroy the session...
session.destroy();
session=undefined;

sleep(10000);

//Preparing callback
session2 = new
Session('{ignore_early_media=true}celliax/interface1/600464646');
session2.setAutoHangup(false);
session2.answer();
exit();

++
Wisdom thoughts?

--
Stopping junk mailers is good for the environment




_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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
Back to top
mgg at giagnocavo.net
Guest





PostPosted: Thu Sep 17, 2009 5:19 pm    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

Dispose is a .NET only thing. But I think you are right – with anthm’s changes, any way you kill your session, if you’re on the right thread, it should really hangup.

-Michael

From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Phillip Jones
Sent: Thursday, September 17, 2009 3:38 PM
To: freeswitch-users@lists.freeswitch.org
Subject: Re: [Freeswitch-users] Callback in Javascript, session.destroy() does not free the channel!


session.dispose();

???
On Thu, Sep 17, 2009 at 5:20 PM, Alberto Escudero <aep.lists@it46.se (aep.lists@it46.se)> wrote:
We are trying to create a callback application in Javascript. We get the
callerid from the unanswered call and after destroying the session, we
initiate a callback to the user to conenct it to a local extension in the
dialplan.

Although we have tried to destroy the first session, or even invoke a
second script using apiExecute("jsrun",dialer.js"), tried session.hangup()
or exit()... the first session does not seem to close properly until the
whole chain of scripts are completed.

Here is a piece of code that shows the concept (yes!, the sleep function
is far from ideal. CPU loves it! )

function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}

if (session.ready()) {
//We catch the caller_id
caller_id_num = session.caller_id_num;

console_log("Now we got your Caller ID\n");

//How long we want to wait to trigger a call back
session.execute("sleep",5000);

console_log("We have waited a while... time to create the
callback\n");

//apiExecute("jsrun", "callback.js");
}

//Destroy the session...
session.destroy();
session=undefined;

sleep(10000);

//Preparing callback
session2 = new
Session('{ignore_early_media=true}celliax/interface1/600464646');
session2.setAutoHangup(false);
session2.answer();
exit();

++
Wisdom thoughts?

--
Stopping junk mailers is good for the environment




_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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
Back to top
gmaruzz at celliax.org
Guest





PostPosted: Thu Sep 17, 2009 6:32 pm    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

On Fri, Sep 18, 2009 at 12:08 AM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Quote:
Dispose is a .NET only thing. But I think you are right – with anthm’s
changes, any way you kill your session, if you’re on the right thread, it
should really hangup.


Problem is, we are trying to *not answer* the incoming call, get the
callid from the ring, destroy the session, create another session (on
the same, monoline interface), and make an outbound call.

Javascript (last svn) give us a

2009-09-18 01:18:49.291721 [ERR] inline:1 Session is not answered!

if we try to session.hangup() a session that was not answered (by the
way, it makes sense).

-giovanni




--
Sincerely,

Giovanni Maruzzelli
Cell : +39-347-2665618

_______________________________________________
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
Back to top
mgg at giagnocavo.net
Guest





PostPosted: Thu Sep 17, 2009 8:03 pm    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

Oh, weird. Seems to work in other languages.

-----Original Message-----
From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Giovanni Maruzzelli
Sent: Thursday, September 17, 2009 5:27 PM
To: freeswitch-users@lists.freeswitch.org
Subject: Re: [Freeswitch-users] Callback in Javascript, session.destroy() does not free the channel!

On Fri, Sep 18, 2009 at 12:08 AM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Quote:
Dispose is a .NET only thing. But I think you are right - with anthm's
changes, any way you kill your session, if you're on the right thread, it
should really hangup.


Problem is, we are trying to *not answer* the incoming call, get the
callid from the ring, destroy the session, create another session (on
the same, monoline interface), and make an outbound call.

Javascript (last svn) give us a

2009-09-18 01:18:49.291721 [ERR] inline:1 Session is not answered!

if we try to session.hangup() a session that was not answered (by the
way, it makes sense).

-giovanni




--
Sincerely,

Giovanni Maruzzelli
Cell : +39-347-2665618

_______________________________________________
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

_______________________________________________
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
Back to top
msc at freeswitch.org
Guest





PostPosted: Fri Sep 18, 2009 1:58 am    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

On Thu, Sep 17, 2009 at 5:53 PM, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:
Oh, weird. Seems to work in other languages.


Yet another reason to use Lua instead of JS. Smile
-MC
Back to top
mgg at giagnocavo.net
Guest





PostPosted: Fri Sep 18, 2009 2:25 am    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

Quote:
Yet another reason to use Lua F# instead of JS. Smile

Fixed that for ya

From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Michael Collins
Sent: Friday, September 18, 2009 12:45 AM
To: freeswitch-users@lists.freeswitch.org
Subject: Re: [Freeswitch-users] Callback in Javascript, session.destroy() does not free the channel!



On Thu, Sep 17, 2009 at 5:53 PM, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Oh, weird. Seems to work in other languages.


Yet another reason to use Lua instead of JS. Smile
-MC
Back to top
anthony.minessale at g...
Guest





PostPosted: Fri Sep 18, 2009 10:06 am    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

You could put an api_hangup_hook on the channel to jsrun your script.

What you want with javascript is not going to happen as long as you execute the script *WITH* the channel.
it's not a problem it's just misuse/misunderstanding on your part.



On Fri, Sep 18, 2009 at 5:03 AM, Alberto Escudero <aep.lists@it46.se (aep.lists@it46.se)> wrote:
Quote:
Thanks for all the tips. I tried to run apiExecute(bgapi, jsrun originate)
and still Javascript?? does not let the thread go.

No matter the combination of session.hangup(), exit, apiExecute with or
without bgapi, the state remains in CS_EXECUTE.

So at the end i am triggering an event that i can later use to execute a
originate callback. It is nicer with ESL but i still think that will be
nice to have a real way to expunge a second Javascript and let the first
one die.

The GSM channel/modem needs to be free-free (as I am a serial port-free)
to handle the outgoing call. The callback script worked perfect with SIP
because it does not care how many sessions are running in parallel. It can
always place a call back event the channel is not properly close.

/aep



--
Stopping junk mailers is good for the environment

Quote:
So, what happens is that when you are executing an app, the state is
CS_EXECUTE. Even if the session is hungup, the state machine doesn't go
through all the hangup code until your app executes.

The easiest workaround is probably to start a background api (bgapi?) call
to a script. This will happen on another thread, then allow your current
thread to execute and the hangup code will execute. This should work just
fine, I think. (You can stop reading here.)

But wait, there's even more fun! anthm recently checked in a change a
couple days that lets you work around this. Don't call destroy, call
hangup on the session, on that session's thread. This will perform a
hangup, then progress the state machine. Then the session will truly be
hungup. Maybe you need update your freeswitch code, if this is not
happening for you.

If you updated and hangup still isn't hanging up, you might want to ask
specifically about that. Or, you may need to call
switch_core_session_hangup_state directly -- just hangup alone might not
do the trick. This is a C function, and not exposed to languages by
default - you can either patch javascript plugin to expose this safely
(and I have no idea what this means for the javascript runtime), or use a
more capable plugin like mod_managed which _does_ expose all the C
functions, and lets you call in and out of them as you please.

And now, someone who knows what they're talking about will chime in and
point out what I got wrong.

Thanks,
-Michael

-----Original Message-----
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)
[mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of
Alberto Escudero
Sent: Thursday, September 17, 2009 3:20 PM
To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: [Freeswitch-users] Callback in Javascript, session.destroy() does
not free the channel!

We are trying to create a callback application in Javascript. We get the
callerid from the unanswered call and after destroying the session, we
initiate a callback to the user to conenct it to a local extension in the
dialplan.

Although we have tried to destroy the first session, or even invoke a
second script using apiExecute("jsrun",dialer.js"), tried session.hangup()
or exit()... the first session does not seem to close properly until the
whole chain of scripts are completed.

Here is a piece of code that shows the concept (yes!, the sleep function
is far from ideal. CPU loves it! )

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

if (session.ready()) {
        //We catch the caller_id
        caller_id_num = session.caller_id_num;

        console_log("Now we got your Caller ID\n");

        //How long we want to wait to trigger a call back
        session.execute("sleep",5000);

        console_log("We have waited a while... time to create the
callback\n");

        //apiExecute("jsrun", "callback.js");
        }

//Destroy the session...
session.destroy();
session=undefined;

sleep(10000);

//Preparing callback
session2 = new
Session('{ignore_early_media=true}celliax/interface1/600464646');
session2.setAutoHangup(false);
session2.answer();
exit();

++
Wisdom thoughts?

--
Stopping junk mailers is good for the environment




_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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

_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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





_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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





--
Anthony Minessale II

FreeSWITCH http://www.freeswitch.org/
ClueCon http://www.cluecon.com/
Twitter: http://twitter.com/FreeSWITCH_wire

AIM: anthm
MSN:anthony_minessale@hotmail.com ([email]MSN%3Aanthony_minessale@hotmail.com[/email])
GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com ([email]PAYPAL%3Aanthony.minessale@gmail.com[/email])
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888@conference.freeswitch.org ([email]sip%3A888@conference.freeswitch.org[/email])
iax:guest@conference.freeswitch.org/888
googletalk:conf+888@conference.freeswitch.org ([email]googletalk%3Aconf%2B888@conference.freeswitch.org[/email])
pstn:213-799-1400
Back to top
msc at freeswitch.org
Guest





PostPosted: Fri Sep 18, 2009 2:46 pm    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

FYI,

I did a POC on this:

<extension name="crazy_callback">  <condition field="destination_number" expression="^(\d{10})$">     <action application="set" data="luarun dump_arg.lua ${caller_id_number} ${caller_id_name}"/>  </condition> </extension>
dump_arg.lua:

-- dump_args.lua                                                                                                                                                -- print out the args                                                                                                                                                                                                                                                                                                           freeswitch.consoleLog("info", "Arg1: " .. argv[1] .. \n")                                                                                                      freeswitch.consoleLog("info", "Arg2: " .. argv[2] .. "\n")                                                                                                       

From there you can do whatever you want in the target script. I'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. Smile

-MC

On Fri, Sep 18, 2009 at 7:53 AM, Anthony Minessale <anthony.minessale@gmail.com (anthony.minessale@gmail.com)> wrote:
Quote:
You could put an api_hangup_hook on the channel to jsrun your script.

What you want with javascript is not going to happen as long as you execute the script *WITH* the channel.
it's not a problem it's just misuse/misunderstanding on your part.




On Fri, Sep 18, 2009 at 5:03 AM, Alberto Escudero <aep.lists@it46.se (aep.lists@it46.se)> wrote:
Quote:
Thanks for all the tips. I tried to run apiExecute(bgapi, jsrun originate)
and still Javascript?? does not let the thread go.

No matter the combination of session.hangup(), exit, apiExecute with or
without bgapi, the state remains in CS_EXECUTE.

So at the end i am triggering an event that i can later use to execute a
originate callback. It is nicer with ESL but i still think that will be
nice to have a real way to expunge a second Javascript and let the first
one die.

The GSM channel/modem needs to be free-free (as I am a serial port-free)
to handle the outgoing call. The callback script worked perfect with SIP
because it does not care how many sessions are running in parallel. It can
always place a call back event the channel is not properly close.

/aep



--
Stopping junk mailers is good for the environment

Quote:
So, what happens is that when you are executing an app, the state is
CS_EXECUTE. Even if the session is hungup, the state machine doesn't go
through all the hangup code until your app executes.

The easiest workaround is probably to start a background api (bgapi?) call
to a script. This will happen on another thread, then allow your current
thread to execute and the hangup code will execute. This should work just
fine, I think. (You can stop reading here.)

But wait, there's even more fun! anthm recently checked in a change a
couple days that lets you work around this. Don't call destroy, call
hangup on the session, on that session's thread. This will perform a
hangup, then progress the state machine. Then the session will truly be
hungup. Maybe you need update your freeswitch code, if this is not
happening for you.

If you updated and hangup still isn't hanging up, you might want to ask
specifically about that. Or, you may need to call
switch_core_session_hangup_state directly -- just hangup alone might not
do the trick. This is a C function, and not exposed to languages by
default - you can either patch javascript plugin to expose this safely
(and I have no idea what this means for the javascript runtime), or use a
more capable plugin like mod_managed which _does_ expose all the C
functions, and lets you call in and out of them as you please.

And now, someone who knows what they're talking about will chime in and
point out what I got wrong.

Thanks,
-Michael

-----Original Message-----
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)
[mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of
Alberto Escudero
Sent: Thursday, September 17, 2009 3:20 PM
To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: [Freeswitch-users] Callback in Javascript, session.destroy() does
not free the channel!

We are trying to create a callback application in Javascript. We get the
callerid from the unanswered call and after destroying the session, we
initiate a callback to the user to conenct it to a local extension in the
dialplan.

Although we have tried to destroy the first session, or even invoke a
second script using apiExecute("jsrun",dialer.js"), tried session.hangup()
or exit()... the first session does not seem to close properly until the
whole chain of scripts are completed.

Here is a piece of code that shows the concept (yes!, the sleep function
is far from ideal. CPU loves it! )

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

if (session.ready()) {
        //We catch the caller_id
        caller_id_num = session.caller_id_num;

        console_log("Now we got your Caller ID\n");

        //How long we want to wait to trigger a call back
        session.execute("sleep",5000);

        console_log("We have waited a while... time to create the
callback\n");

        //apiExecute("jsrun", "callback.js");
        }

//Destroy the session...
session.destroy();
session=undefined;

sleep(10000);

//Preparing callback
session2 = new
Session('{ignore_early_media=true}celliax/interface1/600464646');
session2.setAutoHangup(false);
session2.answer();
exit();

++
Wisdom thoughts?

--
Stopping junk mailers is good for the environment




_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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

_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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





_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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







--
Anthony Minessale II

FreeSWITCH http://www.freeswitch.org/
ClueCon http://www.cluecon.com/
Twitter: http://twitter.com/FreeSWITCH_wire

AIM: anthm
MSN:anthony_minessale@hotmail.com ([email]MSN%3Aanthony_minessale@hotmail.com[/email])
GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com ([email]PAYPAL%3Aanthony.minessale@gmail.com[/email])
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888@conference.freeswitch.org ([email]sip%3A888@conference.freeswitch.org[/email])
iax:guest@conference.freeswitch.org/888
googletalk:conf+888@conference.freeswitch.org ([email]googletalk%3Aconf%2B888@conference.freeswitch.org[/email])
pstn:213-799-1400

_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (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

Back to top
aep.lists at it46.se
Guest





PostPosted: Sat Sep 19, 2009 4:20 am    Post subject: [Freeswitch-users] Callback in Javascript, session.destroy() Reply with quote

Hi Michael,

I will like to get a few RINGS back to the user and sleep a bit before the
call back.
The second i can do using the app sleep.

What about the first thing?
http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_ring_ready

Will test i let you know...

Crazy Callbacker aka aep


--
Stopping junk mailers is good for the environment

Quote:
FYI,

I did a POC on this:

<extension name="crazy_callback">
<condition field="destination_number" expression="^(\d{10})$">
<action application="set" data="luarun dump_arg.lua
${caller_id_number}
${caller_id_name}"/>
</condition>
</extension>

dump_arg.lua:

--
dump_args.lua

-- print out the
args



freeswitch.consoleLog("info", "Arg1: " .. argv[1] ..
\n")

freeswitch.consoleLog("info", "Arg2: " .. argv[2] ..
"\n")



Quote:
From there you can do whatever you want in the target script. I'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. Smile

-MC

On Fri, Sep 18, 2009 at 7:53 AM, Anthony Minessale <
anthony.minessale@gmail.com> wrote:

Quote:
You could put an api_hangup_hook on the channel to jsrun your script.

What you want with javascript is not going to happen as long as you
execute
the script *WITH* the channel.
it's not a problem it's just misuse/misunderstanding on your part.




On Fri, Sep 18, 2009 at 5:03 AM, Alberto Escudero
<aep.lists@it46.se>wrote:

Quote:
Thanks for all the tips. I tried to run apiExecute(bgapi, jsrun
originate)
and still Javascript?? does not let the thread go.

No matter the combination of session.hangup(), exit, apiExecute with or
without bgapi, the state remains in CS_EXECUTE.

So at the end i am triggering an event that i can later use to execute
a
originate callback. It is nicer with ESL but i still think that will be
nice to have a real way to expunge a second Javascript and let the
first
one die.

The GSM channel/modem needs to be free-free (as I am a serial
port-free)
to handle the outgoing call. The callback script worked perfect with
SIP
because it does not care how many sessions are running in parallel. It
can
always place a call back event the channel is not properly close.

/aep


--
Stopping junk mailers is good for the environment

Quote:
So, what happens is that when you are executing an app, the state is
CS_EXECUTE. Even if the session is hungup, the state machine doesn't
go
Quote:
through all the hangup code until your app executes.

The easiest workaround is probably to start a background api (bgapi?)
call
Quote:
to a script. This will happen on another thread, then allow your
current
Quote:
thread to execute and the hangup code will execute. This should work
just
Quote:
fine, I think. (You can stop reading here.)

But wait, there's even more fun! anthm recently checked in a change a
couple days that lets you work around this. Don't call destroy, call
hangup on the session, on that session's thread. This will perform a
hangup, then progress the state machine. Then the session will truly
be
Quote:
hungup. Maybe you need update your freeswitch code, if this is not
happening for you.

If you updated and hangup still isn't hanging up, you might want to
ask
Quote:
specifically about that. Or, you may need to call
switch_core_session_hangup_state directly -- just hangup alone might
not
Quote:
do the trick. This is a C function, and not exposed to languages by
default - you can either patch javascript plugin to expose this
safely
Quote:
(and I have no idea what this means for the javascript runtime), or
use
a
Quote:
more capable plugin like mod_managed which _does_ expose all the C
functions, and lets you call in and out of them as you please.

And now, someone who knows what they're talking about will chime in
and
Quote:
point out what I got wrong.

Thanks,
-Michael

-----Original Message-----
From: freeswitch-users-bounces@lists.freeswitch.org
[mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of
Alberto Escudero
Sent: Thursday, September 17, 2009 3:20 PM
To: freeswitch-users@lists.freeswitch.org
Subject: [Freeswitch-users] Callback in Javascript, session.destroy()
does
Quote:
not free the channel!

We are trying to create a callback application in Javascript. We get
the
Quote:
callerid from the unanswered call and after destroying the session,
we
Quote:
initiate a callback to the user to conenct it to a local extension in
the
Quote:
dialplan.

Although we have tried to destroy the first session, or even invoke a
second script using apiExecute("jsrun",dialer.js"), tried
session.hangup()
Quote:
or exit()... the first session does not seem to close properly until
the
Quote:
whole chain of scripts are completed.

Here is a piece of code that shows the concept (yes!, the sleep
function
Quote:
is far from ideal. CPU loves it! )

function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}

if (session.ready()) {
//We catch the caller_id
caller_id_num = session.caller_id_num;

console_log("Now we got your Caller ID\n");

//How long we want to wait to trigger a call back
session.execute("sleep",5000);

console_log("We have waited a while... time to create the
callback\n");

//apiExecute("jsrun", "callback.js");
}

//Destroy the session...
session.destroy();
session=undefined;

sleep(10000);

//Preparing callback
session2 = new
Session('{ignore_early_media=true}celliax/interface1/600464646');
session2.setAutoHangup(false);
session2.answer();
exit();

++
Wisdom thoughts?

--
Stopping junk mailers is good for the environment




_______________________________________________
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
Quote:
http://www.freeswitch.org

_______________________________________________
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
Quote:
http://www.freeswitch.org





_______________________________________________
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




--
Anthony Minessale II

FreeSWITCH http://www.freeswitch.org/
ClueCon http://www.cluecon.com/
Twitter: http://twitter.com/FreeSWITCH_wire

AIM: anthm
MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com>
GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com>
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org>
iax:guest@conference.freeswitch.org/888
googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org>
pstn:213-799-1400

_______________________________________________
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


_______________________________________________
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




_______________________________________________
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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services