powered by Jive Software

Presence bot in Smack

I am searching for examples of presence bot

written in Smack.

Purpose - I would like to log presence changes

in MySQL database to create reports how long are

users online, or to show Online/Offline icon

on web homepage (JSP page).



I can’‘t think of anyone that has implemented something specifically like this, but it shouldn’‘t be too difficult. Do you have questions about the Presence API? You’‘ll probably just want to add a packet listener that listens for all presence updates sent to the client. You’‘ll just need to make sure that the client that Smack connects as is subscribed to the presence of all the users you want to track. Here’'s what the code might look like in general:

XMPPConnection con = new XMPPConnection("jivesoftware.com");
con.login("someuser", "somepassword");
// Create a packet filter to listen for all presence
// packets.
PacketFilter filter = new PacketTypeFilter(Presence.class);
con.addPacketListener(new PacketListener() {
    public void processPacket(Packet packet) {
        // Process presence packets and do logging.
}, filter);



is this still how this functionality would need to be conducted? just wondering because the last post on this thread is over a year old, and was thinking there might be a newer, easy way just to do a presence lookup given a user id.

like the original poster, i want to show the online/offline status of every user on a JSP page, so that someone can see if their friend is online, and then click a link to contact them (and if not, disable the link).

if i’‘m reading your post right, are you saying there should basically be one central user that has a giant roster of everyone in the system, and then based on that one user’'s roster, show the presence of other users? kind of like a superuser but used only for detecting presence?



Yep, a user that is subscribed to all the other user’‘s presences is what you’'d need. You might be able to customize a server to always return the presences for all users to a specific JID.