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;
}
});
}
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;
}
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);
}
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());
}
}
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());
}
}
Aggregations