use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.
the class Node method addItemEventListener.
/**
* Register a listener for item publication events. This
* listener will get called whenever an item is published to
* this node.
*
* @param listener The handler for the event
*/
public void addItemEventListener(ItemEventListener listener) {
PacketListener conListener = new ItemEventTranslator(listener);
itemEventToListenerMap.put(listener, conListener);
con.addPacketListener(conListener, new EventContentFilter(EventElementType.items.toString(), "item"));
}
use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.
the class Node method addConfigurationListener.
/**
* Register a listener for configuration events. This listener
* will get called whenever the node's configuration changes.
*
* @param listener The handler for the event
*/
public void addConfigurationListener(NodeConfigListener listener) {
PacketListener conListener = new NodeConfigTranslator(listener);
configEventToListenerMap.put(listener, conListener);
con.addPacketListener(conListener, new EventContentFilter(EventElementType.configuration.toString()));
}
use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.
the class Node method addItemDeleteListener.
/**
* Register an listener for item delete events. This listener
* gets called whenever an item is deleted from the node.
*
* @param listener The handler for the event
*/
public void addItemDeleteListener(ItemDeleteListener listener) {
PacketListener delListener = new ItemDeleteTranslator(listener);
itemDeleteToListenerMap.put(listener, delListener);
EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract");
EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString());
con.addPacketListener(delListener, new OrFilter(deleteItem, purge));
}
use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.
the class EntityCapsManager method init.
private void init() {
Connection connection = weakRefConnection.get();
instances.put(connection, this);
connection.addConnectionListener(new ConnectionListener() {
public void connectionClosed() {
// Unregister this instance since the connection has been closed
presenceSend = false;
instances.remove(weakRefConnection.get());
}
public void connectionClosedOnError(Exception e) {
presenceSend = false;
}
public void reconnectionFailed(Exception e) {
// ignore
}
public void reconnectingIn(int seconds) {
// ignore
}
public void reconnectionSuccessful() {
// ignore
}
});
// This calculates the local entity caps version
updateLocalEntityCaps();
if (SmackConfiguration.autoEnableEntityCaps())
enableEntityCaps();
PacketFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new PacketExtensionFilter(ELEMENT, NAMESPACE));
connection.addPacketListener(new PacketListener() {
// Listen for remote presence stanzas with the caps extension
// If we receive such a stanza, record the JID and nodeVer
public void processPacket(Packet packet) {
if (!entityCapsEnabled())
return;
CapsExtension ext = (CapsExtension) packet.getExtension(EntityCapsManager.ELEMENT, EntityCapsManager.NAMESPACE);
String hash = ext.getHash().toLowerCase();
if (!SUPPORTED_HASHES.containsKey(hash))
return;
String from = packet.getFrom();
String node = ext.getNode();
String ver = ext.getVer();
jidCaps.put(from, new NodeVerHash(node, ver, hash));
}
}, packetFilter);
packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new NotFilter(new PacketExtensionFilter(ELEMENT, NAMESPACE)));
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
// always remove the JID from the map, even if entityCaps are
// disabled
String from = packet.getFrom();
jidCaps.remove(from);
}
}, packetFilter);
packetFilter = new PacketTypeFilter(Presence.class);
connection.addPacketSendingListener(new PacketListener() {
public void processPacket(Packet packet) {
presenceSend = true;
}
}, packetFilter);
// Intercept presence packages and add caps data when intended.
// XEP-0115 specifies that a client SHOULD include entity capabilities
// with every presence notification it sends.
PacketFilter capsPacketFilter = new PacketTypeFilter(Presence.class);
PacketInterceptor packetInterceptor = new PacketInterceptor() {
public void interceptPacket(Packet packet) {
if (!entityCapsEnabled)
return;
CapsExtension caps = new CapsExtension(ENTITY_NODE, getCapsVersion(), "sha-1");
packet.addExtension(caps);
}
};
connection.addPacketInterceptor(packetInterceptor, capsPacketFilter);
// It's important to do this as last action. Since it changes the
// behavior of the SDM in some ways
sdm.setEntityCapsManager(this);
}
use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.
the class FileTransferManager method initListeners.
private void initListeners() {
listeners = new ArrayList<FileTransferListener>();
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
fireNewRequest((StreamInitiation) packet);
}
}, new AndFilter(new PacketTypeFilter(StreamInitiation.class), new IQTypeFilter(IQ.Type.SET)));
}
Aggregations