Smack-261

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@10934 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Jeff Williams 2008-12-06 02:15:42 +00:00 committed by jeff.williams
parent 6b375b2e9f
commit bc9f0179fa
8 changed files with 57 additions and 69 deletions

View File

@ -117,7 +117,7 @@ public class ContentNegotiator extends JingleNegotiator {
/**
* Called from above when starting a new session.
*/
public void start() {
protected void doStart() {
JingleContent result = new JingleContent(creator, name);
// result.setDescription(mediaNeg.start());

View File

@ -598,29 +598,4 @@ public class JingleManager implements JingleSessionListener {
}
return null;
}
/**
* Reject the session. If we don't want to accept the new session then we have to
* result/ack the session-initiate and send a session-terminate.
*
* @param request the request to be rejected.
*/
protected void rejectIncomingJingleSession(JingleSessionRequest request) {
JingleSession session = getSession(request.getSessionID());
if (session != null) {
// First send the result/Ack
IQ result = session.createAck(request.getJingle());
connection.sendPacket(result);
// Now send the session-terminate.
try {
session.terminate("Declined");
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

View File

@ -54,7 +54,9 @@ public abstract class JingleNegotiator {
private String expectedAckId;
private JingleNegotiatorState state;
private boolean isStarted;
/**
* Default constructor.
*/
@ -234,6 +236,21 @@ public abstract class JingleNegotiator {
*/
public abstract List<IQ> dispatchIncomingPacket(IQ iq, String id) throws XMPPException;
public void start() {
isStarted = true;
doStart();
}
public boolean isStarted() {
return isStarted;
}
/**
* Each of the negotiators has their individual behavior when they start.
*/
protected abstract void doStart();
/**
* Close the negotiation.
*/

View File

@ -333,6 +333,13 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
// Each content negotiator may pass back a list of JingleContent for addition to the response packet.
for (ContentNegotiator contentNegotiator : contentNegotiators) {
// If at this point the content negotiator isn't started, it's because we sent a session-init jingle
// packet from startOutgoing() and we're waiting for the other side to let us know they're ready
// to take jingle packets. (This packet might be a session-terminate, but that will get handled
// later.
if (!contentNegotiator.isStarted()) {
contentNegotiator.start();
}
responses.addAll(contentNegotiator.dispatchIncomingPacket(iq, responseId));
}
@ -400,7 +407,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
// Depending on the state we're in we'll get different processing actions.
// (See Design Patterns AKA GoF State behavioral pattern.)
getSessionState().processJingle(this, jin, action);
response = getSessionState().processJingle(this, jin, action);
}
}
@ -429,30 +436,6 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
public void sendPacket(IQ iq) {
if (iq instanceof Jingle) {
// Jingle jingle = (Jingle) iq;
//
// JingleActionEnum action = jingle.getAction();
//
// switch (getSessionState()) {
// case UNKNOWN:
// sendUnknownStateAction(jingle, action);
// break;
//
// case PENDING:
// sendPendingStateAction(jingle, action);
// break;
//
// case ACTIVE:
// sendActiveStateAction(jingle, action);
// break;
//
// case ENDED:
// sendEndedStateAction(jingle, action);
// break;
//
// default:
// break;
// }
sendFormattedJingle((Jingle) iq);
@ -1238,9 +1221,13 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
// Give each of the content negotiators a chance to start
// and return a portion of the structure to make the Jingle packet.
for (ContentNegotiator contentNegotiator : contentNegotiators) {
contentNegotiator.start();
}
// Don't do this anymore. The problem is that the other side might not be ready.
// Later when we receive our first jingle packet from the other side we'll fire-up the negotiators
// before processing it. (See receivePacketAndRespond() above.
// for (ContentNegotiator contentNegotiator : contentNegotiators) {
// contentNegotiator.start();
// }
}
/**
@ -1250,6 +1237,10 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
//updatePacketListener();
}
protected void doStart() {
}
/**
* When we initiate a session we need to start a bunch of negotiators right after we receive the result

View File

@ -33,7 +33,9 @@ import org.jivesoftware.smackx.packet.Jingle;
*/
public class JingleSessionRequest {
private final Jingle jingle; // The Jingle packet
private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleSessionRequest.class);
private final Jingle jingle; // The Jingle packet
private final JingleManager manager; // The manager associated to this
@ -121,8 +123,18 @@ public class JingleSessionRequest {
* Rejects the session request.
*/
public synchronized void reject() {
JingleSession session = null;
synchronized (manager) {
manager.rejectIncomingJingleSession(this);
try {
session = manager.createIncomingJingleSession(this);
// Acknowledge the IQ reception
session.setSid(this.getSessionID());
//session.sendAck(this.getJingle());
session.updatePacketListener();
session.terminate("Declined");
} catch (XMPPException e) {
LOGGER.error("", e);
}
}
}
}
}

View File

@ -507,11 +507,8 @@ public class MediaNegotiator extends JingleNegotiator {
* Called from above when starting a new session.
* @return
*/
public void start() {
//JingleDescription result = new JingleDescription.Audio();
// result.addAudioPayloadTypes(localAudioPts);
protected void doStart() {
// return result;
}
/**

View File

@ -142,8 +142,8 @@ public abstract class TransportNegotiator extends JingleNegotiator {
return;
}
}
//LOGGER.debug("BEST: " + bestLocalCandidate.getIp());
throw new XMPPException("Local transport candidate has not be offered.");
LOGGER.debug("BEST: ip=" + bestLocalCandidate.getIp() + " port=" + bestLocalCandidate.getPort() + " has not been offered.");
//throw new XMPPException("Local transport candidate has not be offered.");
}
/**
@ -158,9 +158,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
/**
* Called from above to start the negotiator during a session-initiate.
*/
public void start() {
//JingleTransport result = new JingleTransport(getJingleTransport());
protected void doStart() {
try {
sendTransportCandidatesOffer();
@ -170,8 +168,6 @@ public abstract class TransportNegotiator extends JingleNegotiator {
e.printStackTrace();
}
//return result;
}
/**