From 9ea6a38249f5b66476116165bbc132e3811239f9 Mon Sep 17 00:00:00 2001 From: Thiago Camargo Date: Sat, 10 Mar 2007 18:07:04 +0000 Subject: [PATCH] Candidates Added after session Establishment fixed git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7449 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/jingle/JingleSession.java | 3 +- .../jingle/nat/TransportNegotiator.java | 3 +- .../smackx/jingle/JingleManagerTest.java | 143 +++--- .../smackx/jingle/JingleMediaTest.java | 445 ++++++++++++++++++ 4 files changed, 519 insertions(+), 75 deletions(-) create mode 100644 jingle/extension/test/org/jivesoftware/smackx/jingle/JingleMediaTest.java diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java index 2fa62637f..a64d07011 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java @@ -1122,6 +1122,7 @@ public abstract class JingleSession extends JingleNegotiator { */ public void terminate() throws XMPPException { if (isClosed()) return; + //remo System.out.println("State: " + this.getState()); Jingle result = null; Jingle jout = new Jingle(Jingle.Action.SESSIONTERMINATE); @@ -1138,7 +1139,7 @@ public abstract class JingleSession extends JingleNegotiator { destroyMediaNeg(); destroyTransportNeg(); removePacketListener(); - System.out.println("Negociation Closed: " + getConnection().getUser()); + System.out.println("Negotiation Closed: " + getConnection().getUser() + " " + sid); closed = true; super.close(); } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java index c5de30efd..688c0d9fa 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java @@ -231,7 +231,8 @@ public abstract class TransportNegotiator extends JingleNegotiator { public void candidateChecked(TransportCandidate cand, final boolean validCandidate) { if (validCandidate) { - addValidRemoteCandidate(offeredCandidate); + if (!(getState() instanceof Active)) + addValidRemoteCandidate(offeredCandidate); } } diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java index 02d7c7f95..da6a8ebd6 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java @@ -671,15 +671,11 @@ public class JingleManagerTest extends SmackTestCase { catch (Exception e) { e.printStackTrace(); } - finally { - } } catch (Exception e) { e.printStackTrace(); } - finally { - } } @@ -690,104 +686,105 @@ public class JingleManagerTest extends SmackTestCase { resetCounter(); - try { + XMPPConnection.DEBUG_ENABLED = true; - XMPPConnection.DEBUG_ENABLED = true; + XMPPConnection x0 = getConnection(0); + XMPPConnection x1 = getConnection(1); - XMPPConnection x0 = getConnection(0); - XMPPConnection x1 = getConnection(1); + final JingleManager jm0 = new JingleManager( + x0, new FixedResolver("127.0.0.1", 20080)); - final JingleManager jm0 = new JingleManager( - x0, new STUNResolver() { - }); - final JingleManager jm1 = new JingleManager( - x1, new FixedResolver("127.0.0.1", 20040)); + final JingleManager jm1 = new JingleManager( + x1, new FixedResolver("127.0.0.1", 20040)); // JingleManager jm0 = new JingleSessionManager( // x0, new ICEResolver()); // JingleManager jm1 = new JingleSessionManager( // x1, new ICEResolver()); - JingleMediaManager jingleMediaManager = new JmfMediaManager(); + JingleMediaManager jingleMediaManager = new JmfMediaManager(); - jm0.setMediaManager(jingleMediaManager); - jm1.setMediaManager(jingleMediaManager); + jm0.setMediaManager(jingleMediaManager); + jm1.setMediaManager(jingleMediaManager); - jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() { - public void sessionRequested(final JingleSessionRequest request) { + jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() { + public void sessionRequested(final JingleSessionRequest request) { - try { + try { - IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); - session.addListener(new JingleSessionListener() { + IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); + session.addListener(new JingleSessionListener() { - public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) { - incCounter(); - System.out.println("Establish In"); - } + public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) { + incCounter(); + System.out.println("Establish In"); + } - public void sessionDeclined(String reason, JingleSession jingleSession) { - } + public void sessionDeclined(String reason, JingleSession jingleSession) { + } - public void sessionRedirected(String redirection, JingleSession jingleSession) { - } + public void sessionRedirected(String redirection, JingleSession jingleSession) { + } - public void sessionClosed(String reason, JingleSession jingleSession) { - } + public void sessionClosed(String reason, JingleSession jingleSession) { + // incCounter(); + } - public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) { - } - }); + public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) { + // incCounter(); + } + }); - session.start(); - } - catch (XMPPException e) { - e.printStackTrace(); + session.start(); + } + catch (XMPPException e) { + e.printStackTrace(); + } + + } + }); + + for (int i = 0; i < 3; i++) + try { + + OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); + + js0.addListener(new JingleSessionListener() { + + public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) { + incCounter(); + System.out.println("Establish Out"); } - } - }); + public void sessionDeclined(String reason, JingleSession jingleSession) { + } - OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); + public void sessionRedirected(String redirection, JingleSession jingleSession) { + } - js0.addListener(new JingleSessionListener() { + public void sessionClosed(String reason, JingleSession jingleSession) { + // incCounter(); + } - public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. - incCounter(); - System.out.println("Establish Out"); - } + public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) { + // incCounter(); + } + }); - public void sessionDeclined(String reason, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. - } + js0.start(); - public void sessionRedirected(String redirection, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. - } + Thread.sleep(8000); + js0.terminate(); - public void sessionClosed(String reason, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. - } + Thread.sleep(3000); - public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. - } - }); - - js0.start(); - - Thread.sleep(12000); - js0.terminate(); - - assertTrue(valCounter() == 2); - //Thread.sleep(15000); - - } - catch (Exception e) { - e.printStackTrace(); - } + } + catch (Exception e) { + e.printStackTrace(); + } + System.out.println(valCounter()); + assertTrue(valCounter() == 6); } /** diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleMediaTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleMediaTest.java new file mode 100644 index 000000000..bf84d9e43 --- /dev/null +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleMediaTest.java @@ -0,0 +1,445 @@ +/** + * $RCSfile$ + * $Revision: $ + * $Date: 09/11/2006 + *

+ * Copyright 2003-2006 Jive Software. + *

+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.test.SmackTestCase; +import org.jivesoftware.smackx.jingle.IncomingJingleSession; +import org.jivesoftware.smackx.jingle.JingleManager; +import org.jivesoftware.smackx.jingle.JingleSessionRequest; +import org.jivesoftware.smackx.jingle.OutgoingJingleSession; +import org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager; +import org.jivesoftware.smackx.jingle.mediaimpl.jmf.AudioChannel; +import org.jivesoftware.smackx.jingle.mediaimpl.jspeex.SpeexMediaManager; +import org.jivesoftware.smackx.jingle.mediaimpl.multi.MultiMediaManager; +import org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener; +import org.jivesoftware.smackx.jingle.media.JingleMediaManager; +import org.jivesoftware.smackx.jingle.nat.BridgedTransportManager; +import org.jivesoftware.smackx.jingle.nat.ICETransportManager; +import org.jivesoftware.smackx.jingle.nat.STUNTransportManager; + +import javax.media.MediaLocator; +import javax.media.format.AudioFormat; +import java.net.InetAddress; + +/** + * Test the Jingle Media using the high level API + *

+ * + * @author Thiago Camargo + */ +public class JingleMediaTest extends SmackTestCase { + + public JingleMediaTest(final String name) { + super(name); + } + + public void testCompleteJmf() { + + XMPPConnection x0 = getConnection(0); + XMPPConnection x1 = getConnection(1); + + for(int i=0;i<3;i++) + try { + + ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478); + ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478); + + final JingleManager jm0 = new JingleManager( + x0, icetm0); + final JingleManager jm1 = new JingleManager( + x1, icetm1); + + jm0.addCreationListener(icetm0); + jm1.addCreationListener(icetm1); + + JingleMediaManager jingleMediaManager0 = new JmfMediaManager(); + JingleMediaManager jingleMediaManager1 = new JmfMediaManager(); + + jm0.setMediaManager(jingleMediaManager0); + jm1.setMediaManager(jingleMediaManager1); + + JingleSessionRequestListener jingleSessionRequestListener = new JingleSessionRequestListener() { + public void sessionRequested(final JingleSessionRequest request) { + + try { + IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); + session.start(request); + } + catch (XMPPException e) { + e.printStackTrace(); + } + + } + }; + + jm1.addJingleSessionRequestListener(jingleSessionRequestListener); + + OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); + + js0.start(); + + Thread.sleep(10000); + js0.terminate(); + + jm1.removeJingleSessionRequestListener(jingleSessionRequestListener); + + Thread.sleep(6000); + + } + catch (Exception e) { + e.printStackTrace(); + } + + } + + public void testCompleteMulti() { + + try { + + XMPPConnection x0 = getConnection(0); + XMPPConnection x1 = getConnection(1); + + + ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478); + ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478); + + final JingleManager jm0 = new JingleManager( + x0, icetm0); + final JingleManager jm1 = new JingleManager( + x1, icetm1); + + jm0.addCreationListener(icetm0); + jm1.addCreationListener(icetm1); +/* + + final JingleManager jm0 = new JingleManager( + x0, new BasicTransportManager()); + final JingleManager jm1 = new JingleManager( + x1, new BasicTransportManager()); + */ + MultiMediaManager jingleMediaManager0 = new MultiMediaManager(); + jingleMediaManager0.addMediaManager(new SpeexMediaManager()); + jingleMediaManager0.addMediaManager(new JmfMediaManager()); + MultiMediaManager jingleMediaManager1 = new MultiMediaManager(); + jingleMediaManager1.addMediaManager(new JmfMediaManager()); + jingleMediaManager1.addMediaManager(new SpeexMediaManager()); + + jm0.setMediaManager(jingleMediaManager0); + jm1.setMediaManager(jingleMediaManager1); + + jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() { + public void sessionRequested(final JingleSessionRequest request) { + + try { + IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); + session.start(request); + } + catch (XMPPException e) { + e.printStackTrace(); + } + + } + }); + + OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); + + js0.start(); + + Thread.sleep(60000); + js0.terminate(); + + Thread.sleep(6000); + + x0.disconnect(); + x1.disconnect(); + + } + catch (Exception e) { + e.printStackTrace(); + } + + } + + public void testCompleteSpeex() { + + try { + + //XMPPConnection.DEBUG_ENABLED = true; + + XMPPConnection x0 = getConnection(0); + XMPPConnection x1 = getConnection(1); + + final JingleManager jm0 = new JingleManager( + x0, new STUNTransportManager()); + final JingleManager jm1 = new JingleManager( + x1, new STUNTransportManager()); + + JingleMediaManager jingleMediaManager0 = new SpeexMediaManager(); + JingleMediaManager jingleMediaManager1 = new SpeexMediaManager(); + + jm0.setMediaManager(jingleMediaManager0); + jm1.setMediaManager(jingleMediaManager1); + + jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() { + public void sessionRequested(final JingleSessionRequest request) { + + try { + + IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); + + session.start(request); + } + catch (XMPPException e) { + e.printStackTrace(); + } + + } + }); + + OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); + + js0.start(); + + Thread.sleep(150000); + js0.terminate(); + + Thread.sleep(6000); + + x0.disconnect(); + x1.disconnect(); + + } + catch (Exception e) { + e.printStackTrace(); + } + + } + + public void testCompleteWithBridge() { + + for (int i = 0; i < 1; i += 2) { + final int n = i; + Thread t = new Thread(new Runnable() { + public void run() { + try { + + XMPPConnection x0 = getConnection(n); + XMPPConnection x1 = getConnection(n + 1); + + BridgedTransportManager btm0 = new BridgedTransportManager(x0); + BridgedTransportManager btm1 = new BridgedTransportManager(x1); + + final JingleManager jm0 = new JingleManager(x0, btm0); + final JingleManager jm1 = new JingleManager(x1, btm1); + + jm0.addCreationListener(btm0); + jm1.addCreationListener(btm1); + + JingleMediaManager jingleMediaManager = new JmfMediaManager(); + JingleMediaManager jingleMediaManager2 = new JmfMediaManager(); + + jm0.setMediaManager(jingleMediaManager); + jm1.setMediaManager(jingleMediaManager2); + + jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() { + public void sessionRequested(final JingleSessionRequest request) { + + try { + IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); + + session.start(request); + } + catch (XMPPException e) { + e.printStackTrace(); + } + + } + }); + + OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); + + js0.start(); + + Thread.sleep(55000); + + js0.terminate(); + + Thread.sleep(3000); + + x0.disconnect(); + x1.disconnect(); + + } + catch (Exception e) { + e.printStackTrace(); + } + } + }); + + t.start(); + } + + try { + Thread.sleep(250000); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void testCompleteWithBridgeB() { + try { + + //XMPPConnection.DEBUG_ENABLED = true; + + XMPPConnection x0 = getConnection(0); + XMPPConnection x1 = getConnection(1); + + BridgedTransportManager btm0 = new BridgedTransportManager(x0); + BridgedTransportManager btm1 = new BridgedTransportManager(x1); + + final JingleManager jm0 = new JingleManager(x0, btm0); + final JingleManager jm1 = new JingleManager(x1, btm1); + + jm0.addCreationListener(btm0); + jm1.addCreationListener(btm1); + + JingleMediaManager jingleMediaManager = new JmfMediaManager(); + + jm0.setMediaManager(jingleMediaManager); + jm1.setMediaManager(jingleMediaManager); + + jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() { + public void sessionRequested(final JingleSessionRequest request) { + + try { + + IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); + + session.start(request); + } + catch (XMPPException e) { + e.printStackTrace(); + } + + } + }); + + OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); + + js0.start(); + + Thread.sleep(20000); + + js0.terminate(); + + Thread.sleep(3000); + + js0 = jm0.createOutgoingJingleSession(x1.getUser()); + + js0.start(); + + Thread.sleep(20000); + + js0.terminate(); + + Thread.sleep(3000); + + x0.disconnect(); + x1.disconnect(); + + } + catch (Exception e) { + e.printStackTrace(); + } + + } + + public void testAudioChannelOpenClose() { + for (int i = 0; i < 5; i++) { + try { + AudioChannel audioChannel0 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost().getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7002, 7020, new AudioFormat(AudioFormat.GSM_RTP)); + AudioChannel audioChannel1 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost().getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7020, 7002, new AudioFormat(AudioFormat.GSM_RTP)); + + audioChannel0.start(); + audioChannel1.start(); + + try { + Thread.sleep(10000); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + + audioChannel0.stop(); + audioChannel1.stop(); + + try { + Thread.sleep(3000); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + + public void testAudioChannelStartStop() { + + try { + AudioChannel audioChannel0 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost().getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7002, 7020, new AudioFormat(AudioFormat.GSM_RTP)); + AudioChannel audioChannel1 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost().getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7020, 7002, new AudioFormat(AudioFormat.GSM_RTP)); + + for (int i = 0; i < 5; i++) { + + audioChannel0.start(); + audioChannel1.start(); + + try { + Thread.sleep(10000); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + + audioChannel0.stop(); + audioChannel1.stop(); + + try { + Thread.sleep(3000); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + + protected int getMaxConnections() { + return 2; + } +} \ No newline at end of file