The route.js script file content
################
Engine.debugName("route");
Message.trackName(Engine.debugName());
line = "asteradmin";
line.count = 0;
line.max = 2;
line.chans = [];
function onHangup(msg)
{
var id = "" + msg.id;
var idx = line.chans.indexOf(id);
if (idx >= 0) {
line.count--;
delete line.chans[idx];
Engine.debug(Engine.DebugAll,"Line " + line + " removed chan " + id +
" count=" + line.count);
}
return false;
}
function onRoute(msg)
{
var called = "" + msg.called;
if (!called)
return false;
if (called.startsWith("456")) {
// Route to 'someprovider' line
if (line.count >= line.max) {
msg.retValue("-");
// Return some error (optional)
msg.error = "busy";
return true;
}
line.chans.push(msg.id);
line.count++;
Engine.debug(Engine.DebugAll,"Line " + line + " added chan " + msg.id +
" count=" + line.count);
msg.line = line;
msg.forward_sdp = true;
msg.callername = msg.caller;
msg.formats = "alaw,mulaw,g729";
msg.retValue("sip/99013307" + called.substr(2));
return true;
}
return false;
}
Message.install(onHangup,"chan.hangup");
Message.install(onRoute,"call.route",10);