Search in sources :

Example 1 with JingleSessionRequest

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

the class Demo method initialize.

public void initialize() {
    ICETransportManager icetm0 = new ICETransportManager(xmppConnection, "10.47.47.53", 3478);
    List<JingleMediaManager> mediaManagers = new ArrayList<JingleMediaManager>();
    //mediaManagers.add(new JmfMediaManager(icetm0));
    mediaManagers.add(new SpeexMediaManager(icetm0));
    mediaManagers.add(new ScreenShareMediaManager(icetm0));
    jm = new JingleManager(xmppConnection, mediaManagers);
    jm.addCreationListener(icetm0);
    jm.addJingleSessionRequestListener(new JingleSessionRequestListener() {

        public void sessionRequested(JingleSessionRequest request) {
            try {
                // Accept the call
                incoming = request.accept();
                // Start the call
                incoming.startIncoming();
            } catch (XMPPException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
        }
    });
    createGUI();
}
Also used : ICETransportManager(org.jivesoftware.smackx.jingle.nat.ICETransportManager) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) ArrayList(java.util.ArrayList) JingleManager(org.jivesoftware.smackx.jingle.JingleManager) JingleSessionRequest(org.jivesoftware.smackx.jingle.JingleSessionRequest) ScreenShareMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.sshare.ScreenShareMediaManager) SpeexMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.jspeex.SpeexMediaManager) XMPPException(org.jivesoftware.smack.XMPPException) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener)

Example 2 with JingleSessionRequest

use of org.jivesoftware.smackx.jingle.JingleSessionRequest 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)

Aggregations

ArrayList (java.util.ArrayList)2 XMPPException (org.jivesoftware.smack.XMPPException)2 JingleManager (org.jivesoftware.smackx.jingle.JingleManager)2 JingleSessionRequest (org.jivesoftware.smackx.jingle.JingleSessionRequest)2 JingleSessionRequestListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener)2 JingleMediaManager (org.jivesoftware.smackx.jingle.media.JingleMediaManager)2 UtilityException (de.javawi.jstun.util.UtilityException)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 JingleSession (org.jivesoftware.smackx.jingle.JingleSession)1 JingleSessionListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)1 PayloadType (org.jivesoftware.smackx.jingle.media.PayloadType)1 SpeexMediaManager (org.jivesoftware.smackx.jingle.mediaimpl.jspeex.SpeexMediaManager)1 ScreenShareMediaManager (org.jivesoftware.smackx.jingle.mediaimpl.sshare.ScreenShareMediaManager)1 TestMediaManager (org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager)1 ICETransportManager (org.jivesoftware.smackx.jingle.nat.ICETransportManager)1