mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-10-31 17:25:58 +01:00
Jingle Refactoring
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7114 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
f5834d3ed5
commit
81ad05d49b
6 changed files with 125 additions and 30 deletions
|
@ -57,6 +57,7 @@ import org.jivesoftware.smack.XMPPException;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleMediaListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleTransportListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleSessionStateListener;
|
||||
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
|
||||
import org.jivesoftware.smackx.jingle.media.MediaNegotiator;
|
||||
import org.jivesoftware.smackx.jingle.media.PayloadType;
|
||||
|
@ -68,12 +69,13 @@ import org.jivesoftware.smackx.packet.JingleContentDescription;
|
|||
import org.jivesoftware.smackx.packet.JingleContentDescription.JinglePayloadType;
|
||||
import org.jivesoftware.smackx.packet.JingleError;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An incoming Jingle Session implementation.
|
||||
* This class has especific bahavior to accept and establish a received Jingle Session Request.
|
||||
*
|
||||
* <p/>
|
||||
* This class is not directly used by users. Instead, users should refer to the
|
||||
* JingleManager class, that will create the appropiate instance...
|
||||
*
|
||||
|
@ -90,6 +92,8 @@ public class IncomingJingleSession extends JingleSession {
|
|||
|
||||
private JingleSessionRequest initialSessionRequest;
|
||||
|
||||
private boolean accepted = false;
|
||||
|
||||
/**
|
||||
* Constructor for a Jingle incoming session
|
||||
*
|
||||
|
@ -115,6 +119,7 @@ public class IncomingJingleSession extends JingleSession {
|
|||
if (resolver.getType().equals(TransportResolver.Type.ice)) {
|
||||
setTransportNeg(new TransportNegotiator.Ice(this, resolver));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,11 +156,13 @@ public class IncomingJingleSession extends JingleSession {
|
|||
|
||||
updatePacketListener();
|
||||
respond(packet);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Session request with null Jingle packet.");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Starting session without null state.");
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +347,8 @@ public class IncomingJingleSession extends JingleSession {
|
|||
.getAcceptedLocalCandidate())) {
|
||||
setState(active);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new JingleException(JingleError.MALFORMED_STANZA);
|
||||
}
|
||||
}
|
||||
|
@ -374,6 +382,7 @@ public class IncomingJingleSession extends JingleSession {
|
|||
* "Active" state: we have an agreement about the session.
|
||||
*/
|
||||
public class Active extends JingleNegotiator.State {
|
||||
|
||||
public Active(JingleNegotiator neg) {
|
||||
super(neg);
|
||||
}
|
||||
|
|
|
@ -93,7 +93,8 @@ public abstract class JingleNegotiator {
|
|||
public Class getStateClass() {
|
||||
if (state != null) {
|
||||
return state.getClass();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return Object.class;
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +123,7 @@ public abstract class JingleNegotiator {
|
|||
|
||||
/**
|
||||
* Add expected ID
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void addExpectedId(String id) {
|
||||
|
@ -130,19 +132,22 @@ public abstract class JingleNegotiator {
|
|||
|
||||
/**
|
||||
* Check if the passed ID is the expected ID
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public boolean isExpectedId(String id) {
|
||||
if (id != null) {
|
||||
return id.equals(expectedAckId);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove and expected ID
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void removeExpectedId(String id) {
|
||||
|
|
|
@ -60,10 +60,7 @@ import org.jivesoftware.smack.filter.PacketFilter;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleMediaListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleTransportListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.*;
|
||||
import org.jivesoftware.smackx.jingle.media.*;
|
||||
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle.nat.TransportNegotiator;
|
||||
|
@ -74,10 +71,7 @@ import org.jivesoftware.smackx.packet.JingleContentInfo;
|
|||
import org.jivesoftware.smackx.packet.JingleError;
|
||||
import org.jivesoftware.smackx.packet.JingleTransport.JingleTransportCandidate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* An abstract Jingle session.
|
||||
|
@ -116,10 +110,10 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
|
||||
protected JingleMediaSession jingleMediaSession = null;
|
||||
|
||||
static int ccc = 0;
|
||||
|
||||
private boolean closed = false;
|
||||
|
||||
private List<JingleSessionStateListener> stateListeners = new ArrayList<JingleSessionStateListener>();
|
||||
|
||||
/**
|
||||
* Full featured JingleSession constructor
|
||||
*
|
||||
|
@ -278,6 +272,54 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a State Listener for the Session. It will be called twice every time the Session State changed. One before State change and other after.
|
||||
*
|
||||
* @param listener listener to be added
|
||||
*/
|
||||
public void addStateListener(JingleSessionStateListener listener) {
|
||||
stateListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a JingleStateListener
|
||||
*
|
||||
* @param listener listener to be removed
|
||||
*/
|
||||
public void removedStateListener(JingleSessionStateListener listener) {
|
||||
stateListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all JingleSessionStateListeners.
|
||||
*/
|
||||
public void removeAllStateListeners() {
|
||||
stateListeners.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overides JingleNegiociator Method to add listener capabilities
|
||||
* @param newState new State
|
||||
*/
|
||||
protected void setState(State newState) {
|
||||
boolean proceed = true;
|
||||
State old = getState();
|
||||
|
||||
for (JingleSessionStateListener listener : stateListeners)
|
||||
try {
|
||||
listener.beforeChange(old, newState);
|
||||
}
|
||||
catch (JingleException e) {
|
||||
proceed = false;
|
||||
}
|
||||
|
||||
if (proceed)
|
||||
super.setState(newState);
|
||||
|
||||
for (JingleSessionStateListener listener : stateListeners)
|
||||
listener.afterChanged(old, getState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the transport negotiator for this session.
|
||||
*
|
||||
|
@ -343,8 +385,6 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
public IQ dispatchIncomingPacket(IQ iq, String id) throws XMPPException {
|
||||
IQ jout = null;
|
||||
|
||||
if (iq != null) System.out.println("L: " + iq.toXML());
|
||||
|
||||
if (invalidState()) {
|
||||
throw new IllegalStateException(
|
||||
"Illegal state in dispatch packet in Session manager.");
|
||||
|
@ -423,9 +463,6 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
public synchronized IQ respond(IQ iq) throws XMPPException {
|
||||
IQ response = null;
|
||||
|
||||
if (iq != null)
|
||||
System.out.println("TT: " + iq.toXML());
|
||||
|
||||
if (isValid()) {
|
||||
String responseId = null;
|
||||
IQ sessionResponse = null;
|
||||
|
@ -875,8 +912,6 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
packetFilter = new PacketFilter() {
|
||||
public boolean accept(Packet packet) {
|
||||
|
||||
final int cc = ccc++;
|
||||
|
||||
if (packet instanceof IQ) {
|
||||
IQ iq = (IQ) packet;
|
||||
|
||||
|
@ -1100,7 +1135,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
destroyMediaNeg();
|
||||
destroyTransportNeg();
|
||||
removePacketListener();
|
||||
System.out.println("Negociation Closed: "+getConnection().getUser());
|
||||
System.out.println("Negociation Closed: " + getConnection().getUser());
|
||||
closed = true;
|
||||
super.close();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision: $
|
||||
* $Date: $11-07-2006
|
||||
*
|
||||
* Copyright 2003-2006 Jive Software.
|
||||
*
|
||||
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.jingle.listeners;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.JingleNegotiator;
|
||||
|
||||
/**
|
||||
* Used to Listen for Jingle Session State Changes
|
||||
*/
|
||||
public interface JingleSessionStateListener {
|
||||
|
||||
/**
|
||||
* Called before the State changing. If you want to cancel the State change, you MAY throw a JingleException.
|
||||
*
|
||||
* @param old old State
|
||||
* @param newOne new State
|
||||
* @throws JingleNegotiator.JingleException
|
||||
* Exception. If you want to cancel the State change, you MAY throw a JingleException.
|
||||
*/
|
||||
public void beforeChange(JingleNegotiator.State old, JingleNegotiator.State newOne) throws JingleNegotiator.JingleException;
|
||||
|
||||
/**
|
||||
* Called after State Changing.
|
||||
* @param old old State
|
||||
* @param newOne new State
|
||||
*/
|
||||
public void afterChanged(JingleNegotiator.State old, JingleNegotiator.State newOne);
|
||||
|
||||
}
|
|
@ -535,6 +535,7 @@ public class JingleManagerTest extends SmackTestCase {
|
|||
IncomingJingleSession session = request.accept(getTestPayloads1());
|
||||
session.setInitialSessionRequest(request);
|
||||
session.start();
|
||||
session.terminate();
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -575,7 +576,7 @@ public class JingleManagerTest extends SmackTestCase {
|
|||
|
||||
Thread.sleep(50000);
|
||||
|
||||
session0.terminate();
|
||||
//session0.terminate();
|
||||
|
||||
Thread.sleep(10000);
|
||||
|
||||
|
|
|
@ -48,8 +48,6 @@ public class JingleMediaTest extends SmackTestCase {
|
|||
|
||||
try {
|
||||
|
||||
//XMPPConnection.DEBUG_ENABLED = true;
|
||||
|
||||
XMPPConnection x0 = getConnection(0);
|
||||
XMPPConnection x1 = getConnection(1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue