How to track perspective sessions from my Perspective module

Thank you for letting us know the way to subscribe to perspective session events.
I was able to use PerspectiveContext.get() and subscribe to the Perspective session listener.

Following is the code in gateway hook startup:

this.perspectiveContext = PerspectiveContext.get(this.gatewayContext);
this.perspectiveContext.getEventBus().register(new PerspectiveSessionListener());

And below is listener class to handle the session events.

import com.google.common.eventbus.Subscribe;
import com.inductiveautomation.perspective.gateway.event.SessionShutdownEvent;
import com.inductiveautomation.perspective.gateway.event.SessionStartupEvent;
public class PerspectiveSessionListener {
	
	@Subscribe
	public void sessionStarted(SessionStartupEvent startupEvent)
	{
        	//do session start event handling. All session props are available here.
	}
	
	@Subscribe
	public void sessionEnded(SessionShutdownEvent shutdownEvent)
	{
		//do session end event handling
	}
	
}
1 Like