Javascript Misc bridge

From FreeSWITCH Wiki
Jump to: navigation, search

Contents

Description

Bridges 2 channels together.

Synopsis

bridge(session1, session2 [[, <callback>], <callback_args>])

Callback

function <callback> ( session, type, dtmf, user_data  ) {
   .. do something ..
   return <value>; 
}

Arguments:

  • session - is the session where the event was generated.
  • type - is the type of event.
  • dtmf - dtmf.digit and dtmf.duration are part of the dtmf object so you can not only get the digit but the duration that it was pressed.
  • user_data - are the arguments passed to the callback from the bridge function.

The callback is launched every time when dtmf is generated on either one of the channels.

Return values:

  • true - keep going, do not interrupt the current bridge.
  • false - stop, and exit the current bridge.

Example

new_session = new Session(session, "sofia/sip/1234@10.10.2.55");
bridge(session, new_session);
new_session.hangup();

Example2

This sequence will print "This is from callback under the rock" in the FS console and will recall mycall@mydomain.com every time someone presses a key on either of the call legs

function callback ( session, type, dtmf, user_data) {
 console_log("WARNING","This is from callback "+user_data.param);
 return false;
}
session.answer();
while ( session.ready() ) {
  var bleg=new Session("sofia/sip/mycall@mydomain.com");
  bridge(session,bleg,callback,{param:"under the rock"});
}