# How to track perspective sessions from my Perspective module

**URL:** <https://forum.inductiveautomation.com/t/how-to-track-perspective-sessions-from-my-perspective-module/30724>\
**Category:** Module Development\
**Tags:** ignition80\
**Created:** [December 16, 2019, 7:47am UTC](https://forum.inductiveautomation.com/t/how-to-track-perspective-sessions-from-my-perspective-module/30724 "2019-12-16T07:47:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yogini\_Marathe](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@Yogini\_Marathe](https://forum.inductiveautomation.com/u/Yogini_Marathe)\
**Post date:** [December 16, 2019, 7:47am UTC](https://forum.inductiveautomation.com/t/how-to-track-perspective-sessions-from-my-perspective-module/30724/1 "2019-12-16T07:47:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [December 16, 2019, 11:57am UTC](https://forum.inductiveautomation.com/t/how-to-track-perspective-sessions-from-my-perspective-module/30724/2 "2019-12-16T11:57:45Z")

</div>

This may be what you're looking for:

> [@\[feature-14663\]Perspective Session Info](http://forum.inductiveautomation.com/t/feature-14663-perspective-session-info/29109/4):
>
> A new system.perspective.getSessionInfo function is now available in the 8.0.7 nightly. Thanks again for the suggestion @DavidWisely

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 16, 2019, 4:11pm UTC](https://forum.inductiveautomation.com/t/how-to-track-perspective-sessions-from-my-perspective-module/30724/3 "2019-12-16T16:11:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Yogini\_Marathe](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@Yogini\_Marathe](https://forum.inductiveautomation.com/u/Yogini_Marathe)\
**Post date:** [December 17, 2019, 5:57am UTC](https://forum.inductiveautomation.com/t/how-to-track-perspective-sessions-from-my-perspective-module/30724/4 "2019-12-17T05:57:10Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![Yogini\_Marathe](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@Yogini\_Marathe](https://forum.inductiveautomation.com/u/Yogini_Marathe)\
**Post date:** [December 17, 2019, 6:07am UTC](https://forum.inductiveautomation.com/t/how-to-track-perspective-sessions-from-my-perspective-module/30724/5 "2019-12-17T06:07:13Z")

</div>

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:

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

```

And below is listener class to handle the session events.

```auto
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
	}
	
}

```
