Search in sources :

Example 6 with Jingle

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

the class TransportNegotiator method receiveResult.

/**
     * The other endpoint has partially accepted our invitation: start
     * offering a list of candidates.
     *
     * @return an IQ packet
     * @throws XMPPException
     * @throws SmackException 
     * @throws InterruptedException 
     */
private Jingle receiveResult(IQ iq) throws XMPPException, SmackException, InterruptedException {
    Jingle response = null;
    sendTransportCandidatesOffer();
    setNegotiatorState(JingleNegotiatorState.PENDING);
    return response;
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle)

Example 7 with Jingle

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

the class TransportNegotiator method sendTransportCandidateOffer.

/**
     * Send an offer for a transport candidate
     *
     * @param cand
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
private synchronized void sendTransportCandidateOffer(TransportCandidate cand) throws NotConnectedException, InterruptedException {
    if (!cand.isNull()) {
        // Offer our new candidate...
        addOfferedCandidate(cand);
        JingleContent content = parentNegotiator.getJingleContent();
        content.addJingleTransport(getJingleTransport(cand));
        Jingle jingle = new Jingle(JingleActionEnum.TRANSPORT_INFO);
        jingle.addContent(content);
        // We SHOULD NOT be sending packets directly.
        // This circumvents the state machinery.
        // TODO - work this into the state machinery.
        session.sendFormattedJingle(jingle);
    }
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) JingleContent(org.jivesoftware.smackx.jingleold.packet.JingleContent)

Example 8 with Jingle

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

Example 9 with Jingle

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

the class JingleSession method setupListeners.

/**
     * Setup the listeners that act on events coming from the lower level negotiators.
     */
public void setupListeners() {
    JingleMediaListener jingleMediaListener = new JingleMediaListener() {

        @Override
        public void mediaClosed(PayloadType cand) {
        }

        @Override
        public void mediaEstablished(PayloadType pt) throws NotConnectedException, InterruptedException {
            if (isFullyEstablished()) {
                Jingle jout = new Jingle(JingleActionEnum.SESSION_ACCEPT);
                // Build up a response packet from each media manager.
                for (ContentNegotiator contentNegotiator : contentNegotiators) {
                    if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
                        jout.addContent(contentNegotiator.getJingleContent());
                }
                // Send the "accept" and wait for the ACK
                addExpectedId(jout.getStanzaId());
                sendStanza(jout);
            //triggerSessionEstablished();
            }
        }
    };
    JingleTransportListener jingleTransportListener = new JingleTransportListener() {

        @Override
        public void transportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException {
            if (isFullyEstablished()) {
                // CHECKSTYLE:OFF
                // Indicate that this session is active.
                setSessionState(JingleSessionStateActive.getInstance());
                for (ContentNegotiator contentNegotiator : contentNegotiators) {
                    // CHECKSTYLE:ON
                    if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
                        contentNegotiator.triggerContentEstablished();
                }
                if (getSessionState().equals(JingleSessionStatePending.getInstance())) {
                    Jingle jout = new Jingle(JingleActionEnum.SESSION_ACCEPT);
                    // Build up a response packet from each media manager.
                    for (ContentNegotiator contentNegotiator : contentNegotiators) {
                        if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
                            jout.addContent(contentNegotiator.getJingleContent());
                    }
                    // Send the "accept" and wait for the ACK
                    addExpectedId(jout.getStanzaId());
                    sendStanza(jout);
                }
            }
        }

        @Override
        public void transportClosed(TransportCandidate cand) {
        }

        @Override
        public void transportClosedOnError(XMPPException e) {
        }
    };
    addMediaListener(jingleMediaListener);
    addTransportListener(jingleTransportListener);
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) TransportCandidate(org.jivesoftware.smackx.jingleold.nat.TransportCandidate) JingleMediaListener(org.jivesoftware.smackx.jingleold.listeners.JingleMediaListener) XMPPException(org.jivesoftware.smack.XMPPException) PayloadType(org.jivesoftware.smackx.jingleold.media.PayloadType) JingleTransportListener(org.jivesoftware.smackx.jingleold.listeners.JingleTransportListener)

Example 10 with Jingle

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

the class JingleSession method terminate.

/**
     * Terminates the session with a custom reason.
     * 
     * @throws XMPPException
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void terminate(String reason) throws XMPPException, NotConnectedException, InterruptedException {
    if (isClosed())
        return;
    LOGGER.fine("Terminate " + reason);
    Jingle jout = new Jingle(JingleActionEnum.SESSION_TERMINATE);
    jout.setType(IQ.Type.set);
    sendStanza(jout);
    triggerSessionClosed(reason);
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle)

Aggregations

Jingle (org.jivesoftware.smackx.jingleold.packet.Jingle)12 IQ (org.jivesoftware.smack.packet.IQ)5 XMPPException (org.jivesoftware.smack.XMPPException)4 JingleContent (org.jivesoftware.smackx.jingleold.packet.JingleContent)4 ArrayList (java.util.ArrayList)3 SmackException (org.jivesoftware.smack.SmackException)3 JingleActionEnum (org.jivesoftware.smackx.jingleold.JingleActionEnum)3 JingleException (org.jivesoftware.smackx.jingleold.JingleException)3 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)2 Stanza (org.jivesoftware.smack.packet.Stanza)2 Jid (org.jxmpp.jid.Jid)2 JingleMediaListener (org.jivesoftware.smackx.jingleold.listeners.JingleMediaListener)1 JingleSessionRequestListener (org.jivesoftware.smackx.jingleold.listeners.JingleSessionRequestListener)1 JingleTransportListener (org.jivesoftware.smackx.jingleold.listeners.JingleTransportListener)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