diff --git a/jingle/extension/build/merge/jstun.jar b/jingle/extension/build/merge/jstun.jar index df7e883fd..8ef0b923e 100644 Binary files a/jingle/extension/build/merge/jstun.jar and b/jingle/extension/build/merge/jstun.jar differ diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/ContentNegotiator.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/ContentNegotiator.java index 63be725da..1a2679432 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/ContentNegotiator.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/ContentNegotiator.java @@ -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()); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java index 7ff46a719..89aa35c43 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java @@ -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(); - } - } - } } \ No newline at end of file diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleNegotiator.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleNegotiator.java index ee8c98cb1..5b15c463f 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleNegotiator.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleNegotiator.java @@ -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 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. */ diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java index 5efae61e5..9289160eb 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java @@ -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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionRequest.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionRequest.java index d88217e99..a79d4ecf5 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionRequest.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionRequest.java @@ -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); + } } - } + } } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/media/MediaNegotiator.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/media/MediaNegotiator.java index 7bcbb50b2..b0dd60446 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/media/MediaNegotiator.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/media/MediaNegotiator.java @@ -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; } /** diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java index 25c207d43..a5d4b9a3a 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java @@ -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; - } /**