Search in sources :

Example 1 with TransportResolver

use of org.jivesoftware.smackx.jingleold.nat.TransportResolver in project Smack by igniterealtime.

the class JingleSessionStateUnknown method receiveSessionInitiateAction.

/**
     * In the UNKNOWN state we received a <session-initiate> action.
     * This method processes that action.
     * @throws SmackException 
     * @throws InterruptedException 
     */
private IQ receiveSessionInitiateAction(JingleSession session, Jingle inJingle) throws SmackException, InterruptedException {
    IQ response = null;
    boolean shouldAck = true;
    if (!shouldAck) {
        response = session.createJingleError(inJingle, JingleError.NEGOTIATION_ERROR);
    } else {
        // Create the Ack
        response = session.createAck(inJingle);
        session.setSessionState(JingleSessionStatePending.getInstance());
        // Now set up all of the initial content negotiators for the session.
        for (JingleContent jingleContent : inJingle.getContentsList()) {
            // First create the content negotiator for this <content> section.
            ContentNegotiator contentNeg = new ContentNegotiator(session, jingleContent.getCreator(), jingleContent.getName());
            // Get the media negotiator that goes with the <description> of this content.
            JingleDescription jingleDescription = jingleContent.getDescription();
            // Loop through each media manager looking for the ones that matches the incoming 
            // session-initiate <content> choices.
            // (Set the first media manager as the default, so that in case things don't match we can still negotiate.)
            JingleMediaManager chosenMediaManager = session.getMediaManagers().get(0);
            for (JingleMediaManager mediaManager : session.getMediaManagers()) {
                boolean matches = true;
                for (PayloadType mediaPayloadType : mediaManager.getPayloads()) {
                    for (PayloadType descPayloadType2 : jingleDescription.getPayloadTypesList()) {
                        if (mediaPayloadType.getId() != descPayloadType2.getId()) {
                            matches = false;
                        }
                    }
                    if (matches) {
                        chosenMediaManager = mediaManager;
                    }
                }
            }
            // Create the media negotiator for this content description.
            contentNeg.setMediaNegotiator(new MediaNegotiator(session, chosenMediaManager, jingleDescription.getPayloadTypesList(), contentNeg));
            // Then create a transport negotiator for that transport.
            for (JingleTransport jingleTransport : jingleContent.getJingleTransportsList()) {
                for (JingleMediaManager mediaManager : session.getMediaManagers()) {
                    JingleTransportManager transportManager = mediaManager.getTransportManager();
                    TransportResolver resolver = null;
                    try {
                        resolver = transportManager.getResolver(session);
                    } catch (XMPPException e) {
                        LOGGER.log(Level.WARNING, "exception", e);
                    }
                    if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
                        contentNeg.setTransportNegotiator(new TransportNegotiator.RawUdp(session, resolver, contentNeg));
                    }
                    if (resolver.getType().equals(TransportResolver.Type.ice)) {
                        contentNeg.setTransportNegotiator(new TransportNegotiator.Ice(session, resolver, contentNeg));
                    }
                }
            }
            // Add the content negotiator to the session.
            session.addContentNegotiator(contentNeg);
        }
        // Now setup to track the media negotiators, so that we know when (if) to send a session-accept.
        session.setupListeners();
    }
    return response;
}
Also used : JingleDescription(org.jivesoftware.smackx.jingleold.packet.JingleDescription) IQ(org.jivesoftware.smack.packet.IQ) MediaNegotiator(org.jivesoftware.smackx.jingleold.media.MediaNegotiator) JingleTransport(org.jivesoftware.smackx.jingleold.packet.JingleTransport) PayloadType(org.jivesoftware.smackx.jingleold.media.PayloadType) TransportNegotiator(org.jivesoftware.smackx.jingleold.nat.TransportNegotiator) JingleMediaManager(org.jivesoftware.smackx.jingleold.media.JingleMediaManager) TransportResolver(org.jivesoftware.smackx.jingleold.nat.TransportResolver) JingleContent(org.jivesoftware.smackx.jingleold.packet.JingleContent) XMPPException(org.jivesoftware.smack.XMPPException) JingleTransportManager(org.jivesoftware.smackx.jingleold.nat.JingleTransportManager)

Example 2 with TransportResolver

use of org.jivesoftware.smackx.jingleold.nat.TransportResolver in project Smack by igniterealtime.

the class JingleSession method startOutgoing.

/**
     * This is the starting point for intitiating a new session.
     * 
     * @throws IllegalStateException
     * @throws SmackException 
     * @throws InterruptedException 
     */
public void startOutgoing() throws IllegalStateException, SmackException, InterruptedException {
    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) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
        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.getStanzaId();
    sendStanza(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();
//        }
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) TransportNegotiator(org.jivesoftware.smackx.jingleold.nat.TransportNegotiator) JingleMediaManager(org.jivesoftware.smackx.jingleold.media.JingleMediaManager) TransportResolver(org.jivesoftware.smackx.jingleold.nat.TransportResolver) MediaNegotiator(org.jivesoftware.smackx.jingleold.media.MediaNegotiator) XMPPException(org.jivesoftware.smack.XMPPException) JingleTransportManager(org.jivesoftware.smackx.jingleold.nat.JingleTransportManager)

Aggregations

XMPPException (org.jivesoftware.smack.XMPPException)2 JingleMediaManager (org.jivesoftware.smackx.jingleold.media.JingleMediaManager)2 MediaNegotiator (org.jivesoftware.smackx.jingleold.media.MediaNegotiator)2 JingleTransportManager (org.jivesoftware.smackx.jingleold.nat.JingleTransportManager)2 TransportNegotiator (org.jivesoftware.smackx.jingleold.nat.TransportNegotiator)2 TransportResolver (org.jivesoftware.smackx.jingleold.nat.TransportResolver)2 IQ (org.jivesoftware.smack.packet.IQ)1 PayloadType (org.jivesoftware.smackx.jingleold.media.PayloadType)1 Jingle (org.jivesoftware.smackx.jingleold.packet.Jingle)1 JingleContent (org.jivesoftware.smackx.jingleold.packet.JingleContent)1 JingleDescription (org.jivesoftware.smackx.jingleold.packet.JingleDescription)1 JingleTransport (org.jivesoftware.smackx.jingleold.packet.JingleTransport)1