Search in sources :

Example 11 with Jingle

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

the class JingleSession method updatePacketListener.

/**
     * Install the stanza(/packet) listener. The listener is responsible for responding
     * to any stanza(/packet) that we receive...
     */
protected void updatePacketListener() {
    removeAsyncPacketListener();
    LOGGER.fine("UpdatePacketListener");
    packetListener = new StanzaListener() {

        @Override
        public void processStanza(Stanza packet) {
            try {
                receivePacketAndRespond((IQ) packet);
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
        }
    };
    packetFilter = new StanzaFilter() {

        @Override
        public boolean accept(Stanza packet) {
            if (packet instanceof IQ) {
                IQ iq = (IQ) packet;
                Jid me = getConnection().getUser();
                if (!iq.getTo().equals(me)) {
                    return false;
                }
                Jid other = getResponder().equals(me) ? getInitiator() : getResponder();
                if (iq.getFrom() == null || !iq.getFrom().equals(other == null ? "" : other)) {
                    return false;
                }
                if (iq instanceof Jingle) {
                    Jingle jin = (Jingle) iq;
                    String sid = jin.getSid();
                    if (sid == null || !sid.equals(getSid())) {
                        LOGGER.fine("Ignored Jingle(SID) " + sid + "|" + getSid() + " :" + iq.toXML());
                        return false;
                    }
                    Jid ini = jin.getInitiator();
                    if (!ini.equals(getInitiator())) {
                        LOGGER.fine("Ignored Jingle(INI): " + iq.toXML());
                        return false;
                    }
                } else {
                    // We accept some non-Jingle IQ packets: ERRORs and ACKs
                    if (iq.getType().equals(IQ.Type.set)) {
                        LOGGER.fine("Ignored Jingle(TYPE): " + iq.toXML());
                        return false;
                    } else if (iq.getType().equals(IQ.Type.get)) {
                        LOGGER.fine("Ignored Jingle(TYPE): " + iq.toXML());
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
    };
    getConnection().addAsyncStanzaListener(packetListener, packetFilter);
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) Jid(org.jxmpp.jid.Jid) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) StanzaListener(org.jivesoftware.smack.StanzaListener) SmackException(org.jivesoftware.smack.SmackException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 12 with Jingle

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

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