⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calllistener.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }                        if (response.getStatusCode()==180 && cseqHeader.getMethod().equals("INVITE") ) {                if ( callAssociation.firstCall.isOKReceived()) {                    // This is the RINGING from the callee                    // The From sip uri in the RINGING should match the user_name in the callee agent                    // The from sip uri is equivalent to the user_name in the callee agent in the first call                     String key=callAssociation.firstCall.toAgent.getSipURI();                     CallLauncherDebug.println("CallListener, ringing key:"+key);                     //callLauncher.controllerGUI.updateRow(key,"Ringing");                                   }                return;            }                if (response.getStatusCode()==200 && cseqHeader.getMethod().equals("INVITE") ) {                         if ( !callAssociation.firstCall.isOKReceived()) {                    // We received the OK for the first INVITE:                                        // Let's create the first hole for RTP:                    Object content=response.getContent();                    String text=null;                    if (content instanceof String)                        text=(String)content;                    else                        if (content instanceof byte[] ) {                            text=new String(  (byte[])content  );                        }                        else {                            if (content==null) {                                 CallLauncherDebug.println("CallListener, processResponse(), "+                                 "NO SDP content in 200 OK response from the first call, call aborted!");                                 return;                            }                        }                                        if (callLauncher.rtpHolesManager!=null) {                        // The first SDP is received let's open a hole:                                                firstRTPHole=callLauncher.rtpHolesManager.createRTPHole(                            callIdHeader.getCallId(),                            text,                            getOppositeSipStackAddress(holeIPAddress),                            holeIPAddress);                                               callAssociation.firstCall.setPeerSDP(firstRTPHole.getGeneratedSDPHole() );                                          }                    else {                        callAssociation.firstCall.setPeerSDP(text);                    }                                        if (clientTransaction.getDialog()==null) {                        CallLauncherDebug.println("CallListener, processResponse(), "+                        "NO Dialog related to the OK response from the first call, call aborted!");                        return;                    }                    callAssociation.firstCall.setDialog(clientTransaction.getDialog());                                      // Let's send the second INVITE:                   // CallId, sdp                   callAssociation.secondCall.sendInvite(callAssociation.firstCall.callId,                   callAssociation.firstCall.peerSDP);                    CallLauncherDebug.println("CallListener, Response processed");                                                      }                else                  if ( ! callAssociation.secondCall.isOKReceived()) {                    // We received the OK for the second INVITE:                                        // Let's create the second hole for RTP:                    Object content=response.getContent();                    String text=null;                    if (content instanceof String)                        text=(String)content;                    else                        if (content instanceof byte[] ) {                            text=new String(  (byte[])content  );                        }                        else {                            if (content==null) {                                 CallLauncherDebug.println("CallListener, processResponse(), "+                                 "NO SDP content in 200 OK response from the second call, call aborted!");                                 return;                            }                        }                                        if (callLauncher.rtpHolesManager!=null) {                        secondRTPHole=callLauncher.rtpHolesManager.createRTPHole(                            callIdHeader.getCallId(),                            text,                            getOppositeSipStackAddress(holeIPAddress),                            holeIPAddress);                                                                       firstRTPHole.open();                        secondRTPHole.open();                                                callAssociation.secondCall.setPeerSDP(secondRTPHole.getGeneratedSDPHole());                    }                    else {                        callAssociation.secondCall.setPeerSDP(text);                    }                     if (clientTransaction.getDialog()==null) {                        CallLauncherDebug.println("CallListener, processResponse(), "+                        "NO Dialog related to the OK response from the second call, call aborted!");                        return;                    }                    callAssociation.secondCall.setDialog(clientTransaction.getDialog());                                        // Let's send both ACK:                                     //callAssociation.firstCall.sendAck(callAssociation.secondCall.peerSDP);                    if (callLauncher.rtpHolesManager!=null) {                        callAssociation.firstCall.sendAck(secondRTPHole.getGeneratedSDPHole(),sipProvider );                    }                    else {                        callAssociation.firstCall.sendAck(text,sipProvider );                    }                    callAssociation.secondCall.sendAck(null,sipProvider);                                        CallLauncherDebug.println("CallListener, Response processed");                    String key=callAssociation.firstCall.toAgent.getSipURI();                    //callLauncher.controllerGUI.updateRow(key,"Connected");                   }                return;            }                        if ( (response.getStatusCode()==603 ||                   response.getStatusCode()==486)&& cseqHeader.getMethod().equals("INVITE") ) {                                       // Actually it's coming from MSN when rejecting an incoming INVITE.                // we can ignore it if the MSN is the first call we do, otherwise                // we have to send a BYE to the first call...                CallLauncherDebug.println("CallListener, Actually it can come from MSN or Ubiquity when "+                " rejecting an incoming INVITE.");                if (callAssociation.firstCall.isOKReceived()) {                    CallLauncherDebug.println("CallListener, The error is the second Call, so"+                    " we have to send a BYE to the first call...");                    callAssociation.firstCall.sendBye();                }                else {                    CallLauncherDebug.println("CallListener, We can ignore it because the MSN is the"+                    " first call we make.");                }                                        String key=callAssociation.firstCall.toAgent.getSipURI();                CallLauncherDebug.println("CallListener, BUSY or DECLINE  key:"+key);                //callLauncher.controllerGUI.updateRow(key,"Busy");                       }                                   // At this point the response is a retransmission... we drop it.                                    CallLauncherDebug.println("CallListener, Response processed");                    }        catch (Exception ex) {            if (CallLauncherDebug.debug) {                CallLauncherDebug.println("CallListener, processResponse(), internal error, "+                "exception raised:");                CallLauncherDebug.logException(ex);            }        }    }            /** JAIN Listener method.     */    public void processTimeout(TimeoutEvent timeOutEvent) {        CallLauncherDebug.println("CallListener, TimeoutEvent received");	    }               public ViaHeader getStackViaHeader(SipStack sipStack) {        try {            ListeningPoint lp =            (ListeningPoint)sipStack.getListeningPoints().next();            String host = sipStack.getIPAddress();            int port = lp.getPort();            String transport = lp.getTransport();            // branch id is assigned by the transaction layer.            return  headerFactory.createViaHeader            (host,port,transport,null);        }        catch (Exception e) {            if (CallLauncherDebug.debug) {                CallLauncherDebug.println("CallListener, getStackViaHeader(), internal error, "+                "exception raised:");                CallLauncherDebug.logException(e);            }            return null;        }    }        public ContactHeader getStackContactHeader(SipStack sipStack) {        try {            ListeningPoint lp =            (ListeningPoint)sipStack.getListeningPoints().next();            String host = sipStack.getIPAddress();            int port = lp.getPort();            String transport = lp.getTransport();                        SipURI sipURI=addressFactory.createSipURI(null,host);            sipURI.setPort(port);            sipURI.setTransportParam(transport);            Address contactAddress=addressFactory.createAddress(sipURI);                        return headerFactory.createContactHeader(contactAddress);        }        catch (Exception e) {            if (CallLauncherDebug.debug) {                CallLauncherDebug.println("CallListener, getStackContactHeader(), internal error, "+                "exception raised:");                CallLauncherDebug.logException(e);            }            return null;        }    }           public SipStack getSipStack(String toHostName) {        try {            CallLauncherDebug.println("CallListener, getSipStack(), we try to find the "+            " the appropriate stack to use for the destination: "+toHostName);            byte[] tab=null;            try{                InetAddress inet=InetAddress.getByName(toHostName);                tab=inet.getAddress();                for (int k=0;k<tab.length;k++) {                    int b=(0xff & tab[k]);                   // CallLauncherDebug.println("CallListener, getSipStack(), tab["+k+                   // "]:"+b);                }            }            catch(Exception e) {}            for (int i=0;i<sipStacksList.size();i++) {                SipStack sipStack=(SipStack)sipStacksList.elementAt(i);                String stackIPAddress=sipStack.getIPAddress();                if (stackIPAddress.equals(toHostName) ) {                    CallLauncherDebug.println("CallListener, getSipStack(), we return "+                    " the appropriate stack:"+stackIPAddress);                    return sipStack;                }                else {                    try{                        InetAddress inet=InetAddress.getByName(stackIPAddress);                        byte[] tabs=inet.getAddress();                                               for (int j=0;j<tabs.length;j++) {                            int b=(0xff & tabs[j]);                            //CallLauncherDebug.println("CallListener, getSipStack(), tabs["+j+                            //"]:"+b);                        }                        if (tab[0]==tabs[0] &&                            tab[1]==tabs[1] &&                            tab[2]==tabs[2]                         ) {                           CallLauncherDebug.println("CallListener, getSipStack(), we return "+                    " the appropriate stack:"+stackIPAddress);                            return sipStack;                        }                    }                    catch(Exception e) {}                }            }            CallLauncherDebug.println("CallListener, getSipStack(), we return the default stack:"+            ((SipStack)sipStacksList.firstElement()).getIPAddress() );            return (SipStack)sipStacksList.firstElement();        }        catch(Exception e) {            if (CallLauncherDebug.debug) {                CallLauncherDebug.println("CallListener, getSipStack(), internal error, "+                "exception raised:");                CallLauncherDebug.logException(e);            }            return null;        }    }         public String getOppositeSipStackAddress(String stackIPAddr) {        try {            CallLauncherDebug.println("CallListener, getOppositeSipStack(), we try to get "+            " the opposite stack for the destination:"+stackIPAddr);            for (int i=0;i<sipStacksList.size();i++) {                SipStack sipStack=(SipStack)sipStacksList.elementAt(i);                String stackIPAddress=sipStack.getIPAddress();                if (!stackIPAddress.equals(stackIPAddr) ) {                    CallLauncherDebug.println("CallListener, getOppositeSipStack(), we return "+                    " the opposite stack");                    return stackIPAddress;                }            }            CallLauncherDebug.println("CallListener, getOppositeSipStack(), we return the default stack");            return ((SipStack)sipStacksList.firstElement()).getIPAddress();        }        catch(Exception e) {            if (CallLauncherDebug.debug) {                CallLauncherDebug.println("CallListener, getOppositeSipStack(), internal error, "+                "exception raised:");                CallLauncherDebug.logException(e);            }            return null;        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -