Search in sources :

Example 1 with JingleSessionListener

use of org.jivesoftware.smackx.jingle.listeners.JingleSessionListener in project Smack by igniterealtime.

the class JingleManagerTest method testEqualPayloadsSetSession.

/**
     * This is a simple test where both endpoints have exactly the same payloads
     * and the session is accepted.
     */
public void testEqualPayloadsSetSession() {
    resetCounter();
    try {
        FixedResolver tr0 = new FixedResolver("127.0.0.1", 54213);
        FixedTransportManager ftm0 = new FixedTransportManager(tr0);
        TestMediaManager tmm0 = new TestMediaManager(ftm0);
        tmm0.setPayloads(getTestPayloads1());
        List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
        trl0.add(tmm0);
        FixedResolver tr1 = new FixedResolver("127.0.0.1", 54531);
        FixedTransportManager ftm1 = new FixedTransportManager(tr1);
        TestMediaManager tmm1 = new TestMediaManager(ftm1);
        tmm1.setPayloads(getTestPayloads1());
        List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
        trl1.add(tmm1);
        JingleManager man0 = new JingleManager(getConnection(0), trl0);
        JingleManager man1 = new JingleManager(getConnection(1), trl1);
        man0.addCreationListener(ftm0);
        man1.addCreationListener(ftm1);
        man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {

            /**
                 * Called when a new session request is detected
                 */
            public void sessionRequested(final JingleSessionRequest request) {
                System.out.println("Session request detected, from " + request.getFrom() + ": accepting.");
                try {
                    // We accept the request
                    JingleSession session1 = request.accept();
                    session1.addListener(new JingleSessionListener() {

                        public void sessionClosed(String reason, JingleSession jingleSession) {
                            System.out.println("sessionClosed().");
                        }

                        public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
                            System.out.println("sessionClosedOnError().");
                        }

                        public void sessionDeclined(String reason, JingleSession jingleSession) {
                            System.out.println("sessionDeclined().");
                        }

                        public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) {
                            incCounter();
                            System.out.println("Responder: the session is fully established.");
                            System.out.println("+ Payload Type: " + pt.getId());
                            System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
                            System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
                        }

                        public void sessionMediaReceived(JingleSession jingleSession, String participant) {
                        // Do Nothing
                        }

                        public void sessionRedirected(String redirection, JingleSession jingleSession) {
                        }
                    });
                    session1.startIncoming();
                } catch (Exception e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        });
        // Session 0 starts a request
        System.out.println("Starting session request with equal payloads, to " + getFullJID(1) + "...");
        JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
        session0.startOutgoing();
        Thread.sleep(20000);
        assertTrue(valCounter() == 1);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
        fail("An error occured with Jingle");
    }
}
Also used : FixedResolver(org.jivesoftware.smackx.jingle.nat.FixedResolver) FixedTransportManager(org.jivesoftware.smackx.jingle.nat.FixedTransportManager) ArrayList(java.util.ArrayList) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) PayloadType(org.jivesoftware.smackx.jingle.media.PayloadType) XMPPException(org.jivesoftware.smack.XMPPException) TestMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) TransportCandidate(org.jivesoftware.smackx.jingle.nat.TransportCandidate) XMPPException(org.jivesoftware.smack.XMPPException) JingleSessionListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)

Example 2 with JingleSessionListener

use of org.jivesoftware.smackx.jingle.listeners.JingleSessionListener in project Smack by igniterealtime.

the class STUNResolverTest method testSTUNJingleSession.

/**
     * This is a simple test where the user_2 rejects the Jingle session.
     */
public void testSTUNJingleSession() {
    resetCounter();
    try {
        TransportResolver tr1 = new STUNResolver() {
        };
        TransportResolver tr2 = new STUNResolver() {
        };
        // Explicit resolution
        tr1.resolve(null);
        tr2.resolve(null);
        STUNTransportManager stm0 = new STUNTransportManager();
        TestMediaManager tmm0 = new TestMediaManager(stm0);
        tmm0.setPayloads(getTestPayloads1());
        List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
        trl0.add(tmm0);
        STUNTransportManager stm1 = new STUNTransportManager();
        TestMediaManager tmm1 = new TestMediaManager(stm1);
        tmm1.setPayloads(getTestPayloads2());
        List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
        trl1.add(tmm1);
        final JingleManager man0 = new JingleManager(getConnection(0), trl0);
        final JingleManager man1 = new JingleManager(getConnection(1), trl1);
        man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {

            /**
                 * Called when a new session request is detected
                 */
            public void sessionRequested(final JingleSessionRequest request) {
                System.out.println("Session request detected, from " + request.getFrom() + ": accepting.");
                // We accept the request
                JingleSession session1;
                try {
                    session1 = request.accept();
                    session1.addListener(new JingleSessionListener() {

                        public void sessionClosed(String reason, JingleSession jingleSession) {
                        }

                        public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
                        }

                        public void sessionDeclined(String reason, JingleSession jingleSession) {
                        }

                        public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) {
                            incCounter();
                            System.out.println("Responder: the session is fully established.");
                            System.out.println("+ Payload Type: " + pt.getId());
                            System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
                            System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
                        }

                        public void sessionRedirected(String redirection, JingleSession jingleSession) {
                        }

                        public void sessionMediaReceived(JingleSession jingleSession, String participant) {
                        // Do Nothing
                        }
                    });
                    session1.startIncoming();
                } catch (XMPPException e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        });
        // Session 0 starts a request
        System.out.println("Starting session request, to " + getFullJID(1) + "...");
        JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
        session0.addListener(new JingleSessionListener() {

            public void sessionClosed(String reason, JingleSession jingleSession) {
            }

            public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
            }

            public void sessionDeclined(String reason, JingleSession jingleSession) {
            }

            public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) {
                incCounter();
                System.out.println("Initiator: the session is fully established.");
                System.out.println("+ Payload Type: " + pt.getId());
                System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
                System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
            }

            public void sessionMediaReceived(JingleSession jingleSession, String participant) {
            // Do Nothing
            }

            public void sessionRedirected(String redirection, JingleSession jingleSession) {
            }
        });
        session0.startOutgoing();
        Thread.sleep(60000);
        assertTrue(valCounter() == 2);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
        fail("An error occured with Jingle");
    }
}
Also used : ArrayList(java.util.ArrayList) JingleSessionRequest(org.jivesoftware.smackx.jingle.JingleSessionRequest) JingleSession(org.jivesoftware.smackx.jingle.JingleSession) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) PayloadType(org.jivesoftware.smackx.jingle.media.PayloadType) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException) UtilityException(de.javawi.jstun.util.UtilityException) XMPPException(org.jivesoftware.smack.XMPPException) TestMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) JingleManager(org.jivesoftware.smackx.jingle.JingleManager) XMPPException(org.jivesoftware.smack.XMPPException) JingleSessionListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)

Example 3 with JingleSessionListener

use of org.jivesoftware.smackx.jingle.listeners.JingleSessionListener in project Smack by igniterealtime.

the class JingleManagerTest method testRejectSession.

/**
     * This is a simple test where the user_2 rejects the Jingle session.
     */
public void testRejectSession() {
    resetCounter();
    try {
        FixedResolver tr0 = new FixedResolver("127.0.0.1", 22222);
        FixedTransportManager ftm0 = new FixedTransportManager(tr0);
        TestMediaManager tmm0 = new TestMediaManager(ftm0);
        tmm0.setPayloads(getTestPayloads1());
        List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
        trl0.add(tmm0);
        FixedResolver tr1 = new FixedResolver("127.0.0.1", 22444);
        FixedTransportManager ftm1 = new FixedTransportManager(tr1);
        TestMediaManager tmm1 = new TestMediaManager(ftm1);
        tmm1.setPayloads(getTestPayloads1());
        List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
        trl1.add(tmm1);
        JingleManager man0 = new JingleManager(getConnection(0), trl0);
        JingleManager man1 = new JingleManager(getConnection(1), trl1);
        man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {

            /**
                 * Called when a new session request is detected
                 */
            public void sessionRequested(final JingleSessionRequest request) {
                System.out.println("Session request detected, from " + request.getFrom());
                // We reject the request
                try {
                    JingleSession session = request.accept();
                    //session.setInitialSessionRequest(request);
                    session.startIncoming();
                    session.terminate();
                } catch (XMPPException e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        });
        // Session 0 starts a request
        System.out.println("Starting session request, to " + getFullJID(1) + "...");
        JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
        session0.addListener(new JingleSessionListener() {

            public void sessionClosed(String reason, JingleSession jingleSession) {
                incCounter();
                System.out.println("The session has been closed");
            }

            public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
            }

            public void sessionDeclined(String reason, JingleSession jingleSession) {
                System.out.println("The session has been detected as rejected with reason: " + reason);
            }

            public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) {
            }

            public void sessionMediaReceived(JingleSession jingleSession, String participant) {
            // Do Nothing
            }

            public void sessionRedirected(String redirection, JingleSession jingleSession) {
            }
        });
        session0.startOutgoing();
        Thread.sleep(50000);
        //session0.terminate();
        Thread.sleep(10000);
        assertTrue(valCounter() > 0);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
        fail("An error occured with Jingle");
    }
}
Also used : FixedResolver(org.jivesoftware.smackx.jingle.nat.FixedResolver) FixedTransportManager(org.jivesoftware.smackx.jingle.nat.FixedTransportManager) ArrayList(java.util.ArrayList) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) PayloadType(org.jivesoftware.smackx.jingle.media.PayloadType) XMPPException(org.jivesoftware.smack.XMPPException) TestMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) TransportCandidate(org.jivesoftware.smackx.jingle.nat.TransportCandidate) XMPPException(org.jivesoftware.smack.XMPPException) JingleSessionListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)

Example 4 with JingleSessionListener

use of org.jivesoftware.smackx.jingle.listeners.JingleSessionListener in project Smack by igniterealtime.

the class JingleManagerTest method testStagesSession.

/**
     * This is a simple test where the user_2 rejects the Jingle session.
     */
public void testStagesSession() {
    resetCounter();
    try {
        FixedResolver tr0 = new FixedResolver("127.0.0.1", 54222);
        FixedTransportManager ftm0 = new FixedTransportManager(tr0);
        TestMediaManager tmm0 = new TestMediaManager(ftm0);
        tmm0.setPayloads(getTestPayloads1());
        List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
        trl0.add(tmm0);
        FixedResolver tr1 = new FixedResolver("127.0.0.1", 54567);
        FixedTransportManager ftm1 = new FixedTransportManager(tr1);
        TestMediaManager tmm1 = new TestMediaManager(ftm1);
        tmm1.setPayloads(getTestPayloads2());
        List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
        trl1.add(tmm1);
        JingleManager man0 = new JingleManager(getConnection(0), trl0);
        JingleManager man1 = new JingleManager(getConnection(1), trl1);
        man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {

            /**
                 * Called when a new session request is detected
                 */
            public void sessionRequested(final JingleSessionRequest request) {
                System.out.println("Session request detected, from " + request.getFrom() + ": accepting.");
                try {
                    // We accept the request
                    JingleSession session1 = request.accept();
                    session1.addListener(new JingleSessionListener() {

                        public void sessionClosed(String reason, JingleSession jingleSession) {
                            System.out.println("sessionClosed().");
                        }

                        public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
                            System.out.println("sessionClosedOnError().");
                        }

                        public void sessionDeclined(String reason, JingleSession jingleSession) {
                            System.out.println("sessionDeclined().");
                        }

                        public void sessionEstablished(PayloadType pt, TransportCandidate rc, final TransportCandidate lc, JingleSession jingleSession) {
                            incCounter();
                            System.out.println("Responder: the session is fully established.");
                            System.out.println("+ Payload Type: " + pt.getId());
                            System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
                            System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
                        }

                        public void sessionMediaReceived(JingleSession jingleSession, String participant) {
                        // Do Nothing
                        }

                        public void sessionRedirected(String redirection, JingleSession jingleSession) {
                        }
                    });
                    session1.startIncoming();
                } catch (Exception e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        });
        // Session 0 starts a request
        System.out.println("Starting session request, to " + getFullJID(1) + "...");
        JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
        session0.addListener(new JingleSessionListener() {

            public void sessionClosed(String reason, JingleSession jingleSession) {
            }

            public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
            }

            public void sessionDeclined(String reason, JingleSession jingleSession) {
            }

            public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) {
                incCounter();
                System.out.println("Initiator: the session is fully established.");
                System.out.println("+ Payload Type: " + pt.getId());
                System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
                System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
            }

            public void sessionRedirected(String redirection, JingleSession jingleSession) {
            }

            public void sessionMediaReceived(JingleSession jingleSession, String participant) {
            // Do Nothing
            }
        });
        session0.startOutgoing();
        Thread.sleep(20000);
        assertTrue(valCounter() == 2);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
        fail("An error occured with Jingle");
    }
}
Also used : FixedResolver(org.jivesoftware.smackx.jingle.nat.FixedResolver) FixedTransportManager(org.jivesoftware.smackx.jingle.nat.FixedTransportManager) ArrayList(java.util.ArrayList) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) PayloadType(org.jivesoftware.smackx.jingle.media.PayloadType) XMPPException(org.jivesoftware.smack.XMPPException) TestMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) TransportCandidate(org.jivesoftware.smackx.jingle.nat.TransportCandidate) XMPPException(org.jivesoftware.smack.XMPPException) JingleSessionListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)

Example 5 with JingleSessionListener

use of org.jivesoftware.smackx.jingle.listeners.JingleSessionListener in project Smack by igniterealtime.

the class JingleManagerTest method testFullTest.

/**
     * This is a full test in the Jingle API.
     */
public void testFullTest() {
    resetCounter();
    XMPPTCPConnection x0 = getConnection(0);
    XMPPTCPConnection x1 = getConnection(1);
    XMPPSmackConfiguration.DEBUG = true;
    FixedResolver tr0 = new FixedResolver("127.0.0.1", 20080);
    FixedTransportManager ftm0 = new FixedTransportManager(tr0);
    JmfMediaManager jmf0 = new JmfMediaManager(ftm0);
    List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
    trl0.add(jmf0);
    FixedResolver tr1 = new FixedResolver("127.0.0.1", 20040);
    FixedTransportManager ftm1 = new FixedTransportManager(tr1);
    JmfMediaManager jmf1 = new JmfMediaManager(ftm1);
    List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
    trl1.add(jmf1);
    JingleManager man0 = new JingleManager(x0, trl0);
    JingleManager man1 = new JingleManager(x1, trl1);
    man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {

        public void sessionRequested(final JingleSessionRequest request) {
            try {
                JingleSession session = request.accept();
                session.addListener(new JingleSessionListener() {

                    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 sessionRedirected(String redirection, JingleSession jingleSession) {
                    }

                    public void sessionClosed(String reason, JingleSession jingleSession) {
                    //  incCounter();
                    }

                    public void sessionMediaReceived(JingleSession jingleSession, String participant) {
                    // Do Nothing
                    }

                    public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
                    //  incCounter();
                    }
                });
                session.startIncoming();
            } catch (XMPPException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
        }
    });
    for (int i = 0; i < 3; i++) try {
        JingleSession js0 = man0.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) {
            }

            public void sessionRedirected(String redirection, JingleSession jingleSession) {
            }

            public void sessionClosed(String reason, JingleSession jingleSession) {
            // incCounter();
            }

            public void sessionMediaReceived(JingleSession jingleSession, String participant) {
            // Do Nothing
            }

            public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
            //  incCounter();
            }
        });
        js0.startOutgoing();
        Thread.sleep(8000);
        js0.terminate();
        Thread.sleep(3000);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
    System.out.println(valCounter());
    assertTrue(valCounter() == 6);
}
Also used : FixedResolver(org.jivesoftware.smackx.jingle.nat.FixedResolver) FixedTransportManager(org.jivesoftware.smackx.jingle.nat.FixedTransportManager) JmfMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager) ArrayList(java.util.ArrayList) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) PayloadType(org.jivesoftware.smackx.jingle.media.PayloadType) XMPPException(org.jivesoftware.smack.XMPPException) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) TransportCandidate(org.jivesoftware.smackx.jingle.nat.TransportCandidate) XMPPException(org.jivesoftware.smack.XMPPException) JingleSessionListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)

Aggregations

ArrayList (java.util.ArrayList)5 XMPPException (org.jivesoftware.smack.XMPPException)5 JingleSessionListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)5 JingleSessionRequestListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener)5 JingleMediaManager (org.jivesoftware.smackx.jingle.media.JingleMediaManager)5 PayloadType (org.jivesoftware.smackx.jingle.media.PayloadType)5 TestMediaManager (org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager)4 FixedResolver (org.jivesoftware.smackx.jingle.nat.FixedResolver)4 FixedTransportManager (org.jivesoftware.smackx.jingle.nat.FixedTransportManager)4 TransportCandidate (org.jivesoftware.smackx.jingle.nat.TransportCandidate)4 UtilityException (de.javawi.jstun.util.UtilityException)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 JingleManager (org.jivesoftware.smackx.jingle.JingleManager)1 JingleSession (org.jivesoftware.smackx.jingle.JingleSession)1 JingleSessionRequest (org.jivesoftware.smackx.jingle.JingleSessionRequest)1 JmfMediaManager (org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager)1