Commits initial handling of session-accept.

cusax-fix
Emil Ivov 15 years ago
parent eed2ea2c49
commit af7ffca88e

@ -302,7 +302,6 @@ public String getJingleSID()
public void processSessionTerminate(JingleIQ jingleIQ)
{
String reasonStr = "Call ended by remote side.";
ReasonPacketExtension reasonExt = jingleIQ.getReason();
if(reasonStr != null)
@ -310,19 +309,54 @@ public void processSessionTerminate(JingleIQ jingleIQ)
Reason reason = reasonExt.getReason();
if(reason != null)
{
reasonStr += " Reason: " + reason.toString() + ".";
}
String text = reasonExt.getText();
if(text != null)
{
reasonStr += " " + text;
}
}
setState(CallPeerState.DISCONNECTED, reasonStr);
}
/**
* Processes the session initiation {@link JingleIQ} that we were created
* with, passing its content to the media handler and then sends either a
* "session-info/ringing" or a "session-terminate" response.
*
* @param sessionInitIQ The {@link JingleIQ} that created the session that
* we are handling here.
*/
public void processSessionAccept(JingleIQ sessionInitIQ)
{
this.sessionInitIQ = sessionInitIQ;
List<ContentPacketExtension> offer = sessionInitIQ.getContentList();
try
{
getMediaHandler().processAnswer(offer);
}
catch(Exception exc)
{
logger.info("Failed to process a session-accept", exc);
//send an error response;
JingleIQ errResp = JinglePacketFactory.createSessionTerminate(
sessionInitIQ.getTo(), sessionInitIQ.getFrom(),
sessionInitIQ.getSID(), Reason.INCOMPATIBLE_PARAMETERS,
exc.getMessage());
setState(CallPeerState.FAILED, "Error: " + exc.getMessage());
getProtocolProvider().getConnection().sendPacket(errResp);
return;
}
//tell everyone we are connecting so that the audio notifications would
//stop
setState(CallPeerState.CONNECTED);
getMediaHandler().start();
}
}

@ -358,5 +358,96 @@ private ContentPacketExtension createContentForOffer(
getRtpExtensionsRegistry());
}
/**
* Handles the specified <tt>answer</tt> by creating and initializing the
* corresponding <tt>MediaStream</tt>s.
*
* @param answer the SDP <tt>SessionDescription</tt>.
*
* @throws OperationFailedException if we fail to handle <tt>answer</tt> for
* reasons like failing to initialize media devices or streams.
* @throws IllegalArgumentException if there's a problem with the syntax or
* the semantics of <tt>answer</tt>. Method is synchronized in order to
* avoid closing mediaHandler when we are currently in process of
* initializing, configuring and starting streams and anybody interested
* in this operation can synchronize to the mediaHandler instance to wait
* processing to stop (method setState in CallPeer).
*/
public void processAnswer(List<ContentPacketExtension> answer)
throws OperationFailedException,
IllegalArgumentException
{
for ( ContentPacketExtension content : answer)
{
RtpDescriptionPacketExtension description
= JingleUtils.getRtpDescription(content);
MediaType mediaType
= MediaType.parseString( description.getMedia() );
//stream target
MediaStreamTarget target
= JingleUtils.extractDefaultTarget(content);
// no target port - try next media description
if(target.getDataAddress().getPort() == 0)
{
closeStream(mediaType);
continue;
}
List<MediaFormat> supportedFormats = JingleUtils.extractFormats(
description, getDynamicPayloadTypes());
MediaDevice dev = getDefaultDevice(mediaType);
if(dev == null)
{
closeStream(mediaType);
continue;
}
MediaDirection devDirection
= (dev == null) ? MediaDirection.INACTIVE : dev.getDirection();
// Take the preference of the user with respect to streaming
// mediaType into account.
devDirection
= devDirection.and(getDirectionUserPreference(mediaType));
if (supportedFormats.isEmpty())
{
//remote party must have messed up our SDP. throw an exception.
ProtocolProviderServiceJabberImpl.throwOperationFailedException(
"Remote party sent an invalid SDP answer.",
OperationFailedException.ILLEGAL_ARGUMENT, null, logger);
}
StreamConnector connector = getStreamConnector(mediaType);
//determine the direction that we need to announce.
MediaDirection remoteDirection
= JingleUtils.getDirection(content);
MediaDirection direction
= devDirection.getDirectionForAnswer(remoteDirection);
// update the RTP extensions that we will be exchanging.
List<RTPExtension> remoteRTPExtensions
= JingleUtils.extractRTPExtensions(
description, getRtpExtensionsRegistry());
List<RTPExtension> supportedExtensions
= getExtensionsForType(mediaType);
List<RTPExtension> rtpExtensions = intersectRTPExtensions(
remoteRTPExtensions, supportedExtensions);
// create the corresponding stream...
initStream(connector, dev, supportedFormats.get(0), target,
direction, rtpExtensions);
}
}
}

@ -491,7 +491,7 @@ else if(action == JingleAction.SESSION_TERMINATE)
}
else if(action == JingleAction.SESSION_ACCEPT)
{
callPeer.processSessionAccept(jingleIQ);
}
else if (action == JingleAction.SESSION_INFO)
{

@ -623,11 +623,6 @@ private void setCallInfoURL(URL callInfolURL)
this.callInfoURL = callInfolURL;
}
/**
* Returns the <tt>InetAddress</tt> that is most likely to be to be used
* as a next hop when contacting the specified <tt>destination</tt>. This is

Loading…
Cancel
Save