Dynamic/Manage SIP Legs
I just wanted a sanity check (* everything seems to work), to see if this looks ok to those in the know or to help others looking for similar solution:
in AMS5/Server.xml enabled registry:
| <Registry enabled="true"> | |||
| <!-- Adaptor to run registry core on --> | |||
| <AdaptorName>_defaultRoot_</AdaptorName> | |||
| </Registry> |
AMG/conf/rtmp.xml:
<Server host = "localhost">sip01</Server>
<Server host = "localhost">sip02</Server>
<Server host = "localhost">sip03</Server>
<Server host = "localhost">sip04</Server>
<Server host = "localhost">sip05</Server>
<Server host = "localhost">sip06</Server>
<Server host = "localhost">sip07</Server>
<Server host = "localhost">sip08</Server>
<Server host = "localhost">sip09</Server>
<Server host = "localhost">sip10</Server><!---->
</LegService>
<ControlService>
<!-- List of AMS & service names for ControlService registry connections -->
<!-- Format is <Server host = "server IP/hostname">servicename</Server> -->
<!-- Sample entry: <Server host = "localhost">telephony_control</Server>-->
<Server host = "localhost">sip01_control</Server>
<Server host = "localhost">sip02_control</Server>
<Server host = "localhost">sip03_control</Server>
<Server host = "localhost">sip04_control</Server>
<Server host = "localhost">sip05_control</Server>
<Server host = "localhost">sip06_control</Server>
<Server host = "localhost">sip07_control</Server>
<Server host = "localhost">sip08_control</Server>
<Server host = "localhost">sip09_control</Server>
<Server host = "localhost">sip10_control</Server><!---->
</ControlService>
<EnableAutoConnect>false</EnableAutoConnect>
appcode:
application.onAppStart = function(){
load("TelephonyLib/CallLegServiceClient.asc");
var serviceConnected = false;
application.legService = new CallLegService();
application.legService.setLogLevel("warning");
application.legService.ready = false;
}
Client.prototype.startSipLeg= function(classObj){
application.phoneID=classObj.confID;
application.globalVars_so.setProperty("phoneID",classObj.confID);
StartConferenceAMG();
}
function StartConferenceAMG(){
clearInterval(reconnectInterval);
trace("!!!!startStopConference"+application.prefix+" "+application.phoneID);
var callConferenceNumber = parseInt(application.prefix+""+application.phoneID);
application.legService.createCall(application.phoneID, callConferenceNumber);
}
function sipClose(){
trace("---sipClose---");
application.legService.setLegStateHangup(application.phoneID);
application.legService.setServer(null);
application.legService=null;
}
application.onConnect = function(pclient, params){
if(pclient.agent.indexOf( "FMG ")!=-1){//avoid using legs when session ends
if (application.globalVars_so.getProperty("appEnded")==true && application.isLive ){
this.rejectConnection(pclient);
return;
}
}
if(pclient.agent == "FMG Aux Leg Service 1.0"){
trace("(C) 1 client.agent:"+pclient.agent);
// If we are sure that it is FMG Aux Leg Service
// then let it connect.
if (application.SIPLegs["SIP"]!=undefined){
this.rejectConnection(pclient);
return;
}
trace("(W) A Aux Leg Service connecting");
//if(this.legService.isConnected)return;
application.SIPLegs["SIP"]=pclient;
pclient.audioSampleAccess="/";
pclient.videoSampleAccess ="/";
this.acceptConnection(pclient);
return;
}else if (pclient.agent == "FMG Leg Service 1.0"){
//
trace("(C) 2 client.agent:"+pclient.agent);
// Discard if legService is already connected.
if(!this.legService.isConnected){
// **************** Required ************************
// Passing the pclient object to our legService object
// application.legService would use it communicate with
// AMG.
// **************************************************
this.legService.setServer(pclient);
serviceConnected = true;
this.acceptConnection(pclient);
trace("*******(W) A Leg Service now connected");
//this.acceptConnection(pclient)
// Now this application is all set send/recieve voice
// calls using FMG leg service APIs !!
// **************************************************
}else{
trace("[SIP](R) A Leg Service rejection");
// [Modification Tip] : Add code to disconnect this pclient here
// as LegService is already running
this.rejectConnection(pclient);
}
return;
}
application.legService.onLegMessage = function(info){
trace("onLegMessage");
trace("info.legID::"+info.legID);
}
function sipDisconnect(client){
if(client.agent == "FMG Aux Leg Service 1.0"){
return;
}
if(client.agent == "FMG Leg Service 1.0"){
// FMG call Leg service has disconnected
if(client == application.legService.callLegServiceClient){
trace("FMG Call Leg Service got disconected");
application.legService.setServer(null);
}
}
application.legService.onError = function(info){
trace("(E) LEGservice Error onleg");
readObj(info);
if (info.type == "legService.error.createCall"){//try again
//application.legService.createCall(info.metadata.callerID, info.metadata.calleeID);
reconnectInterval= setInterval(StartConferenceAMG,3000)
}
}
application.legService.onLeg = function(info){
var targetID; // targetID: the phoneID this call Leg belongs to.
if(info.isOriginating){
// It is a call leg originated from this application (via createCall API)
// i.e. an outgoing call for flash client
targetID = info.callerID;
}else{trace("(E) why is AMG calling here?");}
trace("TargetID:"+ targetID);
// trying to find whether this app has a flash client
// with phone number equal matching targetID.
if(application.phoneID != -1){
// Found the matching flash client.
trace ("<<legService.onLeg>> subscriber found. accepting");
application.conferenceStream= info.incomingStream;
// Store info.legID as property of client object
// This will help refer this call leg util it hangup
application.legID = info.legID;
//now go ahead and send the stream info to all users in the class
//whatevvssss....
// Returning true makes AMG wait for a response
// (from flash phone) until timout(60 seconds) expires.
return true;
}
else{
trace("(E) Phone number not found, rejecting a call leg");
// returning false indicates AMG to interrupt the initialization
// this call leg immediatly.
return false;
}
}
Client.prototype.MGCallLegServiceMessage = function(info){
trace(" @@## MGCallLegServiceMessage");
}
//called when stream needs to be added from flash client
function sipAddOutsideStream(stream){
application.legService.pushNewStream(application.phoneID,stream.name);
}
application.legService.onLegStatus = function(info){
trace("----------onLegStatus!!");
readObj(info);
return;
}
