?? messengermanager.java
字號:
} catch (SipException ex) { System.out.println( "An error occurred while sending invite request " + ex); } } /** * Send a MESSAGE to notify the proxy that a mail must be send to the callee */ public void sendMessage(String emailBody, String calleeURI) { //Store the callee in the call status calleeURI = calleeURI.trim(); //call.setCallee(calleeURI); //Listening Point ListeningPoint listeningPoint = messageListener.sipProvider.getListeningPoint(); SipURI requestURI = null; try { requestURI = MessageListener.addressFactory.createSipURI( null, messageListener.getConfiguration().outboundProxy); requestURI.setPort(messageListener.getConfiguration().proxyPort); requestURI.setTransportParam( messageListener.getConfiguration().signalingTransport); } catch (ParseException ex) { ex.printStackTrace(); } catch (NullPointerException ex) { ex.printStackTrace(); return; } //Call ID CallIdHeader callIdHeader = messageListener.sipProvider.getNewCallId(); //CSeq CSeqHeader cSeqHeader = null; try { cSeqHeader = MessageListener.headerFactory.createCSeqHeader( 1, Request.MESSAGE); } catch (ParseException ex) { //Shouldn't happen ex.printStackTrace(); } catch (InvalidArgumentException ex) { //Shouldn't happen System.out.println( "An unexpected error occurred while" + "constructing the CSeqHeader " + ex); } FromHeader fromHeader = null; //From try { fromHeader = MessageListener.headerFactory.createFromHeader( MessageListener.addressFactory.createAddress(userSipURI), generateTag()); } catch (ParseException ex) { ex.printStackTrace(); } //To Header SipURI ToURI = 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()); ToURI = MessageListener.addressFactory.createSipURI(user, host); ToURI.setTransportParam( messageListener.getConfiguration().signalingTransport); } catch (ParseException ex) { System.out.println(calleeURI + " is not a legal SIP uri! " + ex); } Address toAddress = MessageListener.addressFactory.createAddress(ToURI); ToHeader toHeader = null; try { toHeader = MessageListener.headerFactory.createToHeader(toAddress, null); } catch (ParseException ex) { //Shouldn't happen System.out.println( "Null is not an allowed tag for the to header! " + ex); } //ViaHeader ArrayList viaHeaders = null; viaHeaders = new ArrayList(); try { ViaHeader viaHeader = MessageListener.headerFactory.createViaHeader( messageListener.getConfiguration().contactIPAddress, listeningPoint.getPort(), listeningPoint.getTransport(), null); viaHeaders.add(viaHeader); } catch (ParseException ex) { //Shouldn't happen ex.printStackTrace(); } catch (InvalidArgumentException ex) { //Should never happen System.out.println("The application is corrupt"); } //Max Forward Header MaxForwardsHeader maxForwardsHeader = null; try { maxForwardsHeader = MessageListener.headerFactory.createMaxForwardsHeader(70); } catch (InvalidArgumentException ex) { //Should never happen System.out.println("The application is corrupt"); } Request message = null; try { message = MessageListener.messageFactory.createRequest( requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwardsHeader); } catch (ParseException ex) { System.out.println("Failed to create message Request! "); ex.printStackTrace(); } //Contact Header try { SipURI contactURI = MessageListener.addressFactory.createSipURI( userSipURI.getUser(), messageListener.getConfiguration().contactIPAddress); contactURI.setTransportParam( messageListener.getConfiguration().signalingTransport); ContactHeader contactHeader = MessageListener.headerFactory.createContactHeader( MessageListener.addressFactory.createAddress(contactURI)); contactURI.setPort(listeningPoint.getPort()); message.addHeader(contactHeader); } catch (ParseException ex) { System.out.println("Could not create the message request! " + ex); } //Content ContentTypeHeader contentTypeHeader = null; try { contentTypeHeader = MessageListener.headerFactory.createContentTypeHeader( "text", "plain;charset=UTF-8"); } catch (ParseException ex) { //Shouldn't happen System.out.println( "Failed to create a content type header for the MESSAGE request " + ex); } try { message.setContent(emailBody, contentTypeHeader); } catch (ParseException ex) { System.out.println( "Failed to parse sdp data while creating message request! " + ex); } //Transaction //Send the message with the sip Provider //So that he doesn't retransmit the message even if he doesn't receive //an OK (the drawback is that we don't know if the other end ever //received the message) //TODO : send the message in an invite transaction //to know more about delivery //ClientTransaction inviteTransaction=null; try { //inviteTransaction = messageListener.sipProvider.sendRequest(message); } catch (SipException ex) { System.out.println( "An error occurred while sending message request " + ex); ex.printStackTrace(); } System.out.println("request sent :\n" + message); /*try { inviteTransaction.sendRequest(); call.setDialog(inviteTransaction.getDialog()); } catch (SipException ex) { System.out.println( "An error occurred while sending invite request "+ ex); } */ } /** * * @param contactAddress * @param voiceMessage */ public void sendVoiceMessage(String contactAddress, byte[] voiceMessage) { Request messageRequest = null; String contact = contactAddress.trim(); //Try to find if we have an existing transaction for this one AudioCall call = callManager.findAudioCall(contact); javax.sip.Dialog dialog = null; if (call != null) { dialog = call.getDialog(); if (dialog == null || dialog.getState() == null || dialog.getState() == javax.sip.DialogState.COMPLETED || dialog.getState() == javax.sip.DialogState.TERMINATED) { System.out.println("Cannot send message on terminated or un-established dialog!"); // stop the audio stuff messageListener.messageProcessor.stopVoiceMessagingSchedule(); callManager.removeAudioCall(call); return; } try { messageRequest = dialog.createRequest(Request.MESSAGE); System.out.println( "SEND VOICE MESSAGE: " + messageRequest.toString()); } catch (SipException se) { se.printStackTrace(); return; } } else { return; } System.out.println("voice messaging session found!!"); //Content ContentTypeHeader contentTypeHeader = null; try { contentTypeHeader = MessageListener.headerFactory.createContentTypeHeader( "audio", "x-gsm"); } catch (ParseException ex) { //Shouldn't happen System.out.println( "Failed to create a content type header for the MESSAGE request " + ex); } try { messageRequest.setContent(voiceMessage, contentTypeHeader); } catch (ParseException ex) { System.out.println( "Failed to parse sdp data while creating message request! " + ex); } try { ListeningPoint listeningPoint = messageListener.sipProvider.getListeningPoint(); SipURI contactURI = MessageListener.addressFactory.createSipURI( userSipURI.getUser(), messageListener.getConfiguration().contactIPAddress); contactURI.setTransportParam( messageListener.getConfiguration().signalingTransport); ContactHeader contactHeader = MessageListener.headerFactory.createContactHeader( MessageListener.addressFactory.createAddress( contactURI)); contactURI.setPort(listeningPoint.getPort()); messageRequest.addHeader(contactHeader); SipURI routeURI = MessageListener.addressFactory.createSipURI( null, messageListener.getConfiguration().outboundProxy); } catch (ParseException ex) { System.out.println( "Could not create the message request! " + ex); } //Transaction ClientTransaction messageTransaction = null; try { messageTransaction = messageListener.sipProvider.getNewClientTransaction( messageRequest); dialog.sendRequest(messageTransaction); } catch (Exception ex) { System.out.println( "Failed to create Message Transaction.\n" + "This is most probably a network connection error. "); ex.printStackTrace(); return; } } /** * Send a MESSAGE to the contact we want to chat with * @param contactAddress - the contact to send the message to * @parma message - message to be sent */ public void sendInstantMessage(String contactAddress, String message) { Request messageRequest = null; //Try to find if we have an existing transaction for this one SipURI callee = null; try { callee = (SipURI) MessageListener.addressFactory.createURI(contactAddress); } catch (ParseException ex) { ex.printStackTrace(); return; } String contact = callee.getUser()+"@"+callee.getHost(); IMCall call = callManager.findIMCall(contact); javax.sip.Dialog dialog = null; // If we have a call record for this IM session then use the dialog. if (call != null) { dialog = call.getDialog(); System.out.println("im session found!!"); try { messageRequest = dialog.createRequest(Request.MESSAGE); System.out.println( "SEND VOICE MESSAGE: " + messageRequest.toString()); } catch (SipException se) { // The dialog must be dead so get rid of it. // proceed on bravely and re-establish the dialog. callManager.removeIMCall(contact); System.out.println("dialog is dead!"); // Signal that the dialog is dead. dialog = null; } } if (messageRequest == null) { System.out.println("could not find IM session for " + contact); try{ messageRequest = createRequest(Request.MESSAGE, callee, userSipURI); ((FromHeader)messageRequest.getHeader(FromHeader.NAME)).setTag(generateTag()); } catch (ParseException pe) { // should not happen. } } //Content ContentTypeHeader contentTypeHeader = null; try { contentTypeHeader = MessageListener.headerFactory.createContentTypeHeader(
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -