diff --git a/src/net/java/sip/communicator/impl/protocol/sip/CallSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/CallSipImpl.java index bc90c6889..a2e6797c9 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/CallSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/CallSipImpl.java @@ -423,6 +423,49 @@ private void attachSdpOffer(Request invite, CallPeerSipImpl callPeer) } + /** + * Creates an SDP description that could be sent to peer and adds + * it to + * response. Provides a hook for this instance to take last + * configuration steps on a specific Response before it is sent to + * a specific CallPeer as part of the execution of. + * + * @param peer the CallPeer to receive a specific Response + * @param response the Response to be sent to the peer + * + * @throws OperationFailedException if we fail parsing call peer's media. + * @throws ParseException if we try to attach invalid SDP to response. + */ + private void attachSDPAnswer(Response response, CallPeerSipImpl peer) + throws OperationFailedException, ParseException + { + /* + * At the time of this writing, we're only getting called because a + * response to a call-hold invite is to be sent. + */ + + CallSession callSession = + ((CallSipImpl) peer.getCall()).getMediaCallSession(); + + String sdpAnswer = null; + try + { + sdpAnswer = callSession.processSdpOffer( + peer, ((CallPeerSipImpl) peer).getSdpDescription()); + } + catch (MediaException ex) + { + ProtocolProviderServiceSipImpl.throwOperationFailedException( + "Failed to create SDP answer to put-on/off-hold request.", + OperationFailedException.INTERNAL_ERROR, ex, logger); + } + + response.setContent( + sdpAnswer, + getProtocolProvider().getHeaderFactory() + .createContentTypeHeader("application", "sdp")); + } + /** * Creates a new call peer associated with containingTransaction * @@ -466,7 +509,6 @@ public void processReplacingInvite(SipProvider jainSipProvider, ServerTransaction serverTransaction, CallPeerSipImpl callPeerToReplace) { - Request request = serverTransaction.getRequest(); CallPeerSipImpl newCallPeer = createCallPeerFor(serverTransaction, jainSipProvider); try @@ -503,12 +545,81 @@ public void processReplacingInvite(SipProvider jainSipProvider, } } + + /** + * Updates the media flags for + * + * @param callPeer the CallPeer who was sent a specific + * Response + * @param response the Response that has just been sent to the + * peer + * @throws OperationFailedException if we fail parsing callPeer's media. + */ + private void setMediaFlagsForPeer(CallPeerSipImpl callPeer, Response response) + throws OperationFailedException + { + /* + * At the time of this writing, we're only getting called because a + * response to a call-hold invite is to be sent. + */ + + CallSession callSession = callPeer.getCall().getMediaCallSession(); + + int mediaFlags = 0; + try + { + mediaFlags = callSession .getSdpOfferMediaFlags( + callPeer.getSdpDescription()); + } + catch (MediaException ex) + { + ProtocolProviderServiceSipImpl.throwOperationFailedException( + "Failed to create SDP answer to put-on/off-hold request.", + OperationFailedException.INTERNAL_ERROR, ex, logger); + } + + /* + * Comply with the request of the SDP offer with respect to putting on + * hold. + */ + boolean on = ((mediaFlags & CallSession.ON_HOLD_REMOTELY) != 0); + + callSession.putOnHold(on, false); + + CallPeerState state = callPeer.getState(); + if (CallPeerState.ON_HOLD_LOCALLY.equals(state)) + { + if (on) + callPeer.setState(CallPeerState.ON_HOLD_MUTUALLY); + } + else if (CallPeerState.ON_HOLD_MUTUALLY.equals(state)) + { + if (!on) + callPeer.setState(CallPeerState.ON_HOLD_LOCALLY); + } + else if (CallPeerState.ON_HOLD_REMOTELY.equals(state)) + { + if (!on) + callPeer.setState(CallPeerState.CONNECTED); + } + else if (on) + { + callPeer.setState(CallPeerState.ON_HOLD_REMOTELY); + } + + /* + * Reflect the request of the SDP offer with respect to the modification + * of the availability of media. + */ + callSession.setReceiveStreaming(mediaFlags); + } + /** * Ends the call with the specified peer. Depending on the state * of the call the method would send a CANCEL, BYE, or BUSY_HERE message * and set the new state to DISCONNECTED. * - * @param peer the peer that we'd like to hang up on. + * @param callPeer the peer that we'd like to hang up on. * * @throws OperationFailedException if we fail to terminate the call. */ @@ -700,9 +811,9 @@ private void sayCancel(CallPeerSipImpl callPeer) * Sends an OK response to callPeer. Make sure that the call * peer contains an sdp description when you call this method. * - * @param peer the call peer that we need to send the ok to. + * @param callPeer the call peer that we need to send the ok to. * @throws OperationFailedException if we fail to create or send the - * response. + * response. */ public synchronized void answerCallPeer(CallPeerSipImpl callPeer) throws OperationFailedException @@ -834,13 +945,16 @@ public synchronized void answerCallPeer(CallPeerSipImpl callPeer) /** * Creates a new call and sends a RINGING response. * - * @param sourceProvider the provider containing sourceTransaction. + * @param jainSipProvider the provider containing + * sourceTransaction. * @param serverTransaction the transaction containing the received request. - * @param invite the Request that we've just received. + * + * @return CallPeerSipImpl the newly created call peer (the one that sent + * the INVITE). */ public CallPeerSipImpl processInvite(SipProvider jainSipProvider, - ServerTransaction serverTransaction) - { + ServerTransaction serverTransaction) +{ Request invite = serverTransaction.getRequest(); CallPeerSipImpl peer @@ -864,13 +978,6 @@ public CallPeerSipImpl processInvite(SipProvider jainSipProvider, serverTransaction.sendResponse(response); logger.debug("sent a ringing response: " + response); } - catch (ParseException ex) - { - logger.error("Error while trying to create a response", ex); - peer.setState(CallPeerState.FAILED, - "Internal Error: " + ex.getMessage()); - return peer; - } catch (Exception ex) { logger.error("Error while trying to send a request", ex); @@ -882,6 +989,14 @@ public CallPeerSipImpl processInvite(SipProvider jainSipProvider, return peer; } + /** + * Reinitializes the media session of the CallPeer that this + * INVITE request is destined to. + * + * @param jainSipProvider the {@link SipProvider} that received the request. + * @param serverTransaction a reference to the {@link ServerTransaction} + * that contains the reINVITE request. + */ public void processReInvite(SipProvider jainSipProvider, ServerTransaction serverTransaction) { diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java index 0cb0980f0..9ac816e5a 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java @@ -189,7 +189,9 @@ public Iterator getActiveCalls() * Resumes communication with a call peer previously put on hold. * * @param peer the call peer to put on hold. - * @throws OperationFailedException + * + * @throws OperationFailedException if we fail to construct or send the + * INVITE request putting the remote side on/off hold. */ public synchronized void putOffHold(CallPeer peer) throws OperationFailedException @@ -201,7 +203,9 @@ public synchronized void putOffHold(CallPeer peer) * Puts the specified CallPeer "on hold". * * @param peer the peer that we'd like to put on hold. - * @throws OperationFailedException + * + * @throws OperationFailedException if we fail to construct or send the + * INVITE request putting the remote side on/off hold. */ public synchronized void putOnHold(CallPeer peer) throws OperationFailedException @@ -215,7 +219,8 @@ public synchronized void putOnHold(CallPeer peer) * @param peer the CallPeer to be put on or off hold * @param on true to have the specified CallPeer * put on hold; false, otherwise - * @throws OperationFailedException + * @throws OperationFailedException if we fail to construct or send the + * INVITE request putting the remote side on/off hold. */ private void putOnHold(CallPeer peer, boolean on) throws OperationFailedException @@ -271,11 +276,12 @@ else if (on) * Sends an invite request with a specific SDP offer (description) within * the current Dialog with a specific call peer. * - * @param sipPeer the SIP-specific call peer to send the - * invite to within the current Dialog - * @param sdpOffer the description of the SDP offer to be made to the - * specified call peer with the sent invite - * @throws OperationFailedException + * @param sipPeer the SIP-specific call peer to send the to within the + * current Dialog @param sdpOffer the description of the SDP offer + * to be made to the specified call peer with the sent invite + * + * @throws OperationFailedException if sending the request fails for some + * reason. */ void sendInviteRequest(CallPeerSipImpl sipPeer, String sdpOffer) throws OperationFailedException @@ -1134,7 +1140,6 @@ public boolean processDialogTerminated( * * @param sourceProvider the provider containing sourceTransaction. * @param serverTransaction the transaction containing the received request. - * @param invite the Request that we've just received. */ private void processInvite(SipProvider sourceProvider, ServerTransaction serverTransaction) @@ -1187,246 +1192,6 @@ private void processInvite(SipProvider sourceProvider, } } - /** - * Creates a new call and sends a RINGING response. - * - * @param sourceProvider the provider containing sourceTransaction. - * @param serverTransaction the transaction containing the received request. - * @param invite the Request that we've just received. - */ - private void originalProcessInvite(SipProvider sourceProvider, - ServerTransaction serverTransaction, - Request invite) - { - Dialog dialog = serverTransaction.getDialog(); - CallPeerSipImpl callPeer = - activeCallsRepository.findCallPeer(dialog); - int statusCode = 0; - CallPeerSipImpl callPeerToReplace = null; - - if (callPeer == null) - { - ReplacesHeader replacesHeader = - (ReplacesHeader) invite.getHeader(ReplacesHeader.NAME); - - if (replacesHeader == null) - { - //this is not a transfered call so start ringing - statusCode = Response.RINGING; - } - else - { - //this is a transfered call - //.. ok or error if no peer found - } - - logger.trace("Creating call peer."); - callPeer = - createCallPeerFor(serverTransaction, sourceProvider); - logger.trace("call peer created = " + callPeer); - } - else - { - //this is a reINVITE - so we'll OK it without ringing - statusCode = Response.OK; - } - - // extract the SDP description. - // beware: SDP description may be in ACKs - bug report Laurent Michel - ContentLengthHeader cl = invite.getContentLength(); - if (cl != null && cl.getContentLength() > 0) - { - callPeer.setSdpDescription(new String(invite.getRawContent())); - } - - // INVITE w/ Replaces - //.. - - // Send statusCode - //... - Response response = null; - try - { - response = protocolProvider.getMessageFactory() - .createResponse(statusCode, invite); - - // set our display name - ((ToHeader) response.getHeader(ToHeader.NAME)).getAddress() - .setDisplayName(protocolProvider.getOurDisplayName()); - - //add the SDP - if (statusCode == Response.OK) - { - try - { - attachSDP(callPeer, response); - } - catch (OperationFailedException ex) - { - logger.error("Error while trying to send response " - + response, ex); - callPeer.setState(CallPeerState.FAILED, - "Internal Error: " + ex.getMessage()); - return; - } - } - } - catch (ParseException ex) - { - logger.error("Error while trying to send a response", ex); - callPeer.setState(CallPeerState.FAILED, - "Internal Error: " + ex.getMessage()); - return; - } - try - { - logger.trace("will send " + statusCode + " response: "); - serverTransaction.sendResponse(response); - logger.debug("sent a " + statusCode + " response: " - + response); - } - catch (Exception ex) - { - logger.error("Error while trying to send a request", ex); - callPeer.setState(CallPeerState.FAILED, - "Internal Error: " + ex.getMessage()); - return; - } - - if (statusCode == Response.OK) - { - try - { - setMediaFlagsForPeer(callPeer, response); - } - catch (OperationFailedException ex) - { - logger.error("Error after sending response " + response, ex); - } - } - } - - /** - * Provides a hook for this instance to take last configuration steps on a - * specific Response before it is sent to a specific - * CallPeer as part of the execution of - * {@link #processInvite(SipProvider, ServerTransaction, Request)}. - * - * @param peer the CallPeer to receive a specific - * Response - * @param response the Response to be sent to the - * peer - * @throws OperationFailedException - * @throws ParseException - */ - private void attachSDP(CallPeer peer, Response response) - throws OperationFailedException, ParseException - { - /* - * At the time of this writing, we're only getting called because a - * response to a call-hold invite is to be sent. - */ - - CallSession callSession = - ((CallSipImpl) peer.getCall()).getMediaCallSession(); - - String sdpAnswer = null; - try - { - sdpAnswer - = callSession.processSdpOffer( - peer, - ((CallPeerSipImpl) peer) - .getSdpDescription()); - } - catch (MediaException ex) - { - ProtocolProviderServiceSipImpl.throwOperationFailedException( - "Failed to create SDP answer to put-on/off-hold request.", - OperationFailedException.INTERNAL_ERROR, ex, logger); - } - - response.setContent( - sdpAnswer, - protocolProvider.getHeaderFactory() - .createContentTypeHeader("application", "sdp")); - } - - /** - * Provides a hook for this instance to take immediate steps after a - * specific Response has been sent to a specific - * CallPeer as part of the execution of - * {@link #processInvite(SipProvider, ServerTransaction, Request)}. - * - * @param peer the CallPeer who was sent a specific - * Response - * @param response the Response that has just been sent to the - * peer - * @throws OperationFailedException - * @throws ParseException - */ - private void setMediaFlagsForPeer(CallPeer peer, Response response) - throws OperationFailedException - { - /* - * At the time of this writing, we're only getting called because a - * response to a call-hold invite is to be sent. - */ - - CallSession callSession = - ((CallSipImpl) peer.getCall()).getMediaCallSession(); - CallPeerSipImpl sipPeer = - (CallPeerSipImpl) peer; - - int mediaFlags = 0; - try - { - mediaFlags = callSession .getSdpOfferMediaFlags( - sipPeer.getSdpDescription()); - } - catch (MediaException ex) - { - ProtocolProviderServiceSipImpl.throwOperationFailedException( - "Failed to create SDP answer to put-on/off-hold request.", - OperationFailedException.INTERNAL_ERROR, ex, logger); - } - - /* - * Comply with the request of the SDP offer with respect to putting on - * hold. - */ - boolean on = ((mediaFlags & CallSession.ON_HOLD_REMOTELY) != 0); - - callSession.putOnHold(on, false); - - CallPeerState state = sipPeer.getState(); - if (CallPeerState.ON_HOLD_LOCALLY.equals(state)) - { - if (on) - sipPeer.setState(CallPeerState.ON_HOLD_MUTUALLY); - } - else if (CallPeerState.ON_HOLD_MUTUALLY.equals(state)) - { - if (!on) - sipPeer.setState(CallPeerState.ON_HOLD_LOCALLY); - } - else if (CallPeerState.ON_HOLD_REMOTELY.equals(state)) - { - if (!on) - sipPeer.setState(CallPeerState.CONNECTED); - } - else if (on) - { - sipPeer.setState(CallPeerState.ON_HOLD_REMOTELY); - } - - /* - * Reflect the request of the SDP offer with respect to the modification - * of the availability of media. - */ - callSession.setReceiveStreaming(mediaFlags); - } - /** * Sets the state of the corresponding call peer to DISCONNECTED and * sends an OK response. @@ -1998,14 +1763,15 @@ private boolean referToCallStateChanged(Call referToCall, * * @param dialog the Dialog to send the NOTIFY request in * @param subscriptionState the Subscription-State header to be - * sent with the NOTIFY request - * @param reasonCode the reason for the specified - * subscriptionState if any; null otherwise + * sent with the NOTIFY request + * @param reasonCode the reason for the specified subscriptionState + * if any; null otherwise * @param content the content to be carried in the body of the sent NOTIFY - * request + * request * @param sipProvider the SipProvider to send the NOTIFY - * request through - * @throws OperationFailedException + * request through + * + * @throws OperationFailedException if sending the request fails. */ private void sendReferNotifyRequest(Dialog dialog, String subscriptionState, String reasonCode, Object content, @@ -2255,11 +2021,12 @@ public boolean setSasVerified( CallPeer peer, * Transfers (in the sense of call transfer) a specific * CallPeer to a specific callee address. * - * @param peer the CallPeer to be transfered to - * the specified callee address - * @param target the Address the callee to transfer - * peer to - * @throws OperationFailedException + * @param peer the CallPeer to be transfered to the specified + * callee address + * @param target the Address the callee to transfer peer + * to + * @throws OperationFailedException if creating or sending the transferring + * INVITE request fails. */ private void transfer(CallPeer peer, Address target) throws OperationFailedException @@ -2353,11 +2120,12 @@ public void transfer(CallPeer transferee, CallPeer transferTarget) * transfer (though no such requirement is imposed). *

* - * @param peer the CallPeer to be transfered to - * the specified callee address - * @param target the address in the form of CallPeer of - * the callee to transfer peer to - * @throws OperationFailedException + * @param peer the CallPeer to be transfered to the specified + * callee address + * @param target the address in the form of CallPeer of the callee + * to transfer peer to + * @throws OperationFailedException if creating or sending the transferring + * INVITE request fails. */ public void transfer(CallPeer peer, String target) throws OperationFailedException