1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-15 20:12:04 +01:00

Significant improvement to Jingle logging messages, and a new SmackLogger that allows for use of java.commons.logging. Improvements to Jingle processing to keep up with recent changes in the XEPs as we approach approval of the standard. (There will be more changes as the standard changes.) Fixes to the way STUN gets used, and a new JSTUN library (including performance and reliability changes we added to it).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@10852 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Jeff Williams 2008-10-30 21:20:29 +00:00 committed by jeff.williams
parent 995f319f1e
commit 84fcf53512
40 changed files with 755 additions and 337 deletions

View file

@ -199,7 +199,7 @@
<manifest> <manifest>
<attribute name="Class-Path" value="smack.jar, smackx.jar" /> <attribute name="Class-Path" value="smack.jar, smackx.jar" />
</manifest> </manifest>
<zipfileset src="${jingle.extension.merge.lib.dir}/jstun.jar"/> <zipfileset src="${jingle.extension.merge.lib.dir}/jstun-0.7.2.jar"/>
</jar> </jar>
<delete file="${compile.dir}/META-INF/smack-config.xml" /> <delete file="${compile.dir}/META-INF/smack-config.xml" />
<delete file="${compile.dir}/META-INF/smack.providers" /> <delete file="${compile.dir}/META-INF/smack.providers" />

View file

@ -85,7 +85,7 @@
<path id="jingleextension.module.classpath"> <path id="jingleextension.module.classpath">
<path refid="${module.jdk.classpath.jingleextension}"/> <path refid="${module.jdk.classpath.jingleextension}"/>
<pathelement location="${module.jingleextension.basedir}/../merge/jstun-0.6.1.jar"/> <pathelement location="${module.jingleextension.basedir}/../merge/jstun-0.7.2.jar"/>
<pathelement location="${module.jingleextension.basedir}/../lib/smackx.jar"/> <pathelement location="${module.jingleextension.basedir}/../lib/smackx.jar"/>
<pathelement location="${module.jingleextension.basedir}/../lib/smack.jar"/> <pathelement location="${module.jingleextension.basedir}/../lib/smack.jar"/>
<pathelement location="${module.jingleextension.basedir}/../lib/smackx-debug.jar"/> <pathelement location="${module.jingleextension.basedir}/../lib/smackx-debug.jar"/>

Binary file not shown.

View file

@ -20,7 +20,15 @@
package org.jivesoftware.smackx.jingle; package org.jivesoftware.smackx.jingle;
import org.jivesoftware.smack.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter; 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;
@ -34,16 +42,13 @@ import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
import org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener; import org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener;
import org.jivesoftware.smackx.jingle.media.JingleMediaManager; import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.media.PayloadType; import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.nat.BasicTransportManager;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate; import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
import org.jivesoftware.smackx.jingle.nat.TransportResolver; import org.jivesoftware.smackx.jingle.nat.TransportResolver;
import org.jivesoftware.smackx.packet.DiscoverInfo; import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.Jingle; import org.jivesoftware.smackx.packet.Jingle;
import org.jivesoftware.smackx.provider.JingleProvider; import org.jivesoftware.smackx.provider.JingleProvider;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/** /**
* Jingle is a session establishment protocol defined in (XEP-0166). * Jingle is a session establishment protocol defined in (XEP-0166).
* It defines a framework for negotiating and managing out-of-band ( data that is send and receive through other connection than XMPP connection) data sessions over XMPP. * It defines a framework for negotiating and managing out-of-band ( data that is send and receive through other connection than XMPP connection) data sessions over XMPP.
@ -179,6 +184,8 @@ import java.util.List;
*/ */
public class JingleManager implements JingleSessionListener { public class JingleManager implements JingleSessionListener {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleManager.class);
// non-static // non-static
final List<JingleSession> jingleSessions = new ArrayList<JingleSession>(); final List<JingleSession> jingleSessions = new ArrayList<JingleSession>();
@ -195,20 +202,6 @@ public class JingleManager implements JingleSessionListener {
// The Media Managers // The Media Managers
private List<JingleMediaManager> jingleMediaManagers; private List<JingleMediaManager> jingleMediaManagers;
static {
ProviderManager providerManager = ProviderManager.getInstance();
providerManager.addIQProvider("jingle", "http://www.xmpp.org/extensions/xep-0166.html#ns", new JingleProvider());
// Enable the Jingle support on every established connection
// The ServiceDiscoveryManager class should have been already
// initialized
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
JingleManager.setServiceEnabled(connection, true);
}
});
}
/** /**
* Default constructor with a defined XMPPConnection, Transport Resolver and a Media Manager * Default constructor with a defined XMPPConnection, Transport Resolver and a Media Manager
* If a fully implemented JingleMediaSession is entered, JingleManager manage Jingle signalling and jmf * If a fully implemented JingleMediaSession is entered, JingleManager manage Jingle signalling and jmf
@ -252,32 +245,28 @@ public class JingleManager implements JingleSessionListener {
} }
/** /**
* Default constructor with a defined XMPPConnection. * Setup the jingle system to let the remote clients know we support Jingle.
* A default JingleTransportmanager based on BasicResolver will be used in this JingleManager transport. * (This used to be a static part of construction. The problem is a remote client might
* * attempt a Jingle connection to us after we've created an XMPPConnection, but before we've
* @param connection XMPP Connection to be used * setup an instance of a JingleManager. We will appear to not support Jingle. With the new
* method you just call it once and all new connections will report Jingle support.)
*/ */
// public JingleManager(XMPPConnection connection) { public static void setJingleServiceEnabled() {
// this(connection, new JingleTransportManager() { ProviderManager providerManager = ProviderManager.getInstance();
// protected TransportResolver createResolver(JingleSession session) { providerManager.addIQProvider("jingle", "urn:xmpp:tmp:jingle", new JingleProvider());
// return new BasicResolver();
// } // Enable the Jingle support on every established connection
// }); // The ServiceDiscoveryManager class should have been already
// } // initialized
/** XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
* Default constructor with a defined XMPPConnection and a defined Resolver. public void connectionCreated(XMPPConnection connection) {
* A default JingleTransportmanager based on BasicResolver will be used in this JingleManager transport. JingleManager.setServiceEnabled(connection, true);
* }
* @param connection XMPP Connection to be used });
*/ }
// public JingleManager(XMPPConnection connection, final TransportResolver resolver) {
// this(connection, new JingleTransportManager() {
// protected TransportResolver createResolver(JingleSession session) {
// return resolver;
// }
// });
// }
/** /**
* Enables or disables the Jingle support on a given connection. * Enables or disables the Jingle support on a given connection.
* <p/> * <p/>
@ -429,7 +418,7 @@ public class JingleManager implements JingleSessionListener {
jingleSession.removeListener(this); jingleSession.removeListener(this);
jingleSessions.remove(jingleSession); jingleSessions.remove(jingleSession);
jingleSession.close(); jingleSession.close();
System.err.println("Declined:" + reason); LOGGER.error("Declined:" + reason);
} }
public void sessionRedirected(String redirection, JingleSession jingleSession) { public void sessionRedirected(String redirection, JingleSession jingleSession) {

View file

@ -19,14 +19,14 @@
*/ */
package org.jivesoftware.smackx.jingle; package org.jivesoftware.smackx.jingle;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.listeners.JingleListener; import org.jivesoftware.smackx.jingle.listeners.JingleListener;
import java.util.ArrayList;
import java.util.List;
/** /**
* Basic Jingle negotiator. * Basic Jingle negotiator.
* <p/> * <p/>
@ -43,6 +43,8 @@ import java.util.List;
*/ */
public abstract class JingleNegotiator { public abstract class JingleNegotiator {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleNegotiator.class);
//private XMPPConnection connection; // The connection associated //private XMPPConnection connection; // The connection associated
protected JingleSession session; protected JingleSession session;
@ -78,7 +80,7 @@ public abstract class JingleNegotiator {
JingleNegotiatorState stateWas = state; JingleNegotiatorState stateWas = state;
System.out.println("Negotiator state change: " + stateWas + "->" + stateIs + "(" + this.getClass().getSimpleName() + ")"); LOGGER.debug("Negotiator state change: " + stateWas + "->" + stateIs + "(" + this.getClass().getSimpleName() + ")");
switch (stateIs) { switch (stateIs) {
case PENDING: case PENDING:

View file

@ -52,6 +52,12 @@
package org.jivesoftware.smackx.jingle; package org.jivesoftware.smackx.jingle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -65,7 +71,11 @@ import org.jivesoftware.smackx.jingle.listeners.JingleListener;
import org.jivesoftware.smackx.jingle.listeners.JingleMediaListener; import org.jivesoftware.smackx.jingle.listeners.JingleMediaListener;
import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener; import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
import org.jivesoftware.smackx.jingle.listeners.JingleTransportListener; import org.jivesoftware.smackx.jingle.listeners.JingleTransportListener;
import org.jivesoftware.smackx.jingle.media.*; import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.MediaNegotiator;
import org.jivesoftware.smackx.jingle.media.MediaReceivedListener;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.nat.JingleTransportManager; import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
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;
@ -73,8 +83,6 @@ import org.jivesoftware.smackx.jingle.nat.TransportResolver;
import org.jivesoftware.smackx.packet.Jingle; import org.jivesoftware.smackx.packet.Jingle;
import org.jivesoftware.smackx.packet.JingleError; import org.jivesoftware.smackx.packet.JingleError;
import java.util.*;
/** /**
* An abstract Jingle session. <p/> This class contains some basic properties of * An abstract Jingle session. <p/> This class contains some basic properties of
* every Jingle session. However, the concrete implementation can be found in * every Jingle session. However, the concrete implementation can be found in
@ -85,6 +93,8 @@ import java.util.*;
*/ */
public class JingleSession extends JingleNegotiator implements MediaReceivedListener { public class JingleSession extends JingleNegotiator implements MediaReceivedListener {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleSession.class);
// static // static
private static final HashMap sessions = new HashMap(); private static final HashMap sessions = new HashMap();
@ -98,6 +108,8 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
private String sid; // A unique id that identifies this session private String sid; // A unique id that identifies this session
ConnectionListener connectionListener;
PacketListener packetListener; PacketListener packetListener;
PacketFilter packetFilter; PacketFilter packetFilter;
@ -264,7 +276,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
public void setSessionState(JingleSessionState stateIs) { public void setSessionState(JingleSessionState stateIs) {
System.out.println("Session state change: " + sessionState + "->" + stateIs); LOGGER.debug("Session state change: " + sessionState + "->" + stateIs);
stateIs.enter(); stateIs.enter();
sessionState = stateIs; sessionState = stateIs;
} }
@ -307,7 +319,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
String responseId = null; String responseId = null;
System.out.println("Packet: " + iq.toXML()); LOGGER.debug("Packet: " + iq.toXML());
try { try {
@ -505,6 +517,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
} }
// The the packet. // The the packet.
if ((getConnection() != null) && (getConnection().isConnected()))
getConnection().sendPacket(jout); getConnection().sendPacket(jout);
} }
return jout; return jout;
@ -689,7 +702,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
*/ */
private void installConnectionListeners(final XMPPConnection connection) { private void installConnectionListeners(final XMPPConnection connection) {
if (connection != null) { if (connection != null) {
connection.addConnectionListener(new ConnectionListener() { connectionListener = new ConnectionListener() {
public void connectionClosed() { public void connectionClosed() {
unregisterInstanceFor(connection); unregisterInstanceFor(connection);
} }
@ -706,7 +719,16 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
public void reconnectionFailed(Exception exception) { public void reconnectionFailed(Exception exception) {
} }
}); };
connection.addConnectionListener(connectionListener);
}
}
private void removeConnectionListener() {
if (connectionListener != null) {
getConnection().removeConnectionListener(connectionListener);
LOGGER.debug("JINGLE SESSION: REMOVE CONNECTION LISTENER");
} }
} }
@ -717,7 +739,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
if (packetListener != null) { if (packetListener != null) {
getConnection().removePacketListener(packetListener); getConnection().removePacketListener(packetListener);
System.out.println("REMOVE PACKET LISTENER"); LOGGER.debug("JINGLE SESSION: REMOVE PACKET LISTENER");
} }
} }
@ -728,7 +750,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
protected void updatePacketListener() { protected void updatePacketListener() {
removePacketListener(); removePacketListener();
System.out.println("UpdatePacketListener"); LOGGER.debug("UpdatePacketListener");
packetListener = new PacketListener() { packetListener = new PacketListener() {
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
@ -763,21 +785,21 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
String sid = jin.getSid(); String sid = jin.getSid();
if (sid == null || !sid.equals(getSid())) { if (sid == null || !sid.equals(getSid())) {
System.out.println("Ignored Jingle(SID) " + sid + "|" + getSid() + " :" + iq.toXML()); LOGGER.debug("Ignored Jingle(SID) " + sid + "|" + getSid() + " :" + iq.toXML());
return false; return false;
} }
String ini = jin.getInitiator(); String ini = jin.getInitiator();
if (!ini.equals(getInitiator())) { if (!ini.equals(getInitiator())) {
System.out.println("Ignored Jingle(INI): " + iq.toXML()); LOGGER.debug("Ignored Jingle(INI): " + iq.toXML());
return false; return false;
} }
} else { } else {
// We accept some non-Jingle IQ packets: ERRORs and ACKs // We accept some non-Jingle IQ packets: ERRORs and ACKs
if (iq.getType().equals(IQ.Type.SET)) { if (iq.getType().equals(IQ.Type.SET)) {
System.out.println("Ignored Jingle(TYPE): " + iq.toXML()); LOGGER.debug("Ignored Jingle(TYPE): " + iq.toXML());
return false; return false;
} else if (iq.getType().equals(IQ.Type.GET)) { } else if (iq.getType().equals(IQ.Type.GET)) {
System.out.println("Ignored Jingle(TYPE): " + iq.toXML()); LOGGER.debug("Ignored Jingle(TYPE): " + iq.toXML());
return false; return false;
} }
} }
@ -882,12 +904,17 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
public void transportEstablished(TransportCandidate local, TransportCandidate remote) { public void transportEstablished(TransportCandidate local, TransportCandidate remote) {
if (isFullyEstablished()) { if (isFullyEstablished()) {
// Indicate that this session is active.
setSessionState(JingleSessionStateActive.getInstance());
for (ContentNegotiator contentNegotiator : contentNegotiators) { for (ContentNegotiator contentNegotiator : contentNegotiators) {
if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED) if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
contentNegotiator.triggerContentEstablished(); contentNegotiator.triggerContentEstablished();
} }
if (getSessionState().equals(JingleSessionStatePending.getInstance())) { if (getSessionState().equals(JingleSessionStatePending.getInstance())) {
Jingle jout = new Jingle(JingleActionEnum.SESSION_ACCEPT); Jingle jout = new Jingle(JingleActionEnum.SESSION_ACCEPT);
// Build up a response packet from each media manager. // Build up a response packet from each media manager.
@ -1028,7 +1055,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
public void terminate(String reason) throws XMPPException { public void terminate(String reason) throws XMPPException {
if (isClosed()) if (isClosed())
return; return;
System.out.println("Terminate " + reason); LOGGER.debug("Terminate " + reason);
Jingle jout = new Jingle(JingleActionEnum.SESSION_TERMINATE); Jingle jout = new Jingle(JingleActionEnum.SESSION_TERMINATE);
jout.setType(IQ.Type.SET); jout.setType(IQ.Type.SET);
sendPacket(jout); sendPacket(jout);
@ -1055,7 +1082,9 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
contentNegotiator.close(); contentNegotiator.close();
} }
removePacketListener(); removePacketListener();
System.out.println("Negotiation Closed: " + getConnection().getUser() + " " + sid); removeConnectionListener();
getConnection().removeConnectionListener(connectionListener);
LOGGER.debug("Negotiation Closed: " + getConnection().getUser() + " " + sid);
super.close(); super.close();
} }
@ -1114,7 +1143,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
IQ iqError = createIQ(ID, to, from, IQ.Type.ERROR); IQ iqError = createIQ(ID, to, from, IQ.Type.ERROR);
iqError.setError(error); iqError.setError(error);
System.out.println("Created Error Packet:" + iqError.toXML()); LOGGER.debug("Created Error Packet:" + iqError.toXML());
return iqError; return iqError;
} }
@ -1145,7 +1174,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
// NO! Let the normal state machinery do all of the sending. // NO! Let the normal state machinery do all of the sending.
// getConnection().sendPacket(perror); // getConnection().sendPacket(perror);
System.err.println("Error sent: " + errorPacket.toXML()); LOGGER.error("Error sent: " + errorPacket.toXML());
} }
return errorPacket; return errorPacket;
} }

View file

@ -9,6 +9,9 @@ import org.jivesoftware.smackx.packet.JingleError;
* @see JingleSessionState * @see JingleSessionState
*/ */
public class JingleSessionStateEnded extends JingleSessionState { public class JingleSessionStateEnded extends JingleSessionState {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleSessionStateEnded.class);
private static JingleSessionStateEnded INSTANCE = null; private static JingleSessionStateEnded INSTANCE = null;
protected JingleSessionStateEnded() { protected JingleSessionStateEnded() {
@ -28,8 +31,8 @@ public class JingleSessionStateEnded extends JingleSessionState {
} }
public void enter() { public void enter() {
System.out.println("Session Ended"); LOGGER.debug("Session Ended");
System.out.println("-------------------------------------------------------------------"); LOGGER.debug("-------------------------------------------------------------------");
} }

View file

@ -0,0 +1,192 @@
/**
* $RCSfile$
* $Revision: 7071 $
* $Date: 2007-02-11 16:59:05 -0800 (Sun, 11 Feb 2007) $
*
* Copyright 2003-2007 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;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
// --------------------------------------------------------------------------
/**
* SmackLogger attempts to use Apache commons-logging if it's available.
*
* When you request an instance of SmackLogger we make an attempt to create an instance of org.apache.commons.logging.Log.
* If we are able to make an instance of Log then we dispatch all log requests to commons-logging.
* If we are not able to make an instance of Log then we dispatch all log requests to System.out/err.
*
* @author jeffw
*/
public class SmackLogger {
private Log commonsLogger;
// --------------------------------------------------------------------------
/**
* This static method is the only way to get an instance of a SmackLogger.
* @param classToLog This is the class that wants to log. (This gives commons-logging a means to control log-level by class.)
* @return An instance of a SmackLogger for the class that wants logging.
*/
public static SmackLogger getLogger(Class classToLog) {
return new SmackLogger(classToLog);
}
// --------------------------------------------------------------------------
/**
* This is private to make it impossible to instantiate a new SmackLogger outside of the getLogger() static method.
* @param classToLog This is the class that wants to log. (This gives commons-logging a means to control log-level by class.)
*/
public SmackLogger(Class classToLog) {
setupSmackLogger(classToLog);
}
// --------------------------------------------------------------------------
/**
* The actual attempt to create an instance of commons-logging Log.
* @param classToLog
* @return
*/
private void setupSmackLogger(Class classToLog) {
try {
Class logFactoryClass = SmackLogger.class.getClassLoader().loadClass("org.apache.commons.logging.LogFactory");
Method method = logFactoryClass.getMethod("getLog", Class.class);
//Constructor<Log> constructor = Log.class.getConstructor(new Class[] { Object.class });
commonsLogger = (Log) method.invoke(null, classToLog);
// We don't care to do anything about exceptions.
// If we can't create a commons-logger then just use our simple one.
} catch (ClassNotFoundException e) {
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
// --------------------------------------------------------------------------
/**
* Wrapper for commons-logging error(Object msg, Exception exception)
* @param inDebugMsg
*/
public void error(String inErrorMsg, Exception inException) {
if (commonsLogger != null) {
commonsLogger.error(inErrorMsg, inException);
} else {
System.err.println(inErrorMsg);
inException.printStackTrace(System.err);
}
}
// --------------------------------------------------------------------------
/**
* Wrapper for commons-logging error(Object msg)
* @param inDebugMsg
*/
public void error(String inErrorMsg) {
if (commonsLogger != null) {
commonsLogger.error(inErrorMsg);
} else {
System.err.println(inErrorMsg);
}
}
// --------------------------------------------------------------------------
/**
* Wrapper for commons-logging debug(Object msg)
* @param inDebugMsg
*/
public void debug(String inDebugMsg, Exception inException) {
if (commonsLogger != null) {
commonsLogger.debug(inDebugMsg, inException);
} else {
System.out.println(inDebugMsg);
inException.printStackTrace(System.out);
}
}
// --------------------------------------------------------------------------
/**
* Wrapper for commons-logging debug(Object msg)
* @param inDebugMsg
*/
public void debug(String inDebugMsg) {
if (commonsLogger != null) {
commonsLogger.debug(inDebugMsg);
} else {
System.out.println(inDebugMsg);
}
}
// --------------------------------------------------------------------------
/**
* Wrapper for commons-logging warn(Object msg)
* @param inDebugMsg
*/
public void warn(String inDebugMsg, Exception inException) {
if (commonsLogger != null) {
commonsLogger.warn(inDebugMsg, inException);
} else {
System.out.println(inDebugMsg);
inException.printStackTrace(System.out);
}
}
// --------------------------------------------------------------------------
/**
* Wrapper for commons-logging warn(Object msg)
* @param inDebugMsg
*/
public void warn(String inDebugMsg) {
if (commonsLogger != null) {
commonsLogger.warn(inDebugMsg);
} else {
System.out.println(inDebugMsg);
}
}
// --------------------------------------------------------------------------
/**
* Wrapper for commons-logging info(Object msg)
* @param inDebugMsg
*/
public void info(String inDebugMsg, Exception inException) {
if (commonsLogger != null) {
commonsLogger.info(inDebugMsg, inException);
} else {
System.out.println(inDebugMsg);
inException.printStackTrace(System.out);
}
}
// --------------------------------------------------------------------------
/**
* Wrapper for commons-logging info(Object msg)
* @param inDebugMsg
*/
public void info(String inDebugMsg) {
if (commonsLogger != null) {
commonsLogger.info(inDebugMsg);
} else {
System.out.println(inDebugMsg);
}
}
}

View file

@ -19,9 +19,18 @@
*/ */
package org.jivesoftware.smackx.jingle.media; package org.jivesoftware.smackx.jingle.media;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.*; import org.jivesoftware.smackx.jingle.ContentNegotiator;
import org.jivesoftware.smackx.jingle.JingleActionEnum;
import org.jivesoftware.smackx.jingle.JingleException;
import org.jivesoftware.smackx.jingle.JingleNegotiator;
import org.jivesoftware.smackx.jingle.JingleNegotiatorState;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.listeners.JingleListener; import org.jivesoftware.smackx.jingle.listeners.JingleListener;
import org.jivesoftware.smackx.jingle.listeners.JingleMediaListener; import org.jivesoftware.smackx.jingle.listeners.JingleMediaListener;
import org.jivesoftware.smackx.packet.Jingle; import org.jivesoftware.smackx.packet.Jingle;
@ -29,9 +38,6 @@ import org.jivesoftware.smackx.packet.JingleContent;
import org.jivesoftware.smackx.packet.JingleDescription; import org.jivesoftware.smackx.packet.JingleDescription;
import org.jivesoftware.smackx.packet.JingleError; import org.jivesoftware.smackx.packet.JingleError;
import java.util.ArrayList;
import java.util.List;
/** /**
* Manager for jmf descriptor negotiation. <p/> <p/> This class is responsible * Manager for jmf descriptor negotiation. <p/> <p/> This class is responsible
* for managing the descriptor negotiation process, handling all the xmpp * for managing the descriptor negotiation process, handling all the xmpp
@ -42,6 +48,8 @@ import java.util.List;
*/ */
public class MediaNegotiator extends JingleNegotiator { public class MediaNegotiator extends JingleNegotiator {
private static final SmackLogger LOGGER = SmackLogger.getLogger(MediaNegotiator.class);
//private JingleSession session; // The session this negotiation //private JingleSession session; // The session this negotiation
private final JingleMediaManager mediaManager; private final JingleMediaManager mediaManager;
@ -211,7 +219,7 @@ public class MediaNegotiator extends JingleNegotiator {
setNegotiatorState(JingleNegotiatorState.SUCCEEDED); setNegotiatorState(JingleNegotiatorState.SUCCEEDED);
triggerMediaEstablished(getBestCommonAudioPt()); triggerMediaEstablished(getBestCommonAudioPt());
System.err.println("Media choice:" + getBestCommonAudioPt().getName()); LOGGER.error("Media choice:" + getBestCommonAudioPt().getName());
response = session.createAck(jingle); response = session.createAck(jingle);
} }

View file

@ -1,17 +1,24 @@
package org.jivesoftware.smackx.jingle.mediaimpl; package org.jivesoftware.smackx.jingle.mediaimpl;
import com.sun.media.util.Registry; import java.awt.Frame;
import com.sun.media.ExclusiveUse; import java.awt.TextArea;
import java.awt.Toolkit;
import javax.media.format.AudioFormat;
import javax.media.Renderer;
import javax.media.PlugInManager;
import javax.media.Format;
import java.awt.*;
import java.util.Vector; import java.util.Vector;
import javax.media.Format;
import javax.media.PlugInManager;
import javax.media.Renderer;
import javax.media.format.AudioFormat;
import org.jivesoftware.smackx.jingle.SmackLogger;
import com.sun.media.ExclusiveUse;
import com.sun.media.util.Registry;
public class JMFInit extends Frame implements Runnable { public class JMFInit extends Frame implements Runnable {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JMFInit.class);
private String tempDir = "/tmp"; private String tempDir = "/tmp";
private boolean done = false; private boolean done = false;
@ -248,7 +255,7 @@ public class JMFInit extends Frame implements Runnable {
} }
private void message(String mesg) { private void message(String mesg) {
System.out.println(mesg); LOGGER.debug(mesg);
} }
private void createGUI() { private void createGUI() {

View file

@ -19,9 +19,22 @@
*/ */
package org.jivesoftware.smackx.jingle.mediaimpl.jmf; package org.jivesoftware.smackx.jingle.mediaimpl.jmf;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession; import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import javax.media.*; import javax.media.Codec;
import javax.media.Controller;
import javax.media.ControllerClosedEvent;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Format;
import javax.media.MediaLocator;
import javax.media.NoProcessorException;
import javax.media.Processor;
import javax.media.UnsupportedPlugInException;
import javax.media.control.BufferControl; import javax.media.control.BufferControl;
import javax.media.control.PacketSizeControl; import javax.media.control.PacketSizeControl;
import javax.media.control.TrackControl; import javax.media.control.TrackControl;
@ -34,11 +47,9 @@ import javax.media.rtp.InvalidSessionAddressException;
import javax.media.rtp.RTPManager; import javax.media.rtp.RTPManager;
import javax.media.rtp.SendStream; import javax.media.rtp.SendStream;
import javax.media.rtp.SessionAddress; import javax.media.rtp.SessionAddress;
import java.io.IOException;
import java.net.InetAddress; import org.jivesoftware.smackx.jingle.SmackLogger;
import java.net.UnknownHostException; import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import java.util.ArrayList;
import java.util.List;
/** /**
* An Easy to use Audio Channel implemented using JMF. * An Easy to use Audio Channel implemented using JMF.
@ -60,6 +71,8 @@ import java.util.List;
*/ */
public class AudioChannel { public class AudioChannel {
private static final SmackLogger LOGGER = SmackLogger.getLogger(AudioChannel.class);
private MediaLocator locator; private MediaLocator locator;
private String localIpAddress; private String localIpAddress;
private String remoteIpAddress; private String remoteIpAddress;
@ -239,8 +252,8 @@ public class AudioChannel {
} }
if (chosen != null) { if (chosen != null) {
tracks[i].setFormat(chosen); tracks[i].setFormat(chosen);
System.err.println("Track " + i + " is set to transmit as:"); LOGGER.error("Track " + i + " is set to transmit as:");
System.err.println(" " + chosen); LOGGER.error(" " + chosen);
if (tracks[i].getFormat() instanceof AudioFormat) { if (tracks[i].getFormat() instanceof AudioFormat) {
int packetRate = 20; int packetRate = 20;
@ -375,7 +388,7 @@ public class AudioChannel {
rtpMgrs[i].addTarget(destAddr); rtpMgrs[i].addTarget(destAddr);
System.err.println("Created RTP session at " + localPort + " to: " + remoteIpAddress + " " + port); LOGGER.error("Created RTP session at " + localPort + " to: " + remoteIpAddress + " " + port);
sendStream = rtpMgrs[i].createSendStream(dataOutput, i); sendStream = rtpMgrs[i].createSendStream(dataOutput, i);
@ -404,11 +417,11 @@ public class AudioChannel {
try { try {
if (active) { if (active) {
sendStream.start(); sendStream.start();
System.out.println("START"); LOGGER.debug("START");
} }
else { else {
sendStream.stop(); sendStream.stop();
System.out.println("STOP"); LOGGER.debug("STOP");
} }
} }
catch (IOException e) { catch (IOException e) {

View file

@ -20,15 +20,17 @@
package org.jivesoftware.smackx.jingle.mediaimpl.jmf; package org.jivesoftware.smackx.jingle.mediaimpl.jmf;
import java.io.IOException;
import java.net.ServerSocket;
import javax.media.MediaLocator;
import org.jivesoftware.smackx.jingle.JingleSession; import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession; import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.PayloadType; import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate; import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
import javax.media.MediaLocator;
import java.io.IOException;
import java.net.ServerSocket;
/** /**
* This Class implements a complete JingleMediaSession. * This Class implements a complete JingleMediaSession.
* It sould be used to transmit and receive audio captured from the Mic. * It sould be used to transmit and receive audio captured from the Mic.
@ -41,6 +43,8 @@ import java.net.ServerSocket;
*/ */
public class AudioMediaSession extends JingleMediaSession { public class AudioMediaSession extends JingleMediaSession {
private static final SmackLogger LOGGER = SmackLogger.getLogger(AudioMediaSession.class);
private AudioChannel audioChannel; private AudioChannel audioChannel;
/** /**
@ -73,7 +77,7 @@ public class AudioMediaSession extends JingleMediaSession {
localPort = getFreePort(); localPort = getFreePort();
remotePort = this.getLocal().getSymmetric().getPort(); remotePort = this.getLocal().getSymmetric().getPort();
System.out.println(this.getLocal().getConnection() + " " + ip + ": " + localPort + "->" + remotePort); LOGGER.debug(this.getLocal().getConnection() + " " + ip + ": " + localPort + "->" + remotePort);
} }
else { else {

View file

@ -20,12 +20,27 @@
package org.jivesoftware.smackx.jingle.mediaimpl.jmf; package org.jivesoftware.smackx.jingle.mediaimpl.jmf;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession; import javax.media.ControllerErrorEvent;
import javax.media.ControllerEvent;
import javax.media.*; import javax.media.ControllerListener;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import javax.media.protocol.DataSource; import javax.media.protocol.DataSource;
import javax.media.rtp.*; import javax.media.rtp.Participant;
import javax.media.rtp.event.*; import javax.media.rtp.RTPControl;
import javax.media.rtp.ReceiveStream;
import javax.media.rtp.ReceiveStreamListener;
import javax.media.rtp.SessionListener;
import javax.media.rtp.event.ByeEvent;
import javax.media.rtp.event.NewParticipantEvent;
import javax.media.rtp.event.NewReceiveStreamEvent;
import javax.media.rtp.event.ReceiveStreamEvent;
import javax.media.rtp.event.RemotePayloadChangeEvent;
import javax.media.rtp.event.SessionEvent;
import javax.media.rtp.event.StreamMappedEvent;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
/** /**
* This class implements receive methods and listeners to be used in AudioChannel * This class implements receive methods and listeners to be used in AudioChannel
@ -35,6 +50,8 @@ import javax.media.rtp.event.*;
public class AudioReceiver implements ReceiveStreamListener, SessionListener, public class AudioReceiver implements ReceiveStreamListener, SessionListener,
ControllerListener { ControllerListener {
private static final SmackLogger LOGGER = SmackLogger.getLogger(AudioReceiver.class);
boolean dataReceived = false; boolean dataReceived = false;
Object dataSync; Object dataSync;
@ -51,7 +68,7 @@ public class AudioReceiver implements ReceiveStreamListener, SessionListener,
public synchronized void update(SessionEvent evt) { public synchronized void update(SessionEvent evt) {
if (evt instanceof NewParticipantEvent) { if (evt instanceof NewParticipantEvent) {
Participant p = ((NewParticipantEvent) evt).getParticipant(); Participant p = ((NewParticipantEvent) evt).getParticipant();
System.err.println(" - A new participant had just joined: " + p.getCNAME()); LOGGER.error(" - A new participant had just joined: " + p.getCNAME());
} }
} }
@ -64,8 +81,8 @@ public class AudioReceiver implements ReceiveStreamListener, SessionListener,
ReceiveStream stream = evt.getReceiveStream(); // could be null. ReceiveStream stream = evt.getReceiveStream(); // could be null.
if (evt instanceof RemotePayloadChangeEvent) { if (evt instanceof RemotePayloadChangeEvent) {
System.err.println(" - Received an RTP PayloadChangeEvent."); LOGGER.error(" - Received an RTP PayloadChangeEvent.");
System.err.println("Sorry, cannot handle payload change."); LOGGER.error("Sorry, cannot handle payload change.");
} }
else if (evt instanceof NewReceiveStreamEvent) { else if (evt instanceof NewReceiveStreamEvent) {
@ -77,15 +94,15 @@ public class AudioReceiver implements ReceiveStreamListener, SessionListener,
// Find out the formats. // Find out the formats.
RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl"); RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl");
if (ctl != null) { if (ctl != null) {
System.err.println(" - Recevied new RTP stream: " + ctl.getFormat()); LOGGER.error(" - Recevied new RTP stream: " + ctl.getFormat());
} }
else else
System.err.println(" - Recevied new RTP stream"); LOGGER.error(" - Recevied new RTP stream");
if (participant == null) if (participant == null)
System.err.println(" The sender of this stream had yet to be identified."); LOGGER.error(" The sender of this stream had yet to be identified.");
else { else {
System.err.println(" The stream comes from: " + participant.getCNAME()); LOGGER.error(" The stream comes from: " + participant.getCNAME());
} }
// create a player by passing datasource to the Media Manager // create a player by passing datasource to the Media Manager
@ -105,7 +122,7 @@ public class AudioReceiver implements ReceiveStreamListener, SessionListener,
} }
catch (Exception e) { catch (Exception e) {
System.err.println("NewReceiveStreamEvent exception " + e.getMessage()); LOGGER.error("NewReceiveStreamEvent exception " + e.getMessage());
return; return;
} }
@ -116,15 +133,15 @@ public class AudioReceiver implements ReceiveStreamListener, SessionListener,
DataSource ds = stream.getDataSource(); DataSource ds = stream.getDataSource();
// Find out the formats. // Find out the formats.
RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl"); RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl");
System.err.println(" - The previously unidentified stream "); LOGGER.error(" - The previously unidentified stream ");
if (ctl != null) if (ctl != null)
System.err.println(" " + ctl.getFormat()); LOGGER.error(" " + ctl.getFormat());
System.err.println(" had now been identified as sent by: " + participant.getCNAME()); LOGGER.error(" had now been identified as sent by: " + participant.getCNAME());
} }
} }
else if (evt instanceof ByeEvent) { else if (evt instanceof ByeEvent) {
System.err.println(" - Got \"bye\" from: " + participant.getCNAME()); LOGGER.error(" - Got \"bye\" from: " + participant.getCNAME());
} }
@ -147,7 +164,7 @@ public class AudioReceiver implements ReceiveStreamListener, SessionListener,
if (ce instanceof ControllerErrorEvent) { if (ce instanceof ControllerErrorEvent) {
p.removeControllerListener(this); p.removeControllerListener(this);
System.err.println("Receiver internal error: " + ce); LOGGER.error("Receiver internal error: " + ce);
} }
} }

View file

@ -20,7 +20,13 @@
package org.jivesoftware.smackx.jingle.mediaimpl.jmf; package org.jivesoftware.smackx.jingle.mediaimpl.jmf;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smackx.jingle.JingleSession; import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.media.JingleMediaManager; import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession; import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.PayloadType; import org.jivesoftware.smackx.jingle.media.PayloadType;
@ -28,11 +34,6 @@ import org.jivesoftware.smackx.jingle.mediaimpl.JMFInit;
import org.jivesoftware.smackx.jingle.nat.JingleTransportManager; import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate; import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/** /**
* Implements a jingleMediaManager using JMF based API. * Implements a jingleMediaManager using JMF based API.
* It supports GSM and G723 codecs. * It supports GSM and G723 codecs.
@ -42,6 +43,8 @@ import java.util.List;
*/ */
public class JmfMediaManager extends JingleMediaManager { public class JmfMediaManager extends JingleMediaManager {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JmfMediaManager.class);
public static final String MEDIA_NAME = "JMF"; public static final String MEDIA_NAME = "JMF";
@ -142,7 +145,7 @@ public class JmfMediaManager extends JingleMediaManager {
jmfProperties.createNewFile(); jmfProperties.createNewFile();
} }
catch (IOException ex) { catch (IOException ex) {
System.out.println("Failed to create jmf.properties"); LOGGER.debug("Failed to create jmf.properties");
ex.printStackTrace(); ex.printStackTrace();
} }
} }

View file

@ -20,25 +20,28 @@
package org.jivesoftware.smackx.jingle.mediaimpl.jspeex; package org.jivesoftware.smackx.jingle.mediaimpl.jspeex;
import mil.jfcom.cie.media.session.MediaSession;
import mil.jfcom.cie.media.session.MediaSessionListener;
import mil.jfcom.cie.media.session.StreamPlayer;
import mil.jfcom.cie.media.srtp.packetizer.SpeexFormat;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
import javax.media.NoProcessorException;
import javax.media.format.UnsupportedFormatException;
import javax.media.rtp.rtcp.SenderReport;
import javax.media.rtp.rtcp.SourceDescription;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import javax.media.NoProcessorException;
import javax.media.format.UnsupportedFormatException;
import javax.media.rtp.rtcp.SenderReport;
import javax.media.rtp.rtcp.SourceDescription;
import mil.jfcom.cie.media.session.MediaSession;
import mil.jfcom.cie.media.session.MediaSessionListener;
import mil.jfcom.cie.media.session.StreamPlayer;
import mil.jfcom.cie.media.srtp.packetizer.SpeexFormat;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
/** /**
* This Class implements a complete JingleMediaSession. * This Class implements a complete JingleMediaSession.
* It sould be used to transmit and receive audio captured from the Mic. * It sould be used to transmit and receive audio captured from the Mic.
@ -52,6 +55,8 @@ import java.security.GeneralSecurityException;
public class AudioMediaSession extends JingleMediaSession implements MediaSessionListener { public class AudioMediaSession extends JingleMediaSession implements MediaSessionListener {
private static final SmackLogger LOGGER = SmackLogger.getLogger(AudioMediaSession.class);
private MediaSession mediaSession; private MediaSession mediaSession;
/** /**
@ -123,7 +128,7 @@ public class AudioMediaSession extends JingleMediaSession implements MediaSessio
localPort = getFreePort(); localPort = getFreePort();
remotePort = this.getLocal().getSymmetric().getPort(); remotePort = this.getLocal().getSymmetric().getPort();
System.out.println(this.getLocal().getConnection() + " " + ip + ": " + localPort + "->" + remotePort); LOGGER.debug(this.getLocal().getConnection() + " " + ip + ": " + localPort + "->" + remotePort);
} }
else { else {
@ -155,7 +160,7 @@ public class AudioMediaSession extends JingleMediaSession implements MediaSessio
*/ */
public void startTrasmit() { public void startTrasmit() {
try { try {
System.out.println("start"); LOGGER.debug("start");
mediaSession.start(true); mediaSession.start(true);
this.mediaReceived(""); this.mediaReceived("");
} }

View file

@ -19,7 +19,13 @@
*/ */
package org.jivesoftware.smackx.jingle.mediaimpl.jspeex; package org.jivesoftware.smackx.jingle.mediaimpl.jspeex;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smackx.jingle.JingleSession; import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.media.JingleMediaManager; import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession; import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.PayloadType; import org.jivesoftware.smackx.jingle.media.PayloadType;
@ -27,11 +33,6 @@ import org.jivesoftware.smackx.jingle.mediaimpl.JMFInit;
import org.jivesoftware.smackx.jingle.nat.JingleTransportManager; import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate; import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/** /**
* Implements a jingleMediaManager using JMF based API and JSpeex. * Implements a jingleMediaManager using JMF based API and JSpeex.
* It supports Speex codec. * It supports Speex codec.
@ -41,6 +42,8 @@ import java.util.List;
*/ */
public class SpeexMediaManager extends JingleMediaManager { public class SpeexMediaManager extends JingleMediaManager {
private static final SmackLogger LOGGER = SmackLogger.getLogger(SpeexMediaManager.class);
public static final String MEDIA_NAME = "Speex"; public static final String MEDIA_NAME = "Speex";
private List<PayloadType> payloads = new ArrayList<PayloadType>(); private List<PayloadType> payloads = new ArrayList<PayloadType>();
@ -106,7 +109,7 @@ public class SpeexMediaManager extends JingleMediaManager {
jmfProperties.createNewFile(); jmfProperties.createNewFile();
} }
catch (IOException ex) { catch (IOException ex) {
System.out.println("Failed to create jmf.properties"); LOGGER.debug("Failed to create jmf.properties");
ex.printStackTrace(); ex.printStackTrace();
} }
} }

View file

@ -19,17 +19,7 @@
*/ */
package org.jivesoftware.smackx.jingle.mediaimpl.sshare; package org.jivesoftware.smackx.jingle.mediaimpl.sshare;
import org.jivesoftware.smackx.jingle.JingleSession; import java.awt.Rectangle;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.api.ImageDecoder;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.api.ImageEncoder;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.api.ImageReceiver;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.api.ImageTransmitter;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.IOException; import java.io.IOException;
@ -38,6 +28,19 @@ import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.api.ImageDecoder;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.api.ImageEncoder;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.api.ImageReceiver;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.api.ImageTransmitter;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
/** /**
* This Class implements a complete JingleMediaSession. * This Class implements a complete JingleMediaSession.
* It sould be used to transmit and receive captured images from the Display. * It sould be used to transmit and receive captured images from the Display.
@ -49,6 +52,8 @@ import java.net.UnknownHostException;
*/ */
public class ScreenShareSession extends JingleMediaSession { public class ScreenShareSession extends JingleMediaSession {
private static final SmackLogger LOGGER = SmackLogger.getLogger(ScreenShareSession.class);
private ImageTransmitter transmitter = null; private ImageTransmitter transmitter = null;
private ImageReceiver receiver = null; private ImageReceiver receiver = null;
private int width = 600; private int width = 600;
@ -102,7 +107,7 @@ public class ScreenShareSession extends JingleMediaSession {
try { try {
receiver = new ImageReceiver(InetAddress.getByName("0.0.0.0"), getRemote().getPort(), getLocal().getPort(), width, receiver = new ImageReceiver(InetAddress.getByName("0.0.0.0"), getRemote().getPort(), getLocal().getPort(), width,
height); height);
System.out.println("Receiving on:" + receiver.getLocalPort()); LOGGER.debug("Receiving on:" + receiver.getLocalPort());
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -1,6 +1,8 @@
package org.jivesoftware.smackx.jingle.mediaimpl.sshare.api; package org.jivesoftware.smackx.jingle.mediaimpl.sshare.api;
import java.awt.*; import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber; import java.awt.image.PixelGrabber;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -10,6 +12,8 @@ import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Arrays; import java.util.Arrays;
import org.jivesoftware.smackx.jingle.SmackLogger;
/** /**
* UDP Image Receiver. * UDP Image Receiver.
* It uses PNG Tiles into UDP packets. * It uses PNG Tiles into UDP packets.
@ -18,6 +22,8 @@ import java.util.Arrays;
*/ */
public class ImageTransmitter implements Runnable { public class ImageTransmitter implements Runnable {
private static final SmackLogger LOGGER = SmackLogger.getLogger(ImageTransmitter.class);
private Robot robot; private Robot robot;
private InetAddress localHost; private InetAddress localHost;
private InetAddress remoteHost; private InetAddress remoteHost;
@ -80,7 +86,7 @@ public class ImageTransmitter implements Runnable {
if (++keyframe > KEYFRAME) { if (++keyframe > KEYFRAME) {
keyframe = 0; keyframe = 0;
} }
System.out.println("KEYFRAME:" + keyframe); LOGGER.debug("KEYFRAME:" + keyframe);
for (int i = 0; i < maxI; i++) { for (int i = 0; i < maxI; i++) {
for (int j = 0; j < maxJ; j++) { for (int j = 0; j < maxJ; j++) {
@ -110,7 +116,7 @@ public class ImageTransmitter implements Runnable {
byte[] bytesOut = baos.toByteArray(); byte[] bytesOut = baos.toByteArray();
if (bytesOut.length > 1000) if (bytesOut.length > 1000)
System.err.println(bytesOut.length); LOGGER.error("Bytes out > 1000. Equals " + bytesOut.length);
p.setData(bytesOut); p.setData(bytesOut);
p.setAddress(remoteHost); p.setAddress(remoteHost);
@ -142,7 +148,7 @@ public class ImageTransmitter implements Runnable {
} }
trace = (System.currentTimeMillis() - trace); trace = (System.currentTimeMillis() - trace);
System.out.println("Loop Time:" + trace); LOGGER.debug("Loop Time:" + trace);
if (trace < 500) { if (trace < 500) {
try { try {

View file

@ -19,6 +19,8 @@ package org.jivesoftware.smackx.jingle.mediaimpl.sshare.api;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Vector; import java.util.Vector;
import org.jivesoftware.smackx.jingle.SmackLogger;
/** /**
* An image Quantizer based on the Octree algorithm. This is a very basic implementation * An image Quantizer based on the Octree algorithm. This is a very basic implementation
* at present and could be much improved by picking the nodes to reduce more carefully * at present and could be much improved by picking the nodes to reduce more carefully
@ -26,6 +28,8 @@ import java.util.Vector;
*/ */
public class OctTreeQuantizer implements Quantizer { public class OctTreeQuantizer implements Quantizer {
private static final SmackLogger LOGGER = SmackLogger.getLogger(OctTreeQuantizer.class);
/** /**
* The greatest depth the tree is allowed to reach * The greatest depth the tree is allowed to reach
*/ */
@ -50,12 +54,13 @@ public class OctTreeQuantizer implements Quantizer {
* A debugging method which prints the tree out. * A debugging method which prints the tree out.
*/ */
public void list(PrintStream s, int level) { public void list(PrintStream s, int level) {
String indentStr = "";
for (int i = 0; i < level; i++) for (int i = 0; i < level; i++)
System.out.print(' '); indentStr += " ";
if (count == 0) if (count == 0)
System.out.println(index+": count="+count); LOGGER.debug(indentStr + index + ": count=" + count);
else else
System.out.println(index+": count="+count+" red="+(totalRed/count)+" green="+(totalGreen/count)+" blue="+(totalBlue/count)); LOGGER.debug(indentStr + index + ": count=" + count + " red=" + (totalRed/count) + " green=" + (totalGreen / count) + " blue=" + (totalBlue / count));
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
if (leaf[i] != null) if (leaf[i] != null)
leaf[i].list(s, level+2); leaf[i].list(s, level+2);
@ -133,7 +138,7 @@ public class OctTreeQuantizer implements Quantizer {
else else
node = child; node = child;
} }
System.out.println("getIndexForColor failed"); LOGGER.debug("getIndexForColor failed");
return 0; return 0;
} }
@ -144,7 +149,7 @@ public class OctTreeQuantizer implements Quantizer {
OctTreeNode node = root; OctTreeNode node = root;
// System.out.println("insertColor="+Integer.toHexString(rgb)); // LOGGER.debug("insertColor="+Integer.toHexString(rgb));
for (int level = 0; level <= MAX_LEVEL; level++) { for (int level = 0; level <= MAX_LEVEL; level++) {
OctTreeNode child; OctTreeNode child;
int bit = 0x80 >> level; int bit = 0x80 >> level;
@ -190,7 +195,7 @@ public class OctTreeQuantizer implements Quantizer {
} else } else
node = child; node = child;
} }
System.out.println("insertColor failed"); LOGGER.debug("insertColor failed");
} }
private void reduceTree(int numColors) { private void reduceTree(int numColors) {
@ -204,7 +209,7 @@ public class OctTreeQuantizer implements Quantizer {
OctTreeNode child = node.leaf[i]; OctTreeNode child = node.leaf[i];
if (child != null) { if (child != null) {
if (!child.isLeaf) if (!child.isLeaf)
System.out.println("not a leaf!"); LOGGER.debug("not a leaf!");
node.count += child.count; node.count += child.count;
node.totalRed += child.totalRed; node.totalRed += child.totalRed;
node.totalGreen += child.totalGreen; node.totalGreen += child.totalGreen;
@ -225,7 +230,7 @@ public class OctTreeQuantizer implements Quantizer {
} }
} }
System.out.println("Unable to reduce the OctTree"); LOGGER.debug("Unable to reduce the OctTree");
} }
/** /**

View file

@ -52,28 +52,36 @@
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.jivesoftware.smackx.jingle.SmackLogger;
/** /**
* A very Simple HTTP Server * A very Simple HTTP Server
*/ */
public class HttpServer { public class HttpServer {
private static final SmackLogger LOGGER = SmackLogger.getLogger(HttpServer.class);
public HttpServer(int port) { public HttpServer(int port) {
ServerSocket server_socket; ServerSocket server_socket;
try { try {
server_socket = new ServerSocket(port); server_socket = new ServerSocket(port);
System.out.println("httpServer running on port " + LOGGER.debug("httpServer running on port " +
server_socket.getLocalPort()); server_socket.getLocalPort());
while (true) { while (true) {
Socket socket = server_socket.accept(); Socket socket = server_socket.accept();
System.out.println("New connection accepted " + LOGGER.debug("New connection accepted " +
socket.getInetAddress() + socket.getInetAddress() +
":" + socket.getPort()); ":" + socket.getPort());
@ -86,13 +94,13 @@ public class HttpServer {
thread.start(); thread.start();
} }
catch (Exception e) { catch (Exception e) {
System.out.println(e); LOGGER.debug("", e);
} }
} }
} }
catch (IOException e) { catch (IOException e) {
System.out.println(e); LOGGER.debug("", e);
} }
} }
@ -129,7 +137,7 @@ public class HttpServer {
while (true) { while (true) {
String headerLine = br.readLine(); String headerLine = br.readLine();
System.out.println(headerLine); LOGGER.debug(headerLine);
if (headerLine.equals(CRLF) || headerLine.equals("")) break; if (headerLine.equals(CRLF) || headerLine.equals("")) break;
StringTokenizer s = new StringTokenizer(headerLine); StringTokenizer s = new StringTokenizer(headerLine);

View file

@ -55,6 +55,8 @@ import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.List; import java.util.List;
import org.jivesoftware.smackx.jingle.SmackLogger;
/** /**
* ICE Transport candidate. * ICE Transport candidate.
* <p/> * <p/>
@ -65,6 +67,8 @@ import java.util.List;
*/ */
public class ICECandidate extends TransportCandidate implements Comparable { public class ICECandidate extends TransportCandidate implements Comparable {
private static final SmackLogger LOGGER = SmackLogger.getLogger(ICECandidate.class);
private String id; // An identification private String id; // An identification
private String username; private String username;
@ -273,7 +277,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
public void testFinished(TestResult testResult, TransportCandidate candidate) { public void testFinished(TestResult testResult, TransportCandidate candidate) {
if (testResult.isReachable() && checkingCandidate.equals(candidate)) { if (testResult.isReachable() && checkingCandidate.equals(candidate)) {
result.setResult(true); result.setResult(true);
System.out.println("RESULT>>>OK:" + candidate.getIp() + ":" + candidate.getPort()); LOGGER.debug("Candidate reachable: " + candidate.getIp() + ":" + candidate.getPort() + " from " + getIp() +":" + getPort());
} }
} }
}; };
@ -299,7 +303,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
for (int i = 0; i < 10 && !result.isReachable(); i++) for (int i = 0; i < 10 && !result.isReachable(); i++)
try { try {
System.err.println("ICE Candidate retry #" + i); LOGGER.error("ICE Candidate retry #" + i);
Thread.sleep(400); Thread.sleep(400);
} }
catch (InterruptedException e) { catch (InterruptedException e) {

View file

@ -20,20 +20,24 @@
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import de.javawi.jstun.test.demo.ice.Candidate;
import de.javawi.jstun.test.demo.ice.ICENegociator;
import de.javawi.jstun.util.UtilityException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Random; import java.util.Random;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import de.javawi.jstun.test.demo.ice.Candidate;
import de.javawi.jstun.test.demo.ice.ICENegociator;
import de.javawi.jstun.util.UtilityException;
/** /**
* ICE Resolver for Jingle transport method that results in sending data between two entities using the Interactive Connectivity Establishment (ICE) methodology. (XEP-0176) * ICE Resolver for Jingle transport method that results in sending data between two entities using the Interactive Connectivity Establishment (ICE) methodology. (XEP-0176)
* The goal of this resolver is to make possible to establish and manage out-of-band connections between two XMPP entities, even if they are behind Network Address Translators (NATs) or firewalls. * The goal of this resolver is to make possible to establish and manage out-of-band connections between two XMPP entities, even if they are behind Network Address Translators (NATs) or firewalls.
@ -43,12 +47,15 @@ import java.util.Random;
*/ */
public class ICEResolver extends TransportResolver { public class ICEResolver extends TransportResolver {
private static final SmackLogger LOGGER = SmackLogger.getLogger(ICEResolver.class);
XMPPConnection connection; XMPPConnection connection;
Random random = new Random(); Random random = new Random();
long sid; long sid;
String server = "stun.xten.net"; String server;
int port = 3478; int port;
ICENegociator iceNegociator = null; static Map<String, ICENegociator> negociatorsMap = new HashMap<String, ICENegociator>();
//ICENegociator iceNegociator = null;
public ICEResolver(XMPPConnection connection, String server, int port) { public ICEResolver(XMPPConnection connection, String server, int port) {
super(); super();
@ -60,13 +67,21 @@ public class ICEResolver extends TransportResolver {
public void initialize() throws XMPPException { public void initialize() throws XMPPException {
if (!isResolving() && !isResolved()) { if (!isResolving() && !isResolved()) {
System.out.println("Initialized"); LOGGER.debug("Initialized");
// Negotiation with a STUN server for a set of interfaces is quite slow, but the results
// never change over then instance of a JVM. To increase connection performance considerably
// we now cache established/initialized negotiators for each STUN server, so that subsequent uses
// of the STUN server are much, much faster.
if (negociatorsMap.get(server) == null) {
ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1);
negociatorsMap.put(server, iceNegociator);
iceNegociator = new ICENegociator((short) 1, server, port);
// gather candidates // gather candidates
iceNegociator.gatherCandidateAddresses(); iceNegociator.gatherCandidateAddresses();
// priorize candidates // priorize candidates
iceNegociator.prioritizeCandidates(); iceNegociator.prioritizeCandidates();
}
} }
this.setInitialized(); this.setInitialized();
@ -91,6 +106,8 @@ public class ICEResolver extends TransportResolver {
this.clear(); this.clear();
// Create a transport candidate for each ICE negotiator candidate we have.
ICENegociator iceNegociator = negociatorsMap.get(server);
for (Candidate candidate : iceNegociator.getSortedCandidates()) for (Candidate candidate : iceNegociator.getSortedCandidates())
try { try {
Candidate.CandidateType type = candidate.getCandidateType(); Candidate.CandidateType type = candidate.getCandidateType();
@ -104,7 +121,26 @@ public class ICEResolver extends TransportResolver {
else else
iceType = ICECandidate.Type.host; iceType = ICECandidate.Type.host;
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType); // JBW/GW - 17JUL08: Figure out the zero-based NIC number for this candidate.
short nicNum = 0;
try {
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
short i = 0;
NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
while(nics.hasMoreElements()) {
NetworkInterface checkNIC = nics.nextElement();
if (checkNIC.equals(nic)) {
nicNum = i;
break;
}
i++;
}
} catch (SocketException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType);
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress()); transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
transportCandidate.setPort(getFreePort()); transportCandidate.setPort(getFreePort());
try { try {
@ -115,7 +151,7 @@ public class ICEResolver extends TransportResolver {
} }
this.addCandidate(transportCandidate); this.addCandidate(transportCandidate);
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " p:" + candidate.getPriority()); LOGGER.debug("Candidate addr: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " Priority:" + candidate.getPriority());
} }
catch (UtilityException e) { catch (UtilityException e) {
@ -128,16 +164,19 @@ public class ICEResolver extends TransportResolver {
// Get a Relay Candidate from XMPP Server // Get a Relay Candidate from XMPP Server
if (RTPBridge.serviceAvailable(connection)) { if (RTPBridge.serviceAvailable(connection)) {
try { // try {
String localIp; String localIp;
int network; int network;
if (iceNegociator.getPublicCandidate() != null) {
localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress(); // JBW/GW - 17JUL08: ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now the API doesn't exist in JSTUN 1.7.1
network = iceNegociator.getPublicCandidate().getNetwork(); // if (iceNegociator.getPublicCandidate() != null) {
} // localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress();
else { // network = iceNegociator.getPublicCandidate().getNetwork();
// }
// else {
{
localIp = BridgedResolver.getLocalHost(); localIp = BridgedResolver.getLocalHost();
network = 0; network = 0;
} }
@ -168,17 +207,19 @@ public class ICEResolver extends TransportResolver {
addCandidate(localCandidate); addCandidate(localCandidate);
} // }
catch (UtilityException e) { // catch (UtilityException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
catch (UnknownHostException e) { // catch (UnknownHostException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
// Get Public Candidate From XMPP Server // Get Public Candidate From XMPP Server
if (iceNegociator.getPublicCandidate() == null) { // JBW/GW - 17JUL08 - ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now it doesn't exist in JSTUN 1.7.1
// if (iceNegociator.getPublicCandidate() == null) {
if (true) {
String publicIp = RTPBridge.getPublicIP(connection); String publicIp = RTPBridge.getPublicIP(connection);

View file

@ -20,6 +20,12 @@
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Iterator;
import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -29,15 +35,10 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smackx.ServiceDiscoveryManager; import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.packet.DiscoverItems; import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Iterator;
/** /**
* RTPBridge IQ Packet used to request and retrieve a RTPBridge Candidates that can be used for a Jingle Media Transmission between two parties that are behind NAT. * RTPBridge IQ Packet used to request and retrieve a RTPBridge Candidates that can be used for a Jingle Media Transmission between two parties that are behind NAT.
* This Jingle Bridge has all the needed information to establish a full UDP Channel (Send and Receive) between two parties. * This Jingle Bridge has all the needed information to establish a full UDP Channel (Send and Receive) between two parties.
@ -51,6 +52,8 @@ import java.util.Iterator;
*/ */
public class RTPBridge extends IQ { public class RTPBridge extends IQ {
private static final SmackLogger LOGGER = SmackLogger.getLogger(RTPBridge.class);
private String sid; private String sid;
private String pass; private String pass;
private String ip; private String ip;
@ -424,16 +427,25 @@ public class RTPBridge extends IQ {
return false; return false;
} }
System.out.println("Service listing"); LOGGER.debug("Service listing");
ServiceDiscoveryManager disco = ServiceDiscoveryManager ServiceDiscoveryManager disco = ServiceDiscoveryManager
.getInstanceFor(xmppConnection); .getInstanceFor(xmppConnection);
try { try {
DiscoverItems items = disco.discoverItems(xmppConnection.getServiceName()); // DiscoverItems items = disco.discoverItems(xmppConnection.getServiceName());
Iterator iter = items.getItems(); // Iterator iter = items.getItems();
// while (iter.hasNext()) {
// DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
// if (item.getEntityID().startsWith("rtpbridge.")) {
// return true;
// }
// }
DiscoverInfo discoInfo = disco.discoverInfo(xmppConnection.getServiceName());
Iterator iter = discoInfo.getIdentities();
while (iter.hasNext()) { while (iter.hasNext()) {
DiscoverItems.Item item = (DiscoverItems.Item) iter.next(); DiscoverInfo.Identity identity = (DiscoverInfo.Identity) iter.next();
if (item.getEntityID().startsWith("rtpbridge.")) { if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) {
return true; return true;
} }
} }
@ -467,7 +479,7 @@ public class RTPBridge extends IQ {
rtpPacket.setHostA(localCandidate.getIp()); rtpPacket.setHostA(localCandidate.getIp());
rtpPacket.setHostB(proxyCandidate.getIp()); rtpPacket.setHostB(proxyCandidate.getIp());
// System.out.println("Relayed to: " + candidate.getIp() + ":" + candidate.getPort()); // LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
PacketCollector collector = xmppConnection PacketCollector collector = xmppConnection
.createPacketCollector(new PacketIDFilter(rtpPacket.getPacketID())); .createPacketCollector(new PacketIDFilter(rtpPacket.getPacketID()));
@ -499,7 +511,7 @@ public class RTPBridge extends IQ {
rtpPacket.setTo(RTPBridge.NAME + "." + xmppConnection.getServiceName()); rtpPacket.setTo(RTPBridge.NAME + "." + xmppConnection.getServiceName());
rtpPacket.setType(Type.SET); rtpPacket.setType(Type.SET);
// System.out.println("Relayed to: " + candidate.getIp() + ":" + candidate.getPort()); // LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
PacketCollector collector = xmppConnection PacketCollector collector = xmppConnection
.createPacketCollector(new PacketIDFilter(rtpPacket.getPacketID())); .createPacketCollector(new PacketIDFilter(rtpPacket.getPacketID()));

View file

@ -19,6 +19,10 @@
*/ */
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -28,14 +32,11 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smackx.ServiceDiscoveryManager; import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.packet.DiscoverInfo; import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverItems; import org.jivesoftware.smackx.packet.DiscoverItems;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/** /**
* STUN IQ Packet used to request and retrieve a STUN server and port to make p2p connections easier. STUN is usually used by Jingle Media Transmission between two parties that are behind NAT. * STUN IQ Packet used to request and retrieve a STUN server and port to make p2p connections easier. STUN is usually used by Jingle Media Transmission between two parties that are behind NAT.
* <p/> * <p/>
@ -47,6 +48,8 @@ import java.util.List;
*/ */
public class STUN extends IQ { public class STUN extends IQ {
private static final SmackLogger LOGGER = SmackLogger.getLogger(STUN.class);
private List<StunServerAddress> servers = new ArrayList<StunServerAddress>(); private List<StunServerAddress> servers = new ArrayList<StunServerAddress>();
private String publicIp = null; private String publicIp = null;
@ -220,7 +223,7 @@ public class STUN extends IQ {
return false; return false;
} }
System.out.println("Service listing"); LOGGER.debug("Service listing");
ServiceDiscoveryManager disco = ServiceDiscoveryManager ServiceDiscoveryManager disco = ServiceDiscoveryManager
.getInstanceFor(xmppConnection); .getInstanceFor(xmppConnection);
@ -240,7 +243,7 @@ public class STUN extends IQ {
return true; return true;
} }
System.out.println(item.getName()+"-"+info.getType()); LOGGER.debug(item.getName()+"-"+info.getType());
} }
} }

View file

@ -19,15 +19,6 @@
*/ */
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import de.javawi.jstun.test.BindingLifetimeTest;
import de.javawi.jstun.test.DiscoveryInfo;
import de.javawi.jstun.test.DiscoveryTest;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
@ -36,6 +27,17 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import de.javawi.jstun.test.BindingLifetimeTest;
import de.javawi.jstun.test.DiscoveryInfo;
import de.javawi.jstun.test.DiscoveryTest;
/** /**
* Transport resolver using the JSTUN library, to discover public IP and use it as a candidate. * Transport resolver using the JSTUN library, to discover public IP and use it as a candidate.
* *
@ -45,6 +47,8 @@ import java.util.Enumeration;
*/ */
public class STUNResolver extends TransportResolver { public class STUNResolver extends TransportResolver {
private static final SmackLogger LOGGER = SmackLogger.getLogger(STUNResolver.class);
// The filename where the STUN servers are stored. // The filename where the STUN servers are stored.
public final static String STUNSERVERS_FILENAME = "META-INF/stun-config.xml"; public final static String STUNSERVERS_FILENAME = "META-INF/stun-config.xml";
@ -282,7 +286,7 @@ public class STUNResolver extends TransportResolver {
resolvedPublicIP, getFreePort()); resolvedPublicIP, getFreePort());
candidate.setLocalIp(resolvedLocalIP); candidate.setLocalIp(resolvedLocalIP);
System.out.println("RESOLVING : " + resolvedPublicIP + ":" + candidate.getPort()); LOGGER.debug("RESOLVING : " + resolvedPublicIP + ":" + candidate.getPort());
addCandidate(candidate); addCandidate(candidate);
@ -296,7 +300,7 @@ public class STUNResolver extends TransportResolver {
* @throws XMPPException * @throws XMPPException
*/ */
public void initialize() throws XMPPException { public void initialize() throws XMPPException {
System.out.println("Initialized"); LOGGER.debug("Initialized");
if (!isResolving()&&!isResolved()) { if (!isResolving()&&!isResolved()) {
// Get the best STUN server available // Get the best STUN server available
if (currentServer.isNull()) { if (currentServer.isNull()) {

View file

@ -59,6 +59,8 @@ import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import org.jivesoftware.smackx.jingle.SmackLogger;
/** /**
* A Simple and Experimental Bridge. * A Simple and Experimental Bridge.
* It Creates a TCP Socket That Connects to another TCP Socket Listener and forwards every packets received to an UDP Listener. * It Creates a TCP Socket That Connects to another TCP Socket Listener and forwards every packets received to an UDP Listener.
@ -66,6 +68,8 @@ import java.net.Socket;
*/ */
public class TcpUdpBridgeClient { public class TcpUdpBridgeClient {
private static final SmackLogger LOGGER = SmackLogger.getLogger(TcpUdpBridgeClient.class);
private String remoteTcpHost = null; private String remoteTcpHost = null;
private String remoteUdpHost = null; private String remoteUdpHost = null;
private int remoteTcpPort = -1; private int remoteTcpPort = -1;
@ -85,7 +89,7 @@ public class TcpUdpBridgeClient {
localTcpSocket = new Socket(remoteTcpHost, remoteTcpPort); localTcpSocket = new Socket(remoteTcpHost, remoteTcpPort);
localUdpSocket = new DatagramSocket(0); localUdpSocket = new DatagramSocket(0);
localUdpPort = localUdpSocket.getLocalPort(); localUdpPort = localUdpSocket.getLocalPort();
System.out.println("UDP: " + localUdpSocket.getLocalPort()); LOGGER.debug("UDP: " + localUdpSocket.getLocalPort());
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -110,11 +114,11 @@ public class TcpUdpBridgeClient {
localUdpSocket.receive(p); localUdpSocket.receive(p);
if (p.getLength() == 0) continue; if (p.getLength() == 0) continue;
System.out.println("UDP Client Received and Sending to TCP Server:"+new String(p.getData(),0,p.getLength(),"UTF-8")); LOGGER.debug("UDP Client Received and Sending to TCP Server:"+new String(p.getData(),0,p.getLength(),"UTF-8"));
out.write(p.getData(), 0, p.getLength()); out.write(p.getData(), 0, p.getLength());
out.flush(); out.flush();
System.out.println("Client Flush"); LOGGER.debug("Client Flush");
} }
@ -141,7 +145,7 @@ public class TcpUdpBridgeClient {
int s = in.read(b); int s = in.read(b);
//if (s == -1) continue; //if (s == -1) continue;
System.out.println("TCP Client:" +new String(b,0,s,"UTF-8")); LOGGER.debug("TCP Client:" +new String(b,0,s,"UTF-8"));
DatagramPacket udpPacket = new DatagramPacket(b, s); DatagramPacket udpPacket = new DatagramPacket(b, s);

View file

@ -1,9 +1,15 @@
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import java.net.*;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import org.jivesoftware.smackx.jingle.SmackLogger;
/** /**
* A Simple and Experimental Bridge. * A Simple and Experimental Bridge.
@ -12,6 +18,8 @@ import java.io.OutputStream;
*/ */
public class TcpUdpBridgeServer { public class TcpUdpBridgeServer {
private static final SmackLogger LOGGER = SmackLogger.getLogger(TcpUdpBridgeServer.class);
private String remoteTcpHost = null; private String remoteTcpHost = null;
private String remoteUdpHost = null; private String remoteUdpHost = null;
private int remoteTcpPort = -1; private int remoteTcpPort = -1;
@ -32,7 +40,7 @@ public class TcpUdpBridgeServer {
serverTcpSocket = new ServerSocket(remoteTcpPort); serverTcpSocket = new ServerSocket(remoteTcpPort);
localUdpSocket = new DatagramSocket(0); localUdpSocket = new DatagramSocket(0);
localUdpPort = localUdpSocket.getLocalPort(); localUdpPort = localUdpSocket.getLocalPort();
System.out.println("UDP: " + localUdpSocket.getLocalPort()); LOGGER.debug("UDP: " + localUdpSocket.getLocalPort());
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -56,11 +64,11 @@ public class TcpUdpBridgeServer {
localUdpSocket.receive(p); localUdpSocket.receive(p);
if (p.getLength() == 0) continue; if (p.getLength() == 0) continue;
System.out.println("UDP Server Received and Sending to TCP Client:" + new String(p.getData(), 0, p.getLength(), "UTF-8")); LOGGER.debug("UDP Server Received and Sending to TCP Client:" + new String(p.getData(), 0, p.getLength(), "UTF-8"));
out.write(p.getData(), 0, p.getLength()); out.write(p.getData(), 0, p.getLength());
out.flush(); out.flush();
System.out.println("Server Flush"); LOGGER.debug("Server Flush");
} }
} }
@ -87,7 +95,7 @@ public class TcpUdpBridgeServer {
int s = in.read(b); int s = in.read(b);
//if (s == -1) continue; //if (s == -1) continue;
System.out.println("TCP Server:" + new String(b, 0, s, "UTF-8")); LOGGER.debug("TCP Server:" + new String(b, 0, s, "UTF-8"));
DatagramPacket udpPacket = new DatagramPacket(b, s); DatagramPacket udpPacket = new DatagramPacket(b, s);

View file

@ -52,16 +52,21 @@
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.jingle.JingleSession;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.*; import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
/** /**
* Transport candidate. * Transport candidate.
* <p/> * <p/>
@ -73,6 +78,8 @@ import java.util.List;
*/ */
public abstract class TransportCandidate { public abstract class TransportCandidate {
private static final SmackLogger LOGGER = SmackLogger.getLogger(TransportCandidate.class);
private String name; private String name;
private String ip; // IP address private String ip; // IP address
@ -680,14 +687,14 @@ public abstract class TransportCandidate {
public void run() { public void run() {
try { try {
System.out.println("Listening for ECHO: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort()); LOGGER.debug("Listening for ECHO: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort());
while (true) { while (true) {
DatagramPacket packet = new DatagramPacket(new byte[150], 150); DatagramPacket packet = new DatagramPacket(new byte[150], 150);
socket.receive(packet); socket.receive(packet);
//System.out.println("ECHO Packet Received in: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + " From: " + packet.getAddress().getHostAddress() + ":" + packet.getPort()); //LOGGER.debug("ECHO Packet Received in: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + " From: " + packet.getAddress().getHostAddress() + ":" + packet.getPort());
boolean accept = false; boolean accept = false;
@ -766,7 +773,7 @@ public abstract class TransportCandidate {
resultListener.testFinished(testResult, candidate); resultListener.testFinished(testResult, candidate);
} }
public void testASync(final TransportCandidate candidate, final String password) { public void testASync(final TransportCandidate transportCandidate, final String password) {
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@ -776,19 +783,21 @@ public abstract class TransportCandidate {
public boolean datagramReceived(DatagramPacket datagramPacket) { public boolean datagramReceived(DatagramPacket datagramPacket) {
try { try {
System.out.println("Content Received: " + new String(datagramPacket.getData(), "UTF-8")); LOGGER.debug("ECHO Received to: " + candidate.getIp() + ":" + candidate.getPort() + " data: " + new String(datagramPacket.getData(), "UTF-8"));
String str[] = new String(datagramPacket.getData(), "UTF-8").split(";"); String str[] = new String(datagramPacket.getData(), "UTF-8").split(";");
String pass = str[0]; String pass = str[0];
String addr[] = str[1].split(":"); String addr[] = str[1].split(":");
String ip = addr[0]; String ip = addr[0];
String pt = addr[1]; String pt = addr[1];
if (pass.equals(password) && candidate.getIp().indexOf(ip) != -1 && candidate.getPort() == Integer.parseInt(pt)) { if (pass.equals(password)
System.out.println("Result OK:" + candidate.getIp() + ":" + candidate.getPort()); && transportCandidate.getIp().indexOf(ip) != -1
&& transportCandidate.getPort() == Integer.parseInt(pt)) {
LOGGER.debug("ECHO OK: " + candidate.getIp() + ":" + candidate.getPort() + " <-> " + transportCandidate.getIp() + ":" + transportCandidate.getPort());
TestResult testResult = new TestResult(); TestResult testResult = new TestResult();
testResult.setResult(true); testResult.setResult(true);
ended = true; ended = true;
fireTestResult(testResult, candidate); fireTestResult(testResult, transportCandidate);
return true; return true;
} }
@ -797,7 +806,7 @@ public abstract class TransportCandidate {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("Result Wrong Data:" + datagramPacket.getAddress().getHostAddress() + ":" + datagramPacket.getPort()); LOGGER.debug("ECHO Wrong Data: " + datagramPacket.getAddress().getHostAddress() + ":" + datagramPacket.getPort());
return false; return false;
} }
}; };
@ -815,12 +824,12 @@ public abstract class TransportCandidate {
DatagramPacket packet = new DatagramPacket(content, content.length); DatagramPacket packet = new DatagramPacket(content, content.length);
try { try {
packet.setAddress(InetAddress.getByName(candidate.getIp())); packet.setAddress(InetAddress.getByName(transportCandidate.getIp()));
} }
catch (UnknownHostException e) { catch (UnknownHostException e) {
e.printStackTrace(); e.printStackTrace();
} }
packet.setPort(candidate.getPort()); packet.setPort(transportCandidate.getPort());
long delay = 200; long delay = 200;

View file

@ -20,9 +20,20 @@
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.*; import org.jivesoftware.smackx.jingle.ContentNegotiator;
import org.jivesoftware.smackx.jingle.JingleActionEnum;
import org.jivesoftware.smackx.jingle.JingleException;
import org.jivesoftware.smackx.jingle.JingleNegotiator;
import org.jivesoftware.smackx.jingle.JingleNegotiatorState;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.listeners.JingleListener; import org.jivesoftware.smackx.jingle.listeners.JingleListener;
import org.jivesoftware.smackx.jingle.listeners.JingleTransportListener; import org.jivesoftware.smackx.jingle.listeners.JingleTransportListener;
import org.jivesoftware.smackx.packet.Jingle; import org.jivesoftware.smackx.packet.Jingle;
@ -30,11 +41,6 @@ import org.jivesoftware.smackx.packet.JingleContent;
import org.jivesoftware.smackx.packet.JingleTransport; import org.jivesoftware.smackx.packet.JingleTransport;
import org.jivesoftware.smackx.packet.JingleTransport.JingleTransportCandidate; import org.jivesoftware.smackx.packet.JingleTransport.JingleTransportCandidate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/** /**
* Transport negotiator. * Transport negotiator.
* <p/> * <p/>
@ -46,6 +52,8 @@ import java.util.List;
*/ */
public abstract class TransportNegotiator extends JingleNegotiator { public abstract class TransportNegotiator extends JingleNegotiator {
private static final SmackLogger LOGGER = SmackLogger.getLogger(TransportNegotiator.class);
// The time we give to the candidates check before we accept or decline the // The time we give to the candidates check before we accept or decline the
// transport (in milliseconds) // transport (in milliseconds)
public final static int CANDIDATES_ACCEPT_PERIOD = 4000; public final static int CANDIDATES_ACCEPT_PERIOD = 4000;
@ -134,7 +142,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
return; return;
} }
} }
//System.out.println("BEST: " + bestLocalCandidate.getIp()); //LOGGER.debug("BEST: " + bestLocalCandidate.getIp());
throw new XMPPException("Local transport candidate has not be offered."); throw new XMPPException("Local transport candidate has not be offered.");
} }
@ -434,7 +442,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
// Add the candidate to the list // Add the candidate to the list
if (remoteCandidate != null) { if (remoteCandidate != null) {
synchronized (validRemoteCandidates) { synchronized (validRemoteCandidates) {
System.out.println("ADDED Valid Cand: " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort()); LOGGER.debug("Added valid candidate: " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort());
validRemoteCandidates.add(remoteCandidate); validRemoteCandidates.add(remoteCandidate);
} }
} }
@ -562,7 +570,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
if (!(resolver.isResolving() || resolver.isResolved())) { if (!(resolver.isResolving() || resolver.isResolved())) {
// Resolve our IP and port // Resolve our IP and port
System.out.println("RESOLVER CALLED"); LOGGER.debug("RESOLVER CALLED");
resolver.resolve(session); resolver.resolve(session);
} }
} }
@ -727,14 +735,14 @@ public abstract class TransportNegotiator extends JingleNegotiator {
if (!accepted.isEmpty()) { if (!accepted.isEmpty()) {
for (TransportCandidate cand : accepted) { for (TransportCandidate cand : accepted) {
System.out.println("Cand: " + cand.getIp()); LOGGER.debug("Remote acccepted candidate addr: " + cand.getIp());
} }
TransportCandidate cand = (TransportCandidate) accepted.get(0); TransportCandidate cand = (TransportCandidate) accepted.get(0);
setAcceptedLocalCandidate(cand); setAcceptedLocalCandidate(cand);
if (isEstablished()) { if (isEstablished()) {
System.out.println("SET ACTIVE"); LOGGER.debug(cand.getIp() + " is set active");
//setNegotiatorState(JingleNegotiatorState.SUCCEEDED); //setNegotiatorState(JingleNegotiatorState.SUCCEEDED);
} }
} }
@ -748,7 +756,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
private IQ receiveSessionAcceptAction(Jingle jingle) { private IQ receiveSessionAcceptAction(Jingle jingle) {
IQ response = null; IQ response = null;
System.out.println("Transport stabilished"); LOGGER.debug("Transport stabilished");
//triggerTransportEstablished(getAcceptedLocalCandidate(), getBestRemoteCandidate()); //triggerTransportEstablished(getAcceptedLocalCandidate(), getBestRemoteCandidate());
//setNegotiatorState(JingleNegotiatorState.SUCCEEDED); //setNegotiatorState(JingleNegotiatorState.SUCCEEDED);
@ -767,7 +775,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
for (JingleListener li : listeners) { for (JingleListener li : listeners) {
if (li instanceof JingleTransportListener) { if (li instanceof JingleTransportListener) {
JingleTransportListener mli = (JingleTransportListener) li; JingleTransportListener mli = (JingleTransportListener) li;
System.out.println("triggerTransportEstablished " + local.getLocalIp() + ":" + local.getPort() + "|" LOGGER.debug("triggerTransportEstablished " + local.getLocalIp() + ":" + local.getPort() + " <-> "
+ remote.getIp() + ":" + remote.getPort()); + remote.getIp() + ":" + remote.getPort());
mli.transportEstablished(local, remote); mli.transportEstablished(local, remote);
} }
@ -827,10 +835,10 @@ public abstract class TransportNegotiator extends JingleNegotiator {
// Hopefully, we only have one validRemoteCandidate // Hopefully, we only have one validRemoteCandidate
ArrayList cands = getValidRemoteCandidatesList(); ArrayList cands = getValidRemoteCandidatesList();
if (!cands.isEmpty()) { if (!cands.isEmpty()) {
System.out.println("RAW CAND"); LOGGER.debug("RAW CAND");
return (TransportCandidate) cands.get(0); return (TransportCandidate) cands.get(0);
} else { } else {
System.out.println("No Remote Candidate"); LOGGER.debug("No Remote Candidate");
return null; return null;
} }
} }
@ -893,7 +901,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
} }
if (result != null && result.getType().equals("relay")) if (result != null && result.getType().equals("relay"))
System.out.println("Relay Type"); LOGGER.debug("Relay Type");
return result; return result;
} }

View file

@ -52,9 +52,6 @@
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.util.ArrayList; import java.util.ArrayList;
@ -62,6 +59,10 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
/** /**
* A TransportResolver is used for obtaining a list of valid transport * A TransportResolver is used for obtaining a list of valid transport
* candidates. A transport candidate is composed by an IP address and a port number. * candidates. A transport candidate is composed by an IP address and a port number.
@ -72,6 +73,8 @@ import java.util.List;
*/ */
public abstract class TransportResolver { public abstract class TransportResolver {
private static final SmackLogger LOGGER = SmackLogger.getLogger(TransportResolver.class);
public enum Type { public enum Type {
rawupd, ice rawupd, ice
@ -247,7 +250,7 @@ public abstract class TransportResolver {
TransportResolverListener trl = (TransportResolverListener) iter.next(); TransportResolverListener trl = (TransportResolverListener) iter.next();
if (trl instanceof TransportResolverListener.Resolver) { if (trl instanceof TransportResolverListener.Resolver) {
TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl; TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl;
System.out.println("triggerCandidateAdded : " + cand.getLocalIp()); LOGGER.debug("triggerCandidateAdded : " + cand.getLocalIp());
li.candidateAdded(cand); li.candidateAdded(cand);
} }
} }
@ -331,7 +334,7 @@ public abstract class TransportResolver {
Collections.sort(cands); Collections.sort(cands);
// Return the last candidate // Return the last candidate
result = (TransportCandidate) cands.get(cands.size() - 1); result = (TransportCandidate) cands.get(cands.size() - 1);
System.out.println("Result: " + result.getIp()); LOGGER.debug("Result: " + result.getIp());
} }
return result; return result;
@ -383,12 +386,12 @@ public abstract class TransportResolver {
public void initializeAndWait() throws XMPPException { public void initializeAndWait() throws XMPPException {
this.initialize(); this.initialize();
try { try {
System.out.print("Initializing..."); LOGGER.debug("Initializing transport resolver...");
while (!this.isInitialized()) { while (!this.isInitialized()) {
System.out.print("."); LOGGER.debug("Resolver init still pending");
Thread.sleep(1000); Thread.sleep(1000);
} }
System.out.print("Resolved\n"); LOGGER.debug("Transport resolved\n");
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -44,7 +44,7 @@ public class Jingle extends IQ {
// static // static
public static final String NAMESPACE = "http://www.xmpp.org/extensions/xep-0166.html#ns"; public static final String NAMESPACE = "urn:xmpp:tmp:jingle";
public static final String NODENAME = "jingle"; public static final String NODENAME = "jingle";
@ -190,8 +190,6 @@ public class Jingle extends IQ {
/** /**
* Returns the XML namespace of the extension sub-packet root element. * Returns the XML namespace of the extension sub-packet root element.
* According the specification the namespace is always
* "http://www.xmpp.org/extensions/xep-0166.html#ns"
* *
* @return the XML namespace of the packet extension. * @return the XML namespace of the packet extension.
*/ */

View file

@ -172,7 +172,7 @@ public abstract class JingleContentDescription implements PacketExtension {
*/ */
public static class Audio extends JingleContentDescription { public static class Audio extends JingleContentDescription {
public static final String NAMESPACE = "http://jabber.org/protocol/jingle/description/audio"; public static final String NAMESPACE = "urn:xmpp:tmp:jingle:apps:rtp";
public Audio() { public Audio() {
super(); super();

View file

@ -96,7 +96,7 @@ public class JingleContentInfo implements PacketExtension {
*/ */
public static class Audio extends JingleContentInfo { public static class Audio extends JingleContentInfo {
public static final String NAMESPACE = "http://www.xmpp.org/extensions/xep-0167.html#ns-info"; public static final String NAMESPACE = "urn:xmpp:tmp:jingle:apps:rtp";
public Audio(final ContentInfo mi) { public Audio(final ContentInfo mi) {
super(mi); super(mi);

View file

@ -19,14 +19,15 @@
*/ */
package org.jivesoftware.smackx.packet; package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.jingle.SmackLogger;
import org.jivesoftware.smackx.jingle.media.PayloadType;
/** /**
* Jingle content description. * Jingle content description.
* *
@ -34,6 +35,8 @@ import java.util.List;
*/ */
public abstract class JingleDescription implements PacketExtension { public abstract class JingleDescription implements PacketExtension {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleDescription.class);
// static // static
public static final String NODENAME = "description"; public static final String NODENAME = "description";
@ -73,7 +76,7 @@ public abstract class JingleDescription implements PacketExtension {
public void addPayloadType(final PayloadType pt) { public void addPayloadType(final PayloadType pt) {
synchronized (payloads) { synchronized (payloads) {
if (pt == null) { if (pt == null) {
System.err.println("Null payload type"); LOGGER.error("Null payload type");
} else { } else {
payloads.add(pt); payloads.add(pt);
} }
@ -176,7 +179,7 @@ public abstract class JingleDescription implements PacketExtension {
*/ */
public static class Audio extends JingleDescription { public static class Audio extends JingleDescription {
public static final String NAMESPACE = "http://www.xmpp.org/extensions/xep-0167.html#ns"; public static final String NAMESPACE = "urn:xmpp:tmp:jingle:apps:rtp";
public Audio() { public Audio() {
super(); super();

View file

@ -27,7 +27,7 @@ import org.xmlpull.v1.XmlPullParser;
public class JingleError implements PacketExtension { public class JingleError implements PacketExtension {
public static String NAMESPACE = "http://www.xmpp.org/extensions/xep-0166.html#ns-errors"; public static String NAMESPACE = "urn:xmpp:tmp:jingle:errors";
public static final JingleError OUT_OF_ORDER = new JingleError("out-of-order"); public static final JingleError OUT_OF_ORDER = new JingleError("out-of-order");

View file

@ -270,7 +270,7 @@ public class JingleTransport implements PacketExtension {
* RTP-ICE profile * RTP-ICE profile
*/ */
public static class Ice extends JingleTransport { public static class Ice extends JingleTransport {
public static final String NAMESPACE = "http://www.xmpp.org/extensions/xep-0176.html#ns-udp"; public static final String NAMESPACE = "urn:xmpp:tmp:jingle:transports:ice-udp";
public Ice() { public Ice() {
super(); super();

View file

@ -234,7 +234,7 @@ public abstract class JingleTransportProvider implements PacketExtensionProvider
String name = parser.getAttributeValue("", "name"); String name = parser.getAttributeValue("", "name");
String port = parser.getAttributeValue("", "port"); String port = parser.getAttributeValue("", "port");
//System.out.println(); //LOGGER.debug();
if (generation != null) { if (generation != null) {
try { try {

View file

@ -14,8 +14,11 @@ import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.media.PayloadType; import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager; import org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List; import java.util.List;
/** /**
@ -129,10 +132,28 @@ public class STUNResolverTest extends SmackTestCase {
cc.prioritizeCandidates(); cc.prioritizeCandidates();
// get SortedCandidates // get SortedCandidates
for (Candidate candidate : cc.getSortedCandidates()) for (Candidate candidate : cc.getSortedCandidates()) {
short nicNum = 0;
try {
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
short tempNic = 0;
NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
while(nics.hasMoreElements()) {
NetworkInterface checkNIC = nics.nextElement();
if (checkNIC.equals(nic)) {
nicNum = tempNic;
break;
}
i++;
}
} catch (SocketException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try { try {
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress() TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress()
.getHostAddress(), 1, candidate.getNetwork(), "1", candidate.getPort(), "1", candidate.getPriority(), .getHostAddress(), 1, nicNum, "1", candidate.getPort(), "1", candidate.getPriority(),
ICECandidate.Type.prflx); ICECandidate.Type.prflx);
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress()); transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|" System.out.println("C: " + candidate.getAddress().getInetAddress() + "|"
@ -142,6 +163,7 @@ public class STUNResolverTest extends SmackTestCase {
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
e.printStackTrace(); e.printStackTrace();
} }
}
Candidate candidate = cc.getSortedCandidates().get(0); Candidate candidate = cc.getSortedCandidates().get(0);
String temp = "C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() String temp = "C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress()
+ " p:" + candidate.getPriority(); + " p:" + candidate.getPriority();

View file

@ -36,11 +36,11 @@ public class JingleProviderTest extends SmackTestCase {
// Create a dummy packet for testing... // Create a dummy packet for testing...
IQfake iqSent = new IQfake ( IQfake iqSent = new IQfake (
" <jingle xmlns='http://jabber.org/protocol/jingle'" + " <jingle xmlns='urn:xmpp:tmp:jingle'" +
" initiator=\"gorrino@viejo.com\"" + " initiator=\"gorrino@viejo.com\"" +
" responder=\"colico@hepatico.com\"" + " responder=\"colico@hepatico.com\"" +
" action=\"transport-info\" sid=\"\">" + " action=\"transport-info\" sid=\"\">" +
" <transport xmlns='http://jabber.org/protocol/jingle/transport/ice'>" + " <transport xmlns='urn:xmpp:tmp:jingle:transports:ice-udp'>" +
" <candidate generation=\"1\"" + " <candidate generation=\"1\"" +
" ip=\"192.168.1.1\"" + " ip=\"192.168.1.1\"" +
" password=\"secret\"" + " password=\"secret\"" +