Java 类org.jivesoftware.smackx.jingle.media.JingleMediaManager 实例源码

项目:Smack    文件:JingleSessionTest.java   
public void testEqualsObject() {

    FixedResolver tr1 = new FixedResolver("127.0.0.1", 54222);
    FixedTransportManager ftm1 = new FixedTransportManager(tr1);
    TestMediaManager tmm1 = new TestMediaManager(ftm1);
    List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
    trl1.add(tmm1);

    JingleSession js1 = new JingleSession(getConnection(0), "res1", null, "10", trl1);
    JingleSession js2 = new JingleSession(getConnection(1), "res1", null, "10", trl1);
    JingleSession js3 = new JingleSession(getConnection(2), "res2", null, "11", trl1);

    System.out.println(js1.getSid());
    System.out.println(js2.getSid());

    js1.setInitiator("js1");
    js2.setInitiator("js1");
    js1.setSid("10");
    js2.setSid("10");

    assertEquals(js1, js2);
    assertEquals(js2, js1);

    assertFalse(js1.equals(js3));
}
项目:Smack    文件:JingleSessionTest.java   
public void testGetInstanceFor() {
    String ini1 = "initiator1";
    String sid1 = "sid1";
    String ini2 = "initiator2";
    String sid2 = "sid2";

    FixedResolver tr1 = new FixedResolver("127.0.0.1", 54222);
    FixedTransportManager ftm1 = new FixedTransportManager(tr1);
    TestMediaManager tmm1 = new TestMediaManager(ftm1);
    List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
    trl1.add(tmm1);

    JingleSession js1 = new JingleSession(getConnection(0), ini1, null, sid1, trl1);
    JingleSession js2 = new JingleSession(getConnection(1), ini2, null, sid2, trl1);

    // For a packet, we should be able to get a session that handles that...
    assertNotNull(JingleSession.getInstanceFor(getConnection(0)));
    assertNotNull(JingleSession.getInstanceFor(getConnection(1)));

    assertEquals(JingleSession.getInstanceFor(getConnection(0)), js1);
    assertEquals(JingleSession.getInstanceFor(getConnection(1)), js2);
}
项目:java-bells    文件:JingleSession.java   
/**
 * Full featured JingleSession constructor
 * 
 * @param conn
 *            the Connection which is used
 * @param initiator
 *            the initiator JID
 * @param responder
 *            the responder JID
 * @param sessionid
 *            the session ID
 * @param jingleMediaManager
 *            the jingleMediaManager
 */
public JingleSession(Connection conn, String initiator, String responder, String sessionid,
        List<JingleMediaManager> jingleMediaManagers) {
    super();

    this.initiator = initiator;
    this.responder = responder;
    this.sid = sessionid;
    this.jingleMediaManagers = jingleMediaManagers;
    this.setSession(this);
    this.connection = conn;

    // Initially, we don't known the session state.
    setSessionState(JingleSessionStateUnknown.getInstance());

    contentNegotiators = new ArrayList<ContentNegotiator>();
    mediaSessionMap = new HashMap<String, JingleMediaSession>();

    // Add the session to the list and register the listeneres
    registerInstance();
    installConnectionListeners(conn);
}
项目:Smack    文件:Demo.java   
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) {

//                if (incoming != null)
//                    return;

                try {
                    // Accept the call
                    incoming = request.accept();

                    // Start the call
                    incoming.startIncoming();
                }
                catch (XMPPException e) {
                    e.printStackTrace();
                }

            }
        });
        createGUI();
    }
项目:java-bells    文件:Demo.java   
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) {

//                if (incoming != null)
//                    return;

                try {
                    // Accept the call
                    incoming = request.accept();

                    // Start the call
                    incoming.startIncoming();
                }
                catch (XMPPException e) {
                    e.printStackTrace();
                }

            }
        });
        createGUI();
    }
项目:java-bells    文件:MultiMediaManager.java   
/**
 * Return all supported Payloads for this Manager.
 *
 * @return The Payload List
 */
public List<PayloadType> getPayloads() {
    List<PayloadType> list = new ArrayList<PayloadType>();
    if (preferredPayloadType != null) list.add(preferredPayloadType);
    for (JingleMediaManager manager : managers) {
        for (PayloadType payloadType : manager.getPayloads()) {
            if (!list.contains(payloadType) && !payloadType.equals(preferredPayloadType))
                list.add(payloadType);
        }
    }
    return list;
}
项目:java-bells    文件:MultiMediaManager.java   
/**
 * Returns a new JingleMediaSession
 *
 * @param payloadType payloadType
 * @param remote      remote Candidate
 * @param local       local Candidate
 * @return JingleMediaSession JingleMediaSession
 */
public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) {
    for (JingleMediaManager manager : managers) {
        if (manager.getPayloads().contains(payloadType)) {
            return manager.createMediaSession(payloadType, remote, local, jingleSession);
        }
    }
    return null;
}
项目:java-bells    文件:ContentNegotiator.java   
/**
 * Trigger a session established event.
 */
private void triggerContentEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc) {

    // Let the session know that we've established a content/media segment.
    JingleSession session = getSession();
    if (session != null) {
        List<JingleListener> listeners = session.getListenersList();
        for (JingleListener li : listeners) {
            if (li instanceof JingleSessionListener) {
                JingleSessionListener sli = (JingleSessionListener) li;
                sli.sessionEstablished(pt, rc, lc, session);
            }
        }
    }

    // Create a media session for each media manager in the session.
    if (mediaNeg.getMediaManager() != null) {
        rc.removeCandidateEcho();
        lc.removeCandidateEcho();

        jingleMediaSession = getMediaNegotiator().getMediaManager().createMediaSession(pt, rc, lc, session);
        jingleMediaSession.addMediaReceivedListener(session);
        if (jingleMediaSession != null) {

            jingleMediaSession.startTrasmit();
            jingleMediaSession.startReceive();

            for (TransportCandidate candidate : getTransportNegotiator().getOfferedCandidates())
                candidate.removeCandidateEcho();
        }
        JingleMediaManager mediaManager = getMediaNegotiator().getMediaManager();
        getSession().addJingleMediaSession(mediaManager.getName(), jingleMediaSession);
    }

}
项目:spark-svn-mirror    文件:JingleRoom.java   
private void toggleMute() {
    if (transmitting) {
        transmitting = false;
        muteButton.setToolTipText(JingleResources.getString("label.mute"));
        muteButton.setButtonSelected(false);
        setStatus(CONNECTED, false);

        // Change state
        JingleStateManager.getInstance().addJingleSession(chatRoom, JingleStateManager.JingleRoomState.inJingleCall);
    } else {
        transmitting = true;
        muteButton.setToolTipText(JingleResources.getString("label.unmute"));
        muteButton.setButtonSelected(true);
        setStatus("Muted", true);

        // Change state
        JingleStateManager.getInstance().addJingleSession(chatRoom, JingleStateManager.JingleRoomState.muted);
    }

    for (JingleMediaManager mediaManager : session.getMediaManagers()) {
        session.getMediaSession(mediaManager.getName()).setTrasmit(!transmitting);
    }

    muteButton.invalidate();
    muteButton.validate();
    muteButton.repaint();

    // Notify state change
    SparkManager.getChatManager().notifySparkTabHandlers(chatRoom);
}
项目:Smack    文件:JingleManagerTest.java   
/**
 * High level API test. This is a simple test to use with an XMPP client and
 * check if the client receives the message 1. User_1 will send an
 * invitation to user_2.
 */
public void testSendSimpleMessage() {

    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(getTestPayloads1());
        List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
        trl1.add(tmm1);

        JingleManager man0 = new JingleManager(getConnection(0), trl0);
        JingleManager man1 = new JingleManager(getConnection(1), trl1);

        // Session 1 waits for connections
        man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
            /**
             * Called when a new session request is detected
             */
            public void sessionRequested(final JingleSessionRequest request) {
                incCounter();
                System.out.println("Session request detected, from " + request.getFrom());
            }
        });

        // Session 0 starts a request
        System.out.println("Starting session request, to " + getFullJID(1) + "...");
        JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
        session0.startOutgoing();

        Thread.sleep(5000);

        assertTrue(valCounter() > 0);

    } catch (Exception e) {
        e.printStackTrace();
        fail("An error occured with Jingle");
    }
}
项目:java-bells    文件:JingleSession.java   
/**
     * This is the starting point for intitiating a new session.
     * 
     * @throws IllegalStateException
     */
    public void startOutgoing() throws IllegalStateException {

        updatePacketListener();
        setSessionState(JingleSessionStatePending.getInstance());

        Jingle jingle = new Jingle(JingleActionEnum.SESSION_INITIATE);

        // Create a content negotiator for each media manager on the session.
        for (JingleMediaManager mediaManager : getMediaManagers()) {
            ContentNegotiator contentNeg = new ContentNegotiator(this, ContentNegotiator.INITIATOR, mediaManager.getName());

            // Create the media negotiator for this content description.
            contentNeg.setMediaNegotiator(new MediaNegotiator(this, mediaManager, mediaManager.getPayloads(), contentNeg));

            JingleTransportManager transportManager = mediaManager.getTransportManager();
            TransportResolver resolver = null;
            try {
                resolver = transportManager.getResolver(this);
            } catch (XMPPException e) {
                e.printStackTrace();
            }

            if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
                contentNeg.setTransportNegotiator(new TransportNegotiator.RawUdp(this, resolver, contentNeg));
            }
            if (resolver.getType().equals(TransportResolver.Type.ice)) {
                contentNeg.setTransportNegotiator(new TransportNegotiator.Ice(this, resolver, contentNeg));
            }

            addContentNegotiator(contentNeg);
        }

        // Give each of the content negotiators a chance to return a portion of the structure to make the Jingle packet.
        for (ContentNegotiator contentNegotiator : contentNegotiators) {
            jingle.addContent(contentNegotiator.getJingleContent());
        }

        // Save the session-initiate packet ID, so that we can respond to it.
        sessionInitPacketID = jingle.getPacketID();

        sendPacket(jingle);

        // Now setup to track the media negotiators, so that we know when (if) to send a session-accept.
        setupListeners();

        // Give each of the content negotiators a chance to start 
        // and return a portion of the structure to make the Jingle packet.

// Don't do this anymore.  The problem is that the other side might not be ready.
// Later when we receive our first jingle packet from the other side we'll fire-up the negotiators
// before processing it.  (See receivePacketAndRespond() above.
//        for (ContentNegotiator contentNegotiator : contentNegotiators) {
//            contentNegotiator.start();
//        }
    }
项目:java-bells    文件:MultiMediaManager.java   
public void addMediaManager(JingleMediaManager manager) {
    managers.add(manager);
}
项目:java-bells    文件:MultiMediaManager.java   
public void removeMediaManager(JingleMediaManager manager) {
    managers.remove(manager);
}
项目:java-bells    文件:JingleSession.java   
/**
 * JingleSession constructor (for an outgoing Jingle session)
 * 
 * @param conn
 *            Connection
 * @param initiator
 *            the initiator JID
 * @param responder
 *            the responder JID
 * @param jingleMediaManager
 *            the jingleMediaManager
 */
public JingleSession(Connection conn, JingleSessionRequest request, String initiator, String responder,
        List<JingleMediaManager> jingleMediaManagers) {
    this(conn, initiator, responder, generateSessionId(), jingleMediaManagers);
    //sessionRequest = request; // unused
}
项目:java-bells    文件:JingleSession.java   
/**
 * Get the Media Manager of this Jingle Session
 * 
 * @return
 */
public List<JingleMediaManager> getMediaManagers() {
    return jingleMediaManagers;
}
项目:java-bells    文件:JingleSession.java   
/**
 * Set the Media Manager of this Jingle Session
 * 
 * @param jingleMediaManager
 */
public void setMediaManagers(List<JingleMediaManager> jingleMediaManagers) {
    this.jingleMediaManagers = jingleMediaManagers;
}
项目:java-bells    文件:JingleManager.java   
/**
 * Get the Media Managers of this Jingle Manager
 *
 * @return
 */
public List<JingleMediaManager> getMediaManagers() {
    return jingleMediaManagers;
}
项目:java-bells    文件:JingleManager.java   
/**
 * Set the Media Managers of this Jingle Manager
 *
 * @param jingleMediaManager JingleMediaManager to be used for open, close, start and stop jmf streamings
 */
public void setMediaManagers(List<JingleMediaManager> jingleMediaManagers) {
    this.jingleMediaManagers = jingleMediaManagers;
}