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

Alberto Escudero aep.lists at it46.se
Thu Sep 17 14:20:14 PDT 2009


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







More information about the FreeSWITCH-users mailing list