Search in sources :

Example 6 with JingleContent

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

JingleContent (org.jivesoftware.smackx.jingleold.packet.JingleContent)6 Jingle (org.jivesoftware.smackx.jingleold.packet.Jingle)4 ArrayList (java.util.ArrayList)2 SmackException (org.jivesoftware.smack.SmackException)2 XMPPException (org.jivesoftware.smack.XMPPException)2 IQ (org.jivesoftware.smack.packet.IQ)2 JingleActionEnum (org.jivesoftware.smackx.jingleold.JingleActionEnum)2 JingleException (org.jivesoftware.smackx.jingleold.JingleException)2 JingleDescription (org.jivesoftware.smackx.jingleold.packet.JingleDescription)2 JingleTransport (org.jivesoftware.smackx.jingleold.packet.JingleTransport)2 JingleTransportCandidate (org.jivesoftware.smackx.jingleold.packet.JingleTransport.JingleTransportCandidate)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)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 JingleContentInfo (org.jivesoftware.smackx.jingleold.packet.JingleContentInfo)1 Jid (org.jxmpp.jid.Jid)1