Search in sources :

Example 1 with JingleMediaSession

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

the class JingleManagerTest method testMediaManager.

/**
     * This is a full test in the Jingle API.
     */
public void testMediaManager() {
    resetCounter();
    XMPPTCPConnection x0 = getConnection(0);
    XMPPTCPConnection x1 = getConnection(1);
    FixedResolver tr0 = new FixedResolver("127.0.0.1", 20004);
    FixedTransportManager ftm0 = new FixedTransportManager(tr0);
    FixedResolver tr1 = new FixedResolver("127.0.0.1", 20040);
    FixedTransportManager ftm1 = new FixedTransportManager(tr1);
    try {
        JingleMediaManager jingleMediaManager = new JingleMediaManager(ftm0) {

            // Media Session Implementation
            public JingleMediaSession createMediaSession(final PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) {
                return new JingleMediaSession(payloadType, remote, local, null, null) {

                    public void initialize() {
                    }

                    public void startTrasmit() {
                        incCounter();
                        System.out.println("Transmit");
                    }

                    public void startReceive() {
                        incCounter();
                        System.out.println("Receive");
                    }

                    public void setTrasmit(boolean active) {
                    }

                    public void stopTrasmit() {
                        incCounter();
                        System.out.println("Stop Transmit");
                    }

                    public void stopReceive() {
                        incCounter();
                        System.out.println("Stop Receive");
                    }
                };
            }

            public List<PayloadType> getPayloads() {
                return getTestPayloads1();
            }

            public PayloadType.Audio getPreferredAudioPayloadType() {
                return (PayloadType.Audio) getTestPayloads1().get(0);
            }
        };
        List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
        trl0.add(jingleMediaManager);
        List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
        trl1.add(jingleMediaManager);
        JingleManager jm0 = new JingleManager(x0, trl0);
        JingleManager jm1 = new JingleManager(x1, trl1);
        jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {

            public void sessionRequested(final JingleSessionRequest request) {
                try {
                    JingleSession session = request.accept();
                    session.startIncoming();
                } catch (XMPPException e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        });
        JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
        js0.startOutgoing();
        Thread.sleep(10000);
        js0.terminate();
        Thread.sleep(3000);
        System.out.println(valCounter());
        assertTrue(valCounter() == 8);
        Thread.sleep(15000);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
}
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) JingleMediaSession(org.jivesoftware.smackx.jingle.media.JingleMediaSession) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) TransportCandidate(org.jivesoftware.smackx.jingle.nat.TransportCandidate) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

ArrayList (java.util.ArrayList)1 XMPPException (org.jivesoftware.smack.XMPPException)1 JingleSessionRequestListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener)1 JingleMediaManager (org.jivesoftware.smackx.jingle.media.JingleMediaManager)1 JingleMediaSession (org.jivesoftware.smackx.jingle.media.JingleMediaSession)1 PayloadType (org.jivesoftware.smackx.jingle.media.PayloadType)1 FixedResolver (org.jivesoftware.smackx.jingle.nat.FixedResolver)1 FixedTransportManager (org.jivesoftware.smackx.jingle.nat.FixedTransportManager)1 TransportCandidate (org.jivesoftware.smackx.jingle.nat.TransportCandidate)1