View Full Version : Detecting app activity for a 3rd party authentication server

12 Jan 2012, 5:19 AM
Under a single sign-on setup I need to periodically grab an image from an authentication server. Normally this is done as each page is loaded, but in this case there aren't multiple pages. How can I detect activity across the app, in order to update the auth server with activity (to keep the session from timing out).

I've thought about grabbing the image every time data is loaded, but this could result in the session timing out even though the user has been working with the grid full of data that didn't require server access. Also, there are 5 tabs with different kinds of interactivity, grids forms, etc. Some of that activity would result in XHRs, but not all of it, so I'm trying to find something that can worry about the whole interactivity problem outside of the actual app itself. Much like a screen saver watches over the use of anything on the desktop.

I guess I'm looking for clicks and keystrokes mostly, not sure what else to count as activity (at the moment).

How could you do this ext4

12 Jan 2012, 10:18 AM
Take a look at Ext.TaskManager. You can create a task to run on a specified interval and do whatever you want. I used Ext.TaskManager to create a session expiration checker task which alerts a user when they're within 60 seconds of a session timeout.

It works quite nicely.

In my case, I created a globally scoped 'sessionTask' object which has a 'lastActivity' property. I registered click events on the document object to reset the lastActivity date/time stamp, so each time the task ran, it would compare current datetime to the lastActivity datetime and decide what to do:

// Any user click resets the last activity time on the global session
// timeout task.
Ext.EventManager.on(document, 'click', function() {
myapp.global.sessionTask.lastActivity = (new Date()).getTime();

You could obviously add a 'keypress' listener on the document as well, to have keystrokes reset the lastActivity value. I thought that approach was too chatty, from an event standpoint, so I just stuck with clicks.

12 Jan 2012, 10:28 AM

Typically you would need to decide what constitutes an 'active session'.

It might be any time:

a) the user interacts with your service stack (Ajax)
b) the user causes a field to change focus
c) the user simply moves/clicks the mouse over/on the page
d) keyPress?

For any combination of the above, Class Observables (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.util.Observable-static-method-observe) and document-level listeners provide a centralized mechanism for monitoring such events without setting listeners on every component in your layouts.

These events may also be buffered (say a 5 minute threshold), permitting periodic interaction with your server's session/state manager. Couple that with a Task (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.TaskManager) that also runs every 5 minutes to see if anything has actually happened (else, react accordingly).