diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/jmf/AudioChannel.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/jmf/AudioChannel.java index fcca87b37..b309d7d75 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/jmf/AudioChannel.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/jmf/AudioChannel.java @@ -122,8 +122,6 @@ public class AudioChannel { started = false; } - started = true; - // Create an RTP session to transmit the output of the // processor to the specified IP address and port no. result = createTransmitter(); @@ -132,6 +130,9 @@ public class AudioChannel { processor = null; started = false; } + else { + started = true; + } // Start the transmission processor.start(); @@ -203,15 +204,17 @@ public class AudioChannel { // Wait for it to configure boolean result = waitForState(processor, Processor.Configured); - if (!result) + if (!result){ return "Couldn't configure processor"; - + } + // Get the tracks from the processor TrackControl[] tracks = processor.getTrackControls(); // Do we have atleast one track? - if (tracks == null || tracks.length < 1) + if (tracks == null || tracks.length < 1){ return "Couldn't find tracks in processor"; + } // Set the output content descriptor to RAW_RTP // This will limit the supported formats reported from diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java index 526be6ca4..dd3d2d9fa 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java @@ -24,18 +24,18 @@ import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smackx.jingle.JingleSession; import java.util.Random; -import java.net.InetAddress; -import java.net.UnknownHostException; +import java.util.Enumeration; +import java.net.*; /** * Bridged Resolver use a RTPBridge Service to add a relayed candidate. * A very reliable solution for NAT Traversal. - * + *

* The resolver verify is the XMPP Server that the client is connected offer this service. * If the server supports, a candidate is requested from the service. * The resolver adds this candidate */ -public class BridgedResolver extends TransportResolver{ +public class BridgedResolver extends TransportResolver { XMPPConnection connection; @@ -67,21 +67,7 @@ public class BridgedResolver extends TransportResolver{ RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid)); - - String localIp="127.0.0.1"; - try { - localIp = InetAddress.getLocalHost().getHostAddress(); - - InetAddress iaddress = InetAddress.getLocalHost(); - - System.out.println(iaddress.isLoopbackAddress()); - System.out.println(iaddress.isLinkLocalAddress()); - System.out.println(iaddress.isSiteLocalAddress()); - - } - catch (UnknownHostException e) { - e.printStackTrace(); - } + String localIp = getLocalHost(); TransportCandidate localCandidate = new TransportCandidate.Fixed( rtpBridge.getIp(), rtpBridge.getPortA()); @@ -124,4 +110,38 @@ public class BridgedResolver extends TransportResolver{ // Nothing to do here } + public static String getLocalHost() { + Enumeration ifaces = null; + + try { + ifaces = NetworkInterface.getNetworkInterfaces(); + } + catch (SocketException e) { + e.printStackTrace(); + } + + while (ifaces.hasMoreElements()) { + + NetworkInterface iface = (NetworkInterface) ifaces.nextElement(); + Enumeration iaddresses = iface.getInetAddresses(); + + while (iaddresses.hasMoreElements()) { + InetAddress iaddress = (InetAddress) iaddresses.nextElement(); + if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress() && !iaddress.isSiteLocalAddress() && !(iaddress instanceof Inet6Address)) { + return iaddress.getHostAddress(); + } + } + } + + try { + return InetAddress.getLocalHost().getHostAddress(); + } + catch (Exception e) { + e.printStackTrace(); + } + + return "127.0.0.1"; + + } + } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java index c1169fc43..593969dc1 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java @@ -138,7 +138,7 @@ public class ICEResolver extends TransportResolver { network = iceNegociator.getPublicCandidate().getNetwork(); } else { - localIp = InetAddress.getLocalHost().getHostAddress(); + localIp = BridgedResolver.getLocalHost(); network = 0; } diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/LocalhostTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/LocalhostTest.java new file mode 100644 index 000000000..7aaedaa94 --- /dev/null +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/LocalhostTest.java @@ -0,0 +1,17 @@ +package org.jivesoftware.smackx.jingle.nat; + +import junit.framework.TestCase; + +import java.util.Enumeration; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.InetAddress; +import java.net.DatagramSocket; + +public class LocalhostTest extends TestCase { + + public void testGetLocalhost() { + System.out.println(BridgedResolver.getLocalHost()); + } + +}