?? messengermanager.java
字號(hào):
messageListener.getConfiguration().contactIPAddress, listeningPoint.getPort(), listeningPoint.getTransport(), null); viaHeaders.add(viaHeader); //Max Forward Header - just forward by one hop. MaxForwardsHeader maxForwardsHeader = MessageListener.headerFactory.createMaxForwardsHeader(2); Request request = MessageListener.messageFactory.createRequest( requestURI, requestName, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwardsHeader); //Contact Header SipURI contactURI = MessageListener.addressFactory.createSipURI( caller.getUser(), messageListener.getConfiguration().contactIPAddress); contactURI.setTransportParam( messageListener.getConfiguration().signalingTransport); ContactHeader contactHeader = MessageListener.headerFactory.createContactHeader( MessageListener.addressFactory.createAddress(contactURI)); contactURI.setPort(listeningPoint.getPort()); request.addHeader(contactHeader); //Route Header /** * SipURI routeURI= MessageListener.addressFactory.createSipURI( * null, * messageListener.getConfiguration().outboundProxy); * routeURI.setPort(messageListener.getConfiguration().proxyPort); * routeURI.setTransportParam(messageListener.getConfiguration().signalingTransport); * RouteHeader routeHeader = MessageListener.headerFactory.createRouteHeader( * MessageListener.addressFactory.createAddress(routeURI)); * request.addHeader(routeHeader); **/ return request; } catch (Exception ex) { ex.printStackTrace(); System.out.println( "Something bad happened when creating request!!"); System.out.println("method = " + requestName); System.out.println("caller = " + caller); System.out.println("caller = " + callee); return null; } } /** * Send A Register to the proxy with the authentication acquired from the user. * @param userName - the user name * @param password - the password's user * @param realm - the realm's user * TODO : Keep a trace of the expires and schedule a new registration */ public void registerWithAuthentication( String userName, String password, String realm) { //WE start the authentication process!!! // Let's get the Request related to this response: Request request = registerStatus.getRegisterTransaction().getRequest(); if (request == null) { System.out.println( "IMUserAgent, processResponse(), the request " + " that caused the 407 has not been retrieved!!! Return cancelled!"); } else { Request clonedRequest = (Request) request.clone(); // Let's increase the Cseq: CSeqHeader cseqHeader = (CSeqHeader) clonedRequest.getHeader(CSeqHeader.NAME); try { cseqHeader.setSequenceNumber( cseqHeader.getSequenceNumber() + 1); } catch (InvalidArgumentException iae) { iae.printStackTrace(); } // Let's add a Proxy-Authorization header: // We send the informations stored: Header header = registerStatus.getHeader( registerStatus.getRegisterResponse(), userName, password, messageListener.getConfiguration().outboundProxy, messageListener.getConfiguration().proxyPort); if (header == null) { System.out.println( "IMUserAgent, processResponse(), Proxy-Authorization " + " header is null, the request is not resent"); } else { clonedRequest.setHeader(header); ClientTransaction newClientTransaction = null; try { newClientTransaction = messageListener.sipProvider.getNewClientTransaction( clonedRequest); } catch (TransactionUnavailableException tue) { tue.printStackTrace(); } try { newClientTransaction.sendRequest(); } catch (SipException se) { se.printStackTrace(); } System.out.println( "IMUserAgent, processResponse(), REGISTER " + "with credentials sent:\n" + clonedRequest); System.out.println(); } } } /** * Send A Register to the proxy. * TODO : Keep a trace of the expires and schedule a new registration */ public void register() { SipURI proxyURI = null; try { proxyURI = MessageListener.addressFactory.createSipURI( null, messageListener.getConfiguration().outboundProxy); proxyURI.setPort(messageListener.getConfiguration().proxyPort); } catch (ParseException pe) { pe.printStackTrace(); } Request request = createRequest(Request.REGISTER, userSipURI, userSipURI); // Resource to which this is directed is the proxy. request.setRequestURI(proxyURI); //Transaction ClientTransaction regTrans = null; try { regTrans = messageListener.sipProvider.getNewClientTransaction(request); // System.out.println(request.toString()); regTrans.sendRequest(); this.setRegisterStatus(RegisterStatus.REGISTRATION_IN_PROGRESS); } catch (TransactionUnavailableException ex) { System.out.println( "Could not create a register transaction!\n" + "Check that the Registrar address is correct!" + " " + ex); } catch (SipException ex) { System.out.println( "Could not send out the register request! " + ex); ex.printStackTrace(); } } public void unRegisterAndReRegister() { this.reRegisterFlag = true; this.deRegister(); } public void unRegister() { this.reRegisterFlag = false; this.deRegister(); } /** * Stop the registration */ private void deRegister() { SipURI proxyURI = null; try { proxyURI = MessageListener.addressFactory.createSipURI( null, messageListener.getConfiguration().outboundProxy); proxyURI.setPort(messageListener.getConfiguration().proxyPort); } catch (ParseException pe) { pe.printStackTrace(); } Request request = createRequest(Request.REGISTER, userSipURI, userSipURI); // Direct the request towards the proxy. request.setRequestURI(proxyURI); //ExpiresHeader try { ExpiresHeader expires = MessageListener.headerFactory.createExpiresHeader(0); request.setHeader(expires); } catch (InvalidArgumentException iae) { iae.printStackTrace(); } ContactHeader contactHeader = MessageListener.headerFactory.createContactHeader(); request.setHeader(contactHeader); //Transaction ClientTransaction regTrans = null; regTrans = messageListener.sipProvider.getNewClientTransaction(request); System.out.println(request.toString()); regTrans.sendRequest(); } catch (TransactionUnavailableException ex) { System.out.println( "Could not create a un-register transaction!\n" + "Check that the Registrar address is correct!" + " " + ex); } catch (SipException ex) { System.out.println( "Could not send out the un-register request! " + ex); ex.printStackTrace(); } } /** * Create the SDP body of the INVITE message * for the initiation of the media session */ private String createSDPBody(int audioPort) { try { SdpFactory sdpFactory = SdpFactory.getInstance(); SessionDescription sessionDescription = sdpFactory.createSessionDescription(); //Protocol version Version version = sdpFactory.createVersion(0); sessionDescription.setVersion(version); //Owner long sdpSessionId=(long)(Math.random() * 1000000); Origin origin = sdpFactory.createOrigin( userSipURI.getUser(), sdpSessionId, sdpSessionId+1369, "IN", "IP4", messageListener.getConfiguration().contactIPAddress); sessionDescription.setOrigin(origin); //Session Name SessionName sessionName = sdpFactory.createSessionName("-"); sessionDescription.setSessionName(sessionName); //Connection Connection connection = sdpFactory.createConnection( messageListener.getConfiguration().contactIPAddress); sessionDescription.setConnection(connection); //Time Time time = sdpFactory.createTime(); Vector timeDescriptions = new Vector(); timeDescriptions.add(time); sessionDescription.setTimeDescriptions(timeDescriptions); //Media Description MediaDescription mediaDescription = sdpFactory.createMediaDescription( "audio", audioPort, 1, "RTP/AVP", MediaManager.getSdpAudioSupportedCodecs()); Vector mediaDescriptions = new Vector(); mediaDescriptions.add(mediaDescription); sessionDescription.setMediaDescriptions(mediaDescriptions); return sessionDescription.toString(); } catch (SdpException se) { se.printStackTrace(); } return null; } /** * Send an Invite to the sip URI in parameter * @param calleeURI - the URI of the user to call * @param sdpBody - the sdp content describing the media session * to include to the message */ private void sendInvite(String calleeURI, String sdpBody) { if (calleeURI.indexOf("sip:") != -1) calleeURI = calleeURI.substring("sip:".length()); //Request URI SipURI contactURI = null; try { //Create the SIP URI for the user URI String user = calleeURI.substring(0, calleeURI.indexOf("@")); String host = calleeURI.substring( calleeURI.indexOf("@") + 1, calleeURI.length()); contactURI = MessageListener.addressFactory.createSipURI(user, host); } catch (ParseException pe) { pe.printStackTrace(); } Request invite = createRequest(Request.INVITE, contactURI, userSipURI); // Indicate to the other end the type of media I am willing to accept. try { if (messageListener .getConfiguration() .mediaTransport .equalsIgnoreCase("tcp")){ AcceptHeader acceptHeader = MessageListener.headerFactory.createAcceptHeader( "audio", "gsm"); invite.addHeader(acceptHeader); acceptHeader = MessageListener.headerFactory.createAcceptHeader( "audio", "x-gsm"); invite.addHeader(acceptHeader); acceptHeader = MessageListener.headerFactory.createAcceptHeader( "text", "plain"); invite.addHeader(acceptHeader); } //Content ContentTypeHeader contentTypeHeader = null; if (sdpBody != null) { contentTypeHeader = MessageListener.headerFactory.createContentTypeHeader( "application", "sdp"); invite.setContent(sdpBody, contentTypeHeader); } } catch (ParseException ex) { //Shouldn't happen System.out.println( "Failed to create a content type header for the INVITE request " + ex); } //Transaction ClientTransaction inviteTransaction = null; try { inviteTransaction = messageListener.sipProvider.getNewClientTransaction(invite); } catch (TransactionUnavailableException ex) { System.out.println( "Failed to create inviteTransaction.\n" + "This is most probably a network connection error. "); ex.printStackTrace(); } System.out.println("send request:\n" + invite); try { inviteTransaction.sendRequest(); //Find the Audio call AudioCall call = callManager.findAudioCall("sip:" + calleeURI); call.setDialog(inviteTransaction.getDialog());
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -