mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 23:42:06 +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.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.jingle.listeners.JingleMediaListener;
|
import org.jivesoftware.smackx.jingle.listeners.JingleMediaListener;
|
||||||
import org.jivesoftware.smackx.jingle.listeners.JingleTransportListener;
|
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.JingleMediaManager;
|
||||||
import org.jivesoftware.smackx.jingle.media.MediaNegotiator;
|
import org.jivesoftware.smackx.jingle.media.MediaNegotiator;
|
||||||
import org.jivesoftware.smackx.jingle.media.PayloadType;
|
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.JingleContentDescription.JinglePayloadType;
|
||||||
import org.jivesoftware.smackx.packet.JingleError;
|
import org.jivesoftware.smackx.packet.JingleError;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An incoming Jingle Session implementation.
|
* An incoming Jingle Session implementation.
|
||||||
* This class has especific bahavior to accept and establish a received Jingle Session Request.
|
* 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
|
* This class is not directly used by users. Instead, users should refer to the
|
||||||
* JingleManager class, that will create the appropiate instance...
|
* JingleManager class, that will create the appropiate instance...
|
||||||
*
|
*
|
||||||
|
@ -90,6 +92,8 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
|
|
||||||
private JingleSessionRequest initialSessionRequest;
|
private JingleSessionRequest initialSessionRequest;
|
||||||
|
|
||||||
|
private boolean accepted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for a Jingle incoming session
|
* Constructor for a Jingle incoming session
|
||||||
*
|
*
|
||||||
|
@ -98,7 +102,7 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
* @param resolver The transport resolver
|
* @param resolver The transport resolver
|
||||||
*/
|
*/
|
||||||
protected IncomingJingleSession(XMPPConnection conn, String responder,
|
protected IncomingJingleSession(XMPPConnection conn, String responder,
|
||||||
List payloadTypes, TransportResolver resolver) {
|
List payloadTypes, TransportResolver resolver) {
|
||||||
|
|
||||||
super(conn, responder, conn.getUser());
|
super(conn, responder, conn.getUser());
|
||||||
|
|
||||||
|
@ -115,6 +119,7 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
if (resolver.getType().equals(TransportResolver.Type.ice)) {
|
if (resolver.getType().equals(TransportResolver.Type.ice)) {
|
||||||
setTransportNeg(new TransportNegotiator.Ice(this, resolver));
|
setTransportNeg(new TransportNegotiator.Ice(this, resolver));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,7 +131,7 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
* @param jingleMediaManager The Media Manager for this Session
|
* @param jingleMediaManager The Media Manager for this Session
|
||||||
*/
|
*/
|
||||||
protected IncomingJingleSession(XMPPConnection conn, String responder,
|
protected IncomingJingleSession(XMPPConnection conn, String responder,
|
||||||
List payloadTypes, TransportResolver resolver, JingleMediaManager jingleMediaManager) {
|
List payloadTypes, TransportResolver resolver, JingleMediaManager jingleMediaManager) {
|
||||||
this(conn, responder, payloadTypes, resolver);
|
this(conn, responder, payloadTypes, resolver);
|
||||||
this.jingleMediaManager = jingleMediaManager;
|
this.jingleMediaManager = jingleMediaManager;
|
||||||
}
|
}
|
||||||
|
@ -151,11 +156,13 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
|
|
||||||
updatePacketListener();
|
updatePacketListener();
|
||||||
respond(packet);
|
respond(packet);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Session request with null Jingle packet.");
|
"Session request with null Jingle packet.");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new IllegalStateException("Starting session without null state.");
|
throw new IllegalStateException("Starting session without null state.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,7 +256,7 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
|
|
||||||
jingleTransportListener = new JingleTransportListener() {
|
jingleTransportListener = new JingleTransportListener() {
|
||||||
public void transportEstablished(TransportCandidate local,
|
public void transportEstablished(TransportCandidate local,
|
||||||
TransportCandidate remote) {
|
TransportCandidate remote) {
|
||||||
checkFullyEstablished();
|
checkFullyEstablished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +347,8 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
.getAcceptedLocalCandidate())) {
|
.getAcceptedLocalCandidate())) {
|
||||||
setState(active);
|
setState(active);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new JingleException(JingleError.MALFORMED_STANZA);
|
throw new JingleException(JingleError.MALFORMED_STANZA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,6 +382,7 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
* "Active" state: we have an agreement about the session.
|
* "Active" state: we have an agreement about the session.
|
||||||
*/
|
*/
|
||||||
public class Active extends JingleNegotiator.State {
|
public class Active extends JingleNegotiator.State {
|
||||||
|
|
||||||
public Active(JingleNegotiator neg) {
|
public Active(JingleNegotiator neg) {
|
||||||
super(neg);
|
super(neg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,8 @@ public abstract class JingleNegotiator {
|
||||||
public Class getStateClass() {
|
public Class getStateClass() {
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
return state.getClass();
|
return state.getClass();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Object.class;
|
return Object.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,6 +123,7 @@ public abstract class JingleNegotiator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add expected ID
|
* Add expected ID
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
public void addExpectedId(String id) {
|
public void addExpectedId(String id) {
|
||||||
|
@ -130,19 +132,22 @@ public abstract class JingleNegotiator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the passed ID is the expected ID
|
* Check if the passed ID is the expected ID
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean isExpectedId(String id) {
|
public boolean isExpectedId(String id) {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
return id.equals(expectedAckId);
|
return id.equals(expectedAckId);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove and expected ID
|
* Remove and expected ID
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
public void removeExpectedId(String 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.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smackx.jingle.listeners.JingleListener;
|
import org.jivesoftware.smackx.jingle.listeners.*;
|
||||||
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.media.*;
|
import org.jivesoftware.smackx.jingle.media.*;
|
||||||
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle.nat.TransportNegotiator;
|
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.JingleError;
|
||||||
import org.jivesoftware.smackx.packet.JingleTransport.JingleTransportCandidate;
|
import org.jivesoftware.smackx.packet.JingleTransport.JingleTransportCandidate;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract Jingle session.
|
* An abstract Jingle session.
|
||||||
|
@ -116,10 +110,10 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
|
|
||||||
protected JingleMediaSession jingleMediaSession = null;
|
protected JingleMediaSession jingleMediaSession = null;
|
||||||
|
|
||||||
static int ccc = 0;
|
|
||||||
|
|
||||||
private boolean closed = false;
|
private boolean closed = false;
|
||||||
|
|
||||||
|
private List<JingleSessionStateListener> stateListeners = new ArrayList<JingleSessionStateListener>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full featured JingleSession constructor
|
* 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.
|
* 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 {
|
public IQ dispatchIncomingPacket(IQ iq, String id) throws XMPPException {
|
||||||
IQ jout = null;
|
IQ jout = null;
|
||||||
|
|
||||||
if (iq != null) System.out.println("L: " + iq.toXML());
|
|
||||||
|
|
||||||
if (invalidState()) {
|
if (invalidState()) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Illegal state in dispatch packet in Session manager.");
|
"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 {
|
public synchronized IQ respond(IQ iq) throws XMPPException {
|
||||||
IQ response = null;
|
IQ response = null;
|
||||||
|
|
||||||
if (iq != null)
|
|
||||||
System.out.println("TT: " + iq.toXML());
|
|
||||||
|
|
||||||
if (isValid()) {
|
if (isValid()) {
|
||||||
String responseId = null;
|
String responseId = null;
|
||||||
IQ sessionResponse = null;
|
IQ sessionResponse = null;
|
||||||
|
@ -875,8 +912,6 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
packetFilter = new PacketFilter() {
|
packetFilter = new PacketFilter() {
|
||||||
public boolean accept(Packet packet) {
|
public boolean accept(Packet packet) {
|
||||||
|
|
||||||
final int cc = ccc++;
|
|
||||||
|
|
||||||
if (packet instanceof IQ) {
|
if (packet instanceof IQ) {
|
||||||
IQ iq = (IQ) packet;
|
IQ iq = (IQ) packet;
|
||||||
|
|
||||||
|
@ -1100,7 +1135,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
destroyMediaNeg();
|
destroyMediaNeg();
|
||||||
destroyTransportNeg();
|
destroyTransportNeg();
|
||||||
removePacketListener();
|
removePacketListener();
|
||||||
System.out.println("Negociation Closed: "+getConnection().getUser());
|
System.out.println("Negociation Closed: " + getConnection().getUser());
|
||||||
closed = true;
|
closed = true;
|
||||||
super.close();
|
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());
|
IncomingJingleSession session = request.accept(getTestPayloads1());
|
||||||
session.setInitialSessionRequest(request);
|
session.setInitialSessionRequest(request);
|
||||||
session.start();
|
session.start();
|
||||||
|
session.terminate();
|
||||||
}
|
}
|
||||||
catch (XMPPException e) {
|
catch (XMPPException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -575,7 +576,7 @@ public class JingleManagerTest extends SmackTestCase {
|
||||||
|
|
||||||
Thread.sleep(50000);
|
Thread.sleep(50000);
|
||||||
|
|
||||||
session0.terminate();
|
//session0.terminate();
|
||||||
|
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,6 @@ public class JingleMediaTest extends SmackTestCase {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//XMPPConnection.DEBUG_ENABLED = true;
|
|
||||||
|
|
||||||
XMPPConnection x0 = getConnection(0);
|
XMPPConnection x0 = getConnection(0);
|
||||||
XMPPConnection x1 = getConnection(1);
|
XMPPConnection x1 = getConnection(1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue