Freeswitch creating more then two sessions for one call
Following is the js i am using to select route and bridge the call.... use("ODBC"); var DSN = "myodbc"; var DB_USER = "neo"; var DB_PASS = "....."; var sql; var prefix1; var ip1; var no2; var bridge_str; if(argv[0]=="") exit(); if(argv[1]=="") exit(); ip1 =argv[0].split("@")[1]; var no1=argv[1]; var sql = "SELECT id,prefix,name FROM internal_auth where substring('"+no1+"',1,length(prefix))=prefix and ip='" + ip1 +"' and active=1;"; var authName=""; var db = new ODBC(DSN, DB_USER, DB_PASS); db.connect(); db.query(sql); if(db.nextRow()) { var row = db.getData(); if (row["id"] == "" ) { console_log("Err", "auth failed(0001)\t" + no1 + "\targ[0]=>" + argv[0] + "\targ[1]=>" + argv[1] + "\n"); db.close(); exit(); } prefix1=row["prefix"]; authName=row["name"]; }else{ console_log("Err", "auth failed(0001)\t" + no1 + "\targ[0]=>" + argv[0] + "\targ[1]=>" + argv[1] + "\n"); db.close(); exit(); } no2=no1.substring(prefix1.length, no1.length); sql = "SELECT ec.* FROM auth_routes_carriers arc,external_carriers ec, codes c where arc.external_carriers_id = ec.id and arc.code_id = c.id and substring('"+no2+"',1,length(c.code))=c.code and ec.active=1 order by arc.priority asc"; db.connect(); db.query(sql); var carriersName=""; bridge_str=''; while(db.nextRow()) { var row = db.getData(); if (row["id"] != "" ) { bridge_str = row["gateway"]+row["prefix"]+no2+"\@"+row["ip"]; carriersName = row["name"]; break; } } db.close(); if(bridge_str != ''){ if(session.ready()) session.execute("bridge", bridge_str); } else { console_log("Err", "external carrier not found.\t" + no2 + "\targ[0]=>" + argv[0] + "\targ[1]=>" + argv[1] + "\n"); exit(); } exit();
Some thoughts: 1) look at mod_lcr 2) comments on script below... On Sat, Jun 6, 2009 at 2:53 AM, Shoaib Khanzada <skhanzada@gmail.com> wrote:
Following is the js i am using to select route and bridge the call....
use("ODBC");
var DSN = "myodbc"; var DB_USER = "neo"; var DB_PASS = ".....";
[...]
var db = new ODBC(DSN, DB_USER, DB_PASS);
db.connect();
[...]
sql = "SELECT ec.* FROM auth_routes_carriers arc,external_carriers ec, codes c where arc.external_carriers_id = ec.id and arc.code_id = c.id and substring('"+no2+"',1,length(c.code))=c.code and ec.active=1 order by arc.priority asc";
db.connect();
no need to reconnect
db.query(sql);
[...]
if(bridge_str != ''){ if(session.ready()) session.execute("bridge", bridge_str);
Don't actually execute the bridge from javascript. Instead, set the bridge_str to a channel var and then do the bridge from the dialplan using that bridge_str. This way you don't have a javascript interpreter lying around for the duration of the call. -- -Rupa
participants (2)
-
Rupa Schomaker
-
Shoaib Khanzada