Skip to main content
astro44
Inspiring
December 27, 2013
Answered

Dynamic/Manage SIP Legs

  • December 27, 2013
  • 1 reply
  • 1693 views

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;

}

This topic has been closed for replies.
Correct answer astro44

do I have to manage SIP in AMS SSAS ?

Yes

if we are handling SIP in AMG then why we need to handle this AMG leg service seperately in AMS SSAS?

AMG can be setup to automatically connect to SSAS as the documentation and the download of AMS will have scripts ready to do that for you.  However if you want more control and dynamically manage the calls between multiple instances on AMS then you'll need to disable the autoconnect feature and manage the legs on each instance. (*which is what I have done above)

1 reply

Known Participant
April 2, 2014

We have a virtual class room application (like WizIQ) and I want SIP users to dial in to the class room. I have configured AMG with AMS where our SSAS is hosted. Now if I enable AutoConnect in AMG profiles then I get below error.

DEBUG   1073742997 RTMP 32433   Received onStatus <NetConnection.Call.Failed> code <error> classType <Method not found (MGCallLegServiceMessage).> description <(null)> details

And when I try to dial my application instance I get an error that RTMP profile is not connected.

DEBUG   1073742997 CALLLEG      32433   [LEG ID:3] - Execute bridge(rtmp|${destNum}@ams2_aws)

DEBUG   1073742997 CALLLEG      32433   [LEG ID:3] - Expanded String bridge(rtmp|7777@ams2_aws) (ID:1)

DEBUG   1073742997 SIPLEG       32433   [LEG ID:3] - Call in progress

INFO    1073742997 CALLLEG      32433   [LEG ID:3] - Ringing

DEBUG   1073742997 CALLLEG      32433   [LEG ID:4] - Allocated new Call Leg(rtmp)

ERROR   1073742997 RTMPLEG      32433   [LEG ID:4] - Destination rtmp profile/URL (rtmp://ams.teletaaleem.com/vod/_definst_) not connected

ERROR   1073742997 CALLLEG      32433   [LEG ID:4] - cannot create call Leg

DEBUG   1073742997 CALLLEG      32433   [LEG ID:4] - Cleaning up Leg [ALLOC]

ERROR   1073742997 CALLLEG      32433   [LEG ID:3] - Error Creating Call Leg for destination rtmp|7777@ams2_aws

DEBUG   1073742997 CALLLEG      32433   [LEG ID:3] - App  bridge(rtmp|7777@ams2_aws) Returns 4 (next ID:1)

DEBUG   1073742997 CALLLEG      32433   [LEG ID:3] - Execute hangup(null)

DEBUG   1073742997 CALLLEG      32433   [LEG ID:3] - Hangup Call (cause 200), from FMSMGBasicAppNodes.cpp:235

INFO    1073742997 CALLLEG      32433   [LEG ID:3] - Hangup [EXEC] [Not_found]

do I have to manage SIP in AMS SSAS ? if we are handling SIP in AMG then why we need to handle this AMG leg service seperately in AMS SSAS?

astro44
astro44AuthorCorrect answer
Inspiring
May 6, 2014

do I have to manage SIP in AMS SSAS ?

Yes

if we are handling SIP in AMG then why we need to handle this AMG leg service seperately in AMS SSAS?

AMG can be setup to automatically connect to SSAS as the documentation and the download of AMS will have scripts ready to do that for you.  However if you want more control and dynamically manage the calls between multiple instances on AMS then you'll need to disable the autoconnect feature and manage the legs on each instance. (*which is what I have done above)

Known Participant
May 20, 2014

Hi,

I embedded/merged your script with our SSAS. Now my leg service is connected but when I dial AMS from my sip phone AMG doesn't answer or bridge the RTMP/SIP-RTP audio stream. Stream is created and published in AMS as I can see from the wireshark dump and AMS admin console. Can you please advise what exactly I am missing out here ? I have pasted AMG logs, RTMP capture and SIP capture. Please note that both AMG and AMS are installed on the same server and I am testing it on a local LAN.

In SIP traces I  can see that AMG is not answering the call i.e. I am not getting 200-OK after INVITE and 100-TRYING.

AMG logs

2014-05-20::17:09:11.755        DEBUG   1073742997 CORE 23060   num matches: 1

2014-05-20::17:09:11.755        DEBUG   1073742997 CALLLEG      23060   [LEG ID:1] - Execute bridge(rtmp|${destNum}@t2ams)

2014-05-20::17:09:11.755        DEBUG   1073742997 CALLLEG      23060   [LEG ID:1] - Expanded String bridge(rtmp|9999@t2ams) (ID:1)

2014-05-20::17:09:11.755        DEBUG   1073742997 SIPLEG       23060   [LEG ID:1] - Call in progress

2014-05-20::17:09:11.755        INFO    1073742997 CALLLEG      23060   [LEG ID:1] - Ringing

2014-05-20::17:09:11.755        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - Allocated new Call Leg(rtmp)

2014-05-20::17:09:11.756        INFO    1073742997 RTMPLEG      23060   [LEG ID:2] - setting silence level to 0 for Leg

2014-05-20::17:09:11.756        INFO    1073742997 RTMPLEG      23060   [LEG ID:2] - setting silence Timeout to 5000 for Leg

2014-05-20::17:09:11.756        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - Going For State 0

2014-05-20::17:09:11.756        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - State ALLOC

2014-05-20::17:09:11.792        INFO    1073742997 RTMP 23060   Received onStatus <Success> code <status> classType <StreamCreated> description <> details

2014-05-20::17:09:11.794        INFO    1073742997 RTMP 23060   Received onStatus <NetStream.Publish.Start> code <status> classType <fmg/AutoConnect/1 is now published.> description <(null)> details

2014-05-20::17:09:11.816        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - State Change ALLOC -> START

2014-05-20::17:09:11.816        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - Going For State 1

2014-05-20::17:09:11.817        DEBUG   1073742997 RTMPLEG      23060   [LEG ID:2] - Inside start handler

2014-05-20::17:09:11.817        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - Call Leg START

2014-05-20::17:09:25.701        ERROR   1073742997 RTMP 23060   Received Invalid Command on NetConnection:_OnServerHeartBeat, Message Dropped

2014-05-20::17:09:45.700        ERROR   1073742997 RTMP 23060   Received Invalid Command on NetConnection:_OnServerHeartBeat, Message Dropped

2014-05-20::17:09:51.606        DEBUG   1073742997 SIP  23060   Local Interface : 192.168.1.109 will be used

2014-05-20::17:09:51.606        DEBUG   1073742997 SIP  23060   Registration successful for profile sipPhone2

2014-05-20::17:10:05.699        ERROR   1073742997 RTMP 23060   Received Invalid Command on NetConnection:_OnServerHeartBeat, Message Dropped

2014-05-20::17:10:11.388        DEBUG   1073742997 SIP  23060   Remote SIP address not initialize yet for Profile sipPhone

2014-05-20::17:10:11.762        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - Timeout waiting for Answer on Call

2014-05-20::17:10:11.762        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - Hangup Call (cause 408), from FMSMGAppNodesHelper.cpp:529

2014-05-20::17:10:11.762        INFO    1073742997 CALLLEG      23060   [LEG ID:2] - Hangup [START] [Request_timeout]

2014-05-20::17:10:11.762        ERROR   1073742997 CALLLEG      23060   [LEG ID:1] - Error Creating Call Leg for destination rtmp|9999@t2ams

2014-05-20::17:10:11.762        DEBUG   1073742997 CALLLEG      23060   [LEG ID:1] - App  bridge(rtmp|9999@t2ams) Returns 2 (next ID:1)

2014-05-20::17:10:11.762        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - Going For State 7

2014-05-20::17:10:11.762        DEBUG   1073742997 CALLLEG      23060   [LEG ID:1] - Execute hangup(null)

2014-05-20::17:10:11.762        DEBUG   1073742997 CALLLEG      23060   [LEG ID:2] - Call Leg HANGUP, cause: Request_timeout

2014-05-20::17:10:11.762        INFO    1073742997 CALLLEG      23060   [LEG ID:2] - CallLeg Ended

RTMP network capture (using tshark)

277.991307    127.0.0.1 -> 127.0.0.1    RTMP 312 createStream() | MGCallLegServiceMessage()

277.991475    127.0.0.1 -> 127.0.0.1    RTMP 109 _result()

277.991616    127.0.0.1 -> 127.0.0.1    RTMP 127 publish('fmg/AutoConnect/1')

277.992596    127.0.0.1 -> 127.0.0.1    RTMP 241 Set Chunk Size 1024 | onStatus('NetStream.Publish.Start')

278.010156    127.0.0.1 -> 127.0.0.1    RTMP 269 MGLegServiceMessage()

278.015654    127.0.0.1 -> 127.0.0.1    RTMP 225 MGCallLegServiceMessage()

SIP network capture (using tshark)

12  31.896848 192.168.1.100 -> 192.168.1.109 SIP/SDP 968 Request: INVITE sip:9999@192.168.1.109;transport=UDP |

31.897834 192.168.1.109 -> 192.168.1.100 SIP 511 Status: 407 Proxy Authentication Required |

31.914622 192.168.1.100 -> 192.168.1.109 SIP 436 Request: ACK sip:9999@192.168.1.109;transport=UDP |

31.914640 192.168.1.100 -> 192.168.1.109 SIP/SDP 1209 Request: INVITE sip:9999@192.168.1.109;transport=UDP |

31.915874 192.168.1.109 -> 192.168.1.100 SIP 387 Status: 100 Trying |

91.926390 192.168.1.109 -> 192.168.1.100 SIP 400 Status: 408 Request Timeout |

92.029868 192.168.1.100 -> 192.168.1.109 SIP 436 Request: ACK sip:9999@192.168.1.109;transport=UDP |