Component needs to know when user is not online anymore

Hello,

I have a component that manages user groups,

This component should be able to listen for “connection closed events” (say, a user closes the sparkweb browser window) and change the user group.

As it seems the components have no Roster, how can the component listen for connections closed ?

Tx!

joao

Hi Joao,

The best approach would be for your component to use a SessionEventListener to listen for sessionDestroyed events.

Hope that helps,

Ryan

Tx Ryan!! perfect solution.

Heres my implementation in case its useful to anybody:

First coded the SessionEventListener interface implementation

package com.vilt.openfire.plugin;

import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.session.Session;

import org.jivesoftware.openfire.event.SessionEventListener;

public class ViltSessionEventListener implements SessionEventListener {

public void sessionDestroyed(Session session) {
    Log.info("A client session was DESTROYED:" + session.getAddress().toBareJID() );
}

public void anonymousSessionCreated(Session session) {
    Log.info("A client ANONYMOUS session was CREATED:" + session.getAddress().toBareJID() );
}

public void anonymousSessionDestroyed(Session session) {
    Log.info("A client ANONYMOUS session was destroyed:" + session.getAddress().toBareJID() );
}

public void resourceBound(Session session) {
    Log.info("Resource bound");
}

public void sessionCreated(Session session) {
    Log.info("A client session was CREATED:" + session.getAddress().toBareJID() );
}

}//ViltSessionEventListener

Then added the listener to my Component/Plugin using the SessionEventDispatcher class ans passing a instance of my SessionEventListener implementation(inited in the component constructor)

SessionEventDispatcher.addListener(viltSessionEventListener);