How to track perspective sessions from my Perspective module

Using the ClientHook for Vision components, our module can be notified whenever a new vision client is launched and we do store some audit information for each vision client through ClientHook.

On the similar lines, is there an API using which our perspective module could be notified of Perspective Client/Session launches ?

I believe it has to be done in the Gateway Hook however I could not see any interface which we could implement in order to be able to monitor the Perspective Session.

Appreciate help in this regard.

This may be what you're looking for:

There is no backend method that would allow you to do this via listeners, at least for now; Perspective is (by design) a much better encapsulated module, rather than requiring various platform-level additions like Vision does/did.

I think that if you made your own module that was ‘dependent’ upon the Perspective module, we’ll put your module in the appropriate classloader, and you would then be able to call PerspectiveContext.get(<gateway context>), where you could register with the Guava EventBus and subscribe to com.inductiveautomation.perspective.gateway.event.SessionStartupEvent events.

2 Likes

Thank you.

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