Search in sources :

Example 1 with JingleDescription

use of org.jivesoftware.smackx.jingleold.packet.JingleDescription 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 JingleDescription

use of org.jivesoftware.smackx.jingleold.packet.JingleDescription in project Smack by igniterealtime.

the class MediaNegotiator method getJingleDescription.

/**
     *  Create a JingleDescription that matches this negotiator.
     */
public JingleDescription getJingleDescription() {
    JingleDescription result = null;
    PayloadType payloadType = getBestCommonAudioPt();
    if (payloadType != null) {
        result = new JingleDescription.Audio(payloadType);
    } else {
        // If we haven't settled on a best payload type yet then just use the first one in our local list.
        result = new JingleDescription.Audio();
        result.addAudioPayloadTypes(localAudioPts);
    }
    return result;
}
Also used : JingleDescription(org.jivesoftware.smackx.jingleold.packet.JingleDescription)

Example 3 with JingleDescription

use of org.jivesoftware.smackx.jingleold.packet.JingleDescription in project Smack by igniterealtime.

the class JingleDescriptionProvider method parse.

/**
     * Parse a iq/jingle/description element.
     * 
     * @param parser
     *            the input to parse
     * @return a description element
     * @throws SmackException 
     * @throws IOException 
     * @throws XmlPullParserException 
     */
@Override
public JingleDescription parse(XmlPullParser parser, int initialDepth) throws SmackException, XmlPullParserException, IOException {
    boolean done = false;
    JingleDescription desc = getInstance();
    while (!done) {
        int eventType = parser.next();
        String name = parser.getName();
        if (eventType == XmlPullParser.START_TAG) {
            if (name.equals(PayloadType.NODENAME)) {
                desc.addPayloadType(parsePayload(parser));
            } else {
                throw new SmackException("Unknow element \"" + name + "\" in content.");
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (name.equals(JingleDescription.NODENAME)) {
                done = true;
            }
        }
    }
    return desc;
}
Also used : JingleDescription(org.jivesoftware.smackx.jingleold.packet.JingleDescription) SmackException(org.jivesoftware.smack.SmackException)

Example 4 with JingleDescription

use of org.jivesoftware.smackx.jingleold.packet.JingleDescription in project Smack by igniterealtime.

the class MediaNegotiator method dispatchIncomingPacket.

/**
     * Dispatch an incoming packet. The method is responsible for recognizing
     * the stanza(/packet) type and, depending on the current state, delivering the
     * stanza(/packet) to the right event handler and wait for a response.
     * 
     * @param iq
     *            the stanza(/packet) received
     * @return the new Jingle stanza(/packet) to send.
     * @throws XMPPException
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
@Override
public List<IQ> dispatchIncomingPacket(IQ iq, String id) throws XMPPException, NotConnectedException, InterruptedException {
    List<IQ> responses = new ArrayList<IQ>();
    IQ response = null;
    if (iq.getType().equals(IQ.Type.error)) {
        // Process errors
        setNegotiatorState(JingleNegotiatorState.FAILED);
        triggerMediaClosed(getBestCommonAudioPt());
        // This next line seems wrong, and may subvert the normal closing process.
        throw new JingleException(iq.getError().getDescriptiveText());
    } else if (iq.getType().equals(IQ.Type.result)) {
        // Process ACKs
        if (isExpectedId(iq.getStanzaId())) {
            receiveResult(iq);
            removeExpectedId(iq.getStanzaId());
        }
    } else if (iq instanceof Jingle) {
        Jingle jingle = (Jingle) iq;
        JingleActionEnum action = jingle.getAction();
        // Only act on the JingleContent sections that belong to this media negotiator.
        for (JingleContent jingleContent : jingle.getContentsList()) {
            if (jingleContent.getName().equals(parentNegotiator.getName())) {
                JingleDescription description = jingleContent.getDescription();
                if (description != null) {
                    switch(action) {
                        case CONTENT_ACCEPT:
                            response = receiveContentAcceptAction(jingle, description);
                            break;
                        case CONTENT_MODIFY:
                            break;
                        case CONTENT_REMOVE:
                            break;
                        case SESSION_INFO:
                            response = receiveSessionInfoAction(jingle, description);
                            break;
                        case SESSION_INITIATE:
                            response = receiveSessionInitiateAction(jingle, description);
                            break;
                        case SESSION_ACCEPT:
                            response = receiveSessionAcceptAction(jingle, description);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
    if (response != null) {
        addExpectedId(response.getStanzaId());
        responses.add(response);
    }
    return responses;
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) JingleDescription(org.jivesoftware.smackx.jingleold.packet.JingleDescription) ArrayList(java.util.ArrayList) IQ(org.jivesoftware.smack.packet.IQ) JingleContent(org.jivesoftware.smackx.jingleold.packet.JingleContent) JingleActionEnum(org.jivesoftware.smackx.jingleold.JingleActionEnum) JingleException(org.jivesoftware.smackx.jingleold.JingleException)

Aggregations

JingleDescription (org.jivesoftware.smackx.jingleold.packet.JingleDescription)4 IQ (org.jivesoftware.smack.packet.IQ)2 JingleContent (org.jivesoftware.smackx.jingleold.packet.JingleContent)2 ArrayList (java.util.ArrayList)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 JingleActionEnum (org.jivesoftware.smackx.jingleold.JingleActionEnum)1 JingleException (org.jivesoftware.smackx.jingleold.JingleException)1 JingleMediaManager (org.jivesoftware.smackx.jingleold.media.JingleMediaManager)1 MediaNegotiator (org.jivesoftware.smackx.jingleold.media.MediaNegotiator)1 PayloadType (org.jivesoftware.smackx.jingleold.media.PayloadType)1 JingleTransportManager (org.jivesoftware.smackx.jingleold.nat.JingleTransportManager)1 TransportNegotiator (org.jivesoftware.smackx.jingleold.nat.TransportNegotiator)1 TransportResolver (org.jivesoftware.smackx.jingleold.nat.TransportResolver)1 Jingle (org.jivesoftware.smackx.jingleold.packet.Jingle)1 JingleTransport (org.jivesoftware.smackx.jingleold.packet.JingleTransport)1