Search in sources :

Example 1 with PacketFilter

use of org.jivesoftware.smack.filter.PacketFilter in project Openfire by igniterealtime.

the class SmackServiceNode method setup.

private void setup() {
    scheduledExecutor.scheduleWithFixedDelay(new Runnable() {

        public void run() {
            for (final RelayChannel c : channels.values()) {
                final long current = System.currentTimeMillis();
                final long da = current - c.getLastReceivedTimeA();
                final long db = current - c.getLastReceivedTimeB();
                if (da > timeout || db > timeout) {
                    removeChannel(c);
                }
            }
        }
    }, timeout, timeout, TimeUnit.MILLISECONDS);
    connection.addPacketListener(this, new PacketFilter() {

        public boolean accept(Packet packet) {
            return packet instanceof JingleChannelIQ || packet instanceof JingleTrackerIQ;
        }
    });
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) RelayChannel(org.xmpp.jnodes.RelayChannel)

Example 2 with PacketFilter

use of org.jivesoftware.smack.filter.PacketFilter in project camel by apache.

the class XmppEndpoint method createConnection.

public synchronized XMPPConnection createConnection() throws XMPPException, SmackException, IOException {
    if (connection != null && connection.isConnected()) {
        // use existing working connection
        return connection;
    }
    // prepare for creating new connection
    connection = null;
    LOG.trace("Creating new connection ...");
    XMPPConnection newConnection = createConnectionInternal();
    newConnection.connect();
    newConnection.addPacketListener(new XmppLogger("INBOUND"), new PacketFilter() {

        public boolean accept(Packet packet) {
            return true;
        }
    });
    newConnection.addPacketSendingListener(new XmppLogger("OUTBOUND"), new PacketFilter() {

        public boolean accept(Packet packet) {
            return true;
        }
    });
    if (!newConnection.isAuthenticated()) {
        if (user != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Logging in to XMPP as user: {} on connection: {}", user, getConnectionMessage(newConnection));
            }
            if (password == null) {
                LOG.warn("No password configured for user: {} on connection: {}", user, getConnectionMessage(newConnection));
            }
            if (createAccount) {
                AccountManager accountManager = AccountManager.getInstance(newConnection);
                accountManager.createAccount(user, password);
            }
            if (login) {
                if (resource != null) {
                    newConnection.login(user, password, resource);
                } else {
                    newConnection.login(user, password);
                }
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Logging in anonymously to XMPP on connection: {}", getConnectionMessage(newConnection));
            }
            newConnection.loginAnonymously();
        }
    // presence is not needed to be sent after login
    }
    // okay new connection was created successfully so assign it as the connection
    LOG.debug("Created new connection successfully: {}", newConnection);
    connection = newConnection;
    return connection;
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) AccountManager(org.jivesoftware.smack.AccountManager) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 3 with PacketFilter

use of org.jivesoftware.smack.filter.PacketFilter in project SmartMesh_Android by SmartMeshFoundation.

the class XmppService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        if (XmppAction.ACTION_LOGIN.equals(intent.getAction())) {
            // The login
            if (intent.getExtras() != null) {
                Bundle mBundle = intent.getExtras().getBundle(XmppAction.ACTION_LOGIN);
                String[] uNamePwd = mBundle.getStringArray(XmppAction.ACTION_LOGIN);
                String username = uNamePwd[0];
                String password = uNamePwd[1];
                if (!XmppUtils.isLogining) {
                    new LoginThread(mHandler, username, password).start();
                }
            }
        } else if (XmppAction.ACTION_LOGIN_MESSAGE_LISTENER.equals(intent.getAction())) {
            try {
                mXmppUtils = XmppUtils.getInstance();
                if (mPacketListener != null) {
                    mXmppUtils.getConnection().removePacketListener(mPacketListener);
                }
                mXmppUtils.sendOnLine();
                mPacketListener = new NextPacketListener();
                mXmppUtils.getConnection().addPacketListener(mPacketListener, new PacketFilter() {

                    @Override
                    public boolean accept(Packet packet) {
                        return true;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return super.onStartCommand(intent, flags, startId);
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) Bundle(android.os.Bundle) LoginThread(com.lingtuan.firefly.xmpp.LoginThread)

Example 4 with PacketFilter

use of org.jivesoftware.smack.filter.PacketFilter in project ecf by eclipse.

the class MultiUserChat method changeAffiliationByAdmin.

private void changeAffiliationByAdmin(Collection<String> jids, String affiliation) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    for (String jid : jids) {
        // Set the new affiliation.
        MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
        item.setJid(jid);
        iq.addItem(item);
    }
    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();
    if (answer == null) {
        throw new XMPPException("No response from server.");
    } else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
Also used : PacketFilter(org.jivesoftware.smack.filter.PacketFilter) MUCAdmin(org.jivesoftware.smackx.packet.MUCAdmin) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 5 with PacketFilter

use of org.jivesoftware.smack.filter.PacketFilter in project ecf by eclipse.

the class MultiUserChat method changeRole.

private void changeRole(Collection<String> nicknames, String role) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    for (String nickname : nicknames) {
        // Set the new role.
        MUCAdmin.Item item = new MUCAdmin.Item(null, role);
        item.setNick(nickname);
        iq.addItem(item);
    }
    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();
    if (answer == null) {
        throw new XMPPException("No response from server.");
    } else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
Also used : PacketFilter(org.jivesoftware.smack.filter.PacketFilter) MUCAdmin(org.jivesoftware.smackx.packet.MUCAdmin) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

PacketFilter (org.jivesoftware.smack.filter.PacketFilter)40 XMPPException (org.jivesoftware.smack.XMPPException)23 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)22 PacketCollector (org.jivesoftware.smack.PacketCollector)21 IQ (org.jivesoftware.smack.packet.IQ)18 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)15 AndFilter (org.jivesoftware.smack.filter.AndFilter)13 Packet (org.jivesoftware.smack.packet.Packet)13 Registration (org.jivesoftware.smack.packet.Registration)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 ArrayList (java.util.ArrayList)5 PacketListener (org.jivesoftware.smack.PacketListener)5 FromMatchesFilter (org.jivesoftware.smack.filter.FromMatchesFilter)5 Presence (org.jivesoftware.smack.packet.Presence)5 PacketInterceptor (org.jivesoftware.smack.PacketInterceptor)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 Message (org.jivesoftware.smack.packet.Message)4 MUCInitialPresence (org.jivesoftware.smackx.packet.MUCInitialPresence)4 HashMap (java.util.HashMap)2