[Freeswitch-users] How to bridge 2 sessions with Javascript?

Brian West brian.west at mac.com
Thu Mar 27 19:49:40 PDT 2008


If you change this one line:

> if (session1.ready() && new_session.ready()) {

session1 = new Session();
session1.originate(session, "{ignore_early_media=true}sofia/gateway/ 
asterlink.com/19184249378");

new_session = new Session();
new_session.originate(session, "{ignore_early_media=true}sofia/gateway/ 
asterlink.com/19184238080");

bridge(session1,  
new_session 
);                                                                                                                              	
// this line is key.
while (session1.ready() && new_session.ready()) {
  // do nothing
}

This also means the first leg calling 500 will be up till the call  
ends.. this is not the most optimal way of doing it.... It also means  
you can't hangup the first leg till you're 100% sure the third leg is  
up or all legs will hang up and the call will fail.  You might want to  
learn about jsrun.  For example if you take that script above and do  
"jsrun script.js" it'll perform the same thing without the extra leg.

/b


On Mar 27, 2008, at 9:10 PM, Nicolas Brenner wrote:
> Hello everybody again,
>
> First of all I want to say thanks to the people on this list and on
> IRC, I'm really surprised (in a very good way) of the help I've
> received.
>
> Now to my problem: I'm trying to bridge two SIP calls together with a
> JS script, and to achieve it, I'm did the following:
> - created a dialplan entry for extension 500 which calls js script
> - created a js script with the following code:
>
> // Create new_session
> session1 = new Session();
> session1.originate(session,
> "{ignore_early_media=true}sofia/gateway/sip.sipdiscount.com/ 
> 005624949458");
> session1.waitForAnswer(10000);
>
> new_session = new Session();
> new_session.originate(session,
> "{ignore_early_media=true}sofia/gateway/sip.sipdiscount.com/ 
> 0056979039388",
> 30);
> new_session.waitForAnswer(10000);
>
> // IF everybody is ready, then bridge our current session & the  
> new_session
> if (session1.ready() && new_session.ready()) {
>        console_log("info", "Interoligofrenico!\n");
>    bridge(session1, new_session);
> }
>
> // hangup when done
> session1.hangup();
> new_session.hangup();
>
> When I register with extension 1000 using a softphone and dial
> extension 500, the code above successfully creates the two new
> sessions, makes the calls in order, and supposedly bridges the
> sessions (I get no error about the bridge on the console, and I get
> the log text too), but I get no audio on either end. Anybody know
> what's wrong with the code?
>
> Btw, how can I originate a call to a configure extension? All examples
> on the wiki use the 'sofia syntax', should I just use
> sofia/default/1001 for example?
>
> Thanks!
>
> Nicolas
>
> _______________________________________________
> Freeswitch-users mailing list
> Freeswitch-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org





More information about the FreeSWITCH-users mailing list