How do you determine what client software a user logged on with (such as spark, sparkweb, gaim, pidgin, etc)? So in the admin console under the “sessions” tab, it states next to each logged on user what client they’re using. How do I access that info from a plugin?
Thanks for any help…
Hello,
The sessions tab actually shows what resource the client is using, which might not necessarily be the same as the client they’re using (most clients default to their name). So, I could have signed in using Spark but I could have my resource set to “office”.
The client type/version is not stored anywhere so you’ll either have to collect it each time a user logs in or send a iq packet to the client when you want to get it. In the case of the former, I would suggest you look at the source to the Client Control plugin and the SparkManager class and in the case of the latter look at the Version class in Smack.
Hope that helps,
Ryan
OK, that makes sense (resource not necessarily the name of the client software). Is there a way to pull whatever resource the user has currently specified from Openfire using an Openfire plugin? My scenario is that I need to do something specific (insert a translation into chat packets) whenever the receiving user isn’t using a specific resource (in this case “Spark”). Psuedocode:
if(destinationUser.currentResource != “Spark”){ // <–need to figure out how to do this
insert translation
else
let it through normally
Hope that clears up what I’m trying to do, and thanks for the quick reply…
Hello,
Sure, you can pull the information a couple of different ways. If you’re using a packet interceptor you can do something like the following:
private class MyPacketInterceptor implements PacketInterceptor {
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException { if (processed && packet instanceof Message) {
Message msg = (Message) packet; String fromResource = msg.getFrom().getResource();
}
}
}
Hope that helps,
Ryan
For everyone keeping track at home I should point out that there is acutally an easier way to get the resource info than the smack based approach I mentioned above. A better way would probably be to do something like:
SessionManager manager = XMPPServer.getInstance().getSessionManager();
Collection<ClientSession> sessions = manager.getSessions("bob");
for (ClientSession session : sessions) {
String theResource = session.getAddress().getResource();
}