1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-16 08:34:50 +02:00

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. * Called from above when starting a new session.
*/ */
public void start() { protected void doStart() {
JingleContent result = new JingleContent(creator, name); JingleContent result = new JingleContent(creator, name);
// result.setDescription(mediaNeg.start()); // result.setDescription(mediaNeg.start());

View file

@ -598,29 +598,4 @@ public class JingleManager implements JingleSessionListener {
} }
return null; 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

@ -55,6 +55,8 @@ public abstract class JingleNegotiator {
private JingleNegotiatorState state; private JingleNegotiatorState state;
private boolean isStarted;
/** /**
* Default constructor. * Default constructor.
*/ */
@ -234,6 +236,21 @@ public abstract class JingleNegotiator {
*/ */
public abstract List<IQ> dispatchIncomingPacket(IQ iq, String id) throws XMPPException; 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. * 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. // Each content negotiator may pass back a list of JingleContent for addition to the response packet.
for (ContentNegotiator contentNegotiator : contentNegotiators) { 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)); 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. // Depending on the state we're in we'll get different processing actions.
// (See Design Patterns AKA GoF State behavioral pattern.) // (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) { public void sendPacket(IQ iq) {
if (iq instanceof Jingle) { 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); sendFormattedJingle((Jingle) iq);
@ -1238,9 +1221,13 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
// Give each of the content negotiators a chance to start // Give each of the content negotiators a chance to start
// and return a portion of the structure to make the Jingle packet. // 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();
// }
} }
/** /**
@ -1251,6 +1238,10 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
//updatePacketListener(); //updatePacketListener();
} }
protected void doStart() {
}
/** /**
* When we initiate a session we need to start a bunch of negotiators right after we receive the result * When we initiate a session we need to start a bunch of negotiators right after we receive the result
* packet for our session-initiate. This is where we start them. * packet for our session-initiate. This is where we start them.

View file

@ -33,6 +33,8 @@ import org.jivesoftware.smackx.packet.Jingle;
*/ */
public class JingleSessionRequest { public class JingleSessionRequest {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleSessionRequest.class);
private final Jingle jingle; // The Jingle packet private final Jingle jingle; // The Jingle packet
private final JingleManager manager; // The manager associated to this private final JingleManager manager; // The manager associated to this
@ -121,8 +123,18 @@ public class JingleSessionRequest {
* Rejects the session request. * Rejects the session request.
*/ */
public synchronized void reject() { public synchronized void reject() {
JingleSession session = null;
synchronized (manager) { 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. * Called from above when starting a new session.
* @return * @return
*/ */
public void start() { protected void doStart() {
//JingleDescription result = new JingleDescription.Audio();
// result.addAudioPayloadTypes(localAudioPts);
// return result;
} }
/** /**

View file

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