use of org.jivesoftware.smackx.entitycaps.packet.CapsExtension 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);
}
Aggregations