Search in sources :

Example 1 with JingleException

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

the class TransportNegotiator method dispatchIncomingPacket.

/**
     * Dispatch an incoming packet. The method is responsible for recognizing
     * the stanza(/packet) type and, depending on the current state, deliverying 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 SmackException 
     * @throws InterruptedException 
     */
@Override
public final List<IQ> dispatchIncomingPacket(IQ iq, String id) throws XMPPException, SmackException, InterruptedException {
    List<IQ> responses = new ArrayList<IQ>();
    IQ response = null;
    if (iq != null) {
        if (iq.getType().equals(IQ.Type.error)) {
            // Process errors
            setNegotiatorState(JingleNegotiatorState.FAILED);
            triggerTransportClosed(null);
            // 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())) {
                response = receiveResult(iq);
                removeExpectedId(iq.getStanzaId());
            }
        } else if (iq instanceof Jingle) {
            // Get the action from the Jingle packet
            Jingle jingle = (Jingle) iq;
            JingleActionEnum action = jingle.getAction();
            switch(action) {
                case CONTENT_ACCEPT:
                    response = receiveContentAcceptAction(jingle);
                    break;
                case CONTENT_MODIFY:
                    break;
                case CONTENT_REMOVE:
                    break;
                case SESSION_INFO:
                    break;
                case SESSION_INITIATE:
                    response = receiveSessionInitiateAction(jingle);
                    break;
                case SESSION_ACCEPT:
                    response = receiveSessionAcceptAction(jingle);
                    break;
                case TRANSPORT_INFO:
                    response = receiveTransportInfoAction(jingle);
                    break;
                default:
                    break;
            }
        }
    }
    if (response != null) {
        addExpectedId(response.getStanzaId());
        responses.add(response);
    }
    return responses;
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) ArrayList(java.util.ArrayList) IQ(org.jivesoftware.smack.packet.IQ) JingleActionEnum(org.jivesoftware.smackx.jingleold.JingleActionEnum) JingleException(org.jivesoftware.smackx.jingleold.JingleException)

Example 2 with JingleException

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

the class MediaNegotiator method receiveSessionAcceptAction.

/**
     * A jmf description has been accepted. In this case, we must save the
     * accepted payload type and notify any listener...
     * 
     * @param jin
     *            The input packet
     * @return a Jingle packet
     * @throws JingleException
     */
private IQ receiveSessionAcceptAction(Jingle jingle, JingleDescription description) throws JingleException {
    IQ response = null;
    PayloadType.Audio agreedCommonAudioPt;
    List<PayloadType> offeredPayloads = new ArrayList<PayloadType>();
    if (bestCommonAudioPt == null) {
        // Update the best common audio PT
        bestCommonAudioPt = calculateBestCommonAudioPt(remoteAudioPts);
    //response = createAcceptMessage();
    }
    offeredPayloads = description.getAudioPayloadTypesList();
    if (!offeredPayloads.isEmpty()) {
        if (offeredPayloads.size() == 1) {
            agreedCommonAudioPt = (PayloadType.Audio) offeredPayloads.get(0);
            if (bestCommonAudioPt != null) {
                // everything is fine
                if (!agreedCommonAudioPt.equals(bestCommonAudioPt)) {
                    throw new JingleException(JingleError.NEGOTIATION_ERROR);
                }
            }
        } else if (offeredPayloads.size() > 1) {
            throw new JingleException(JingleError.MALFORMED_STANZA);
        }
    }
    return response;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) ArrayList(java.util.ArrayList) JingleException(org.jivesoftware.smackx.jingleold.JingleException)

Example 3 with JingleException

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

the class MediaNegotiator method receiveSessionInfoAction.

/**
     * A content info has been received. This is done for publishing the
     * list of payload types...
     * 
     * @param jin
     *            The input packet
     * @return a Jingle packet
     * @throws JingleException
     */
private IQ receiveSessionInfoAction(Jingle jingle, JingleDescription description) throws JingleException {
    IQ response = null;
    PayloadType oldBestCommonAudioPt = bestCommonAudioPt;
    List<PayloadType> offeredPayloads;
    boolean ptChange = false;
    offeredPayloads = description.getAudioPayloadTypesList();
    if (!offeredPayloads.isEmpty()) {
        synchronized (remoteAudioPts) {
            remoteAudioPts.clear();
            remoteAudioPts.addAll(offeredPayloads);
        }
        // Calculate the best common codec
        bestCommonAudioPt = calculateBestCommonAudioPt(remoteAudioPts);
        if (bestCommonAudioPt != null) {
            // and send an accept if we have an agreement...
            ptChange = !bestCommonAudioPt.equals(oldBestCommonAudioPt);
            if (oldBestCommonAudioPt == null || ptChange) {
            //response = createAcceptMessage();
            }
        } else {
            throw new JingleException(JingleError.NO_COMMON_PAYLOAD);
        }
    }
    // Parse the Jingle and get the payload accepted
    return response;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) JingleException(org.jivesoftware.smackx.jingleold.JingleException)

Example 4 with JingleException

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

IQ (org.jivesoftware.smack.packet.IQ)4 JingleException (org.jivesoftware.smackx.jingleold.JingleException)4 ArrayList (java.util.ArrayList)3 JingleActionEnum (org.jivesoftware.smackx.jingleold.JingleActionEnum)2 Jingle (org.jivesoftware.smackx.jingleold.packet.Jingle)2 JingleContent (org.jivesoftware.smackx.jingleold.packet.JingleContent)1 JingleDescription (org.jivesoftware.smackx.jingleold.packet.JingleDescription)1