Activity Monitoring is the feature that monitors any user interaction and signals the server to reset session timeout based on any activity. Activity Monitoring works out of the box for Hx (including HTML5) and is built into Velocity and Mobile profiles and can be accessed via utility methods.
The system will automatically logoff a user if there has not been any interaction for a certain amount of time.
For more information on Velocity check out the Activity Monitoring section here Apache Velocity
The Activity Monitor can be paused in cases where a view may have to stay online permanently. An example is a dashboard that keeps reporting out changing data of a system. There is really no interaction here but provides timely visual feedback of a system. In such cases, the Activity Monitor can be paused and the session kept alive for as long as the view is open. Every call to keep the view alive returns a token that can be released when pausing is no longer needed. Based on the type of view there are different approaches to pausing the Activity Monitor.
For Bajaux widgets a convenient mixin is available that does the setup and release automatically. In the example below, calling the mixin inside a widget’s constructor immediately pauses the monitor and releases the keep alive token when the widget is destroyed.
var MyWidget = function MyWidget() {
Widget.apply(this, arguments);
//Keeps the widget alive and releases the token in the widget's doDestroy.
activityMonitor.mixinKeepAlive(this);
};
The example below shows how to typically use Activity Monitor to keep a view alive and release the token to restart monitoring. The example below could apply to a HxView that loads in a javascript file that does all the view related work. Note that if destroy in the example below is called when the view is unloaded then it is not necessary to call release. However, if for example, this view is loaded as a widget on a px view that has other widgets, then it is important to release the token.
var MyView = function MyView(){
var that = this;
activityMonitor.keepAlive()
.then(function(t){
that.token = t; //Get the token
});
};
MyView.prototype.destroy = function(){
return activityMonitor.release(this.token);
};
Note: Sometimes a view may have multiple widgets calling keepAlive on the Activity Monitor. In such cases it is important that each widget releases its keepAlive token when it is destroyed. When all tokens are released, monitoring will start automatically.
There may be cases where a view outside of a working profile, say any HTML file served off of a station, needs auto logoff support.
The example below includes the Activity Monitor script and starts after the HTML document has loaded. As long as there is user interaction (mouse click, scroll, keyboard actions, etc) within the configured session expiry time, the user will not be automatically logged out.
<!DOCTYPE html>
<!-- @noSnoop -->
<html>
<head>
<title>This is a Sample HTML</title>
<script type='text/javascript' src='/module/web/rc/util/activityMonitor.js'></script>
<script>
function startMonitor(){
window.activityMonitor.start();
}
</script>
</head>
<body onload="startMonitor()">
<h1>This page has user activity monitoring enabled</h1>
</body>
</html>
Note: Including the activityMonitor script will attach it to the global window object.
The example below shows how to pause Activity Monitoring on any HTML file.
<!DOCTYPE html>
<!-- @noSnoop -->
<html>
<head>
<title>Dashboard</title>
<script type='text/javascript' src='/module/web/rc/util/activityMonitor.js'></script>
<script>
function keepViewAlive(){
window.activityMonitor.keepAlive();
}
</script>
</head>
<body onload="keepViewAlive()">
<h1>I am a dashboard and I am always on</h1>
</body>
</html>
Note: IE11 does not natively support the Javascript Promise API. To ensure Activity Monitoring works well in IE, include either of the scripts here in your HTML file. Note that promise.min.js provides a lightweight minimum Promise compatibility while bluebird.min.js is a more full-fledged Promise API implementation. The lightweight version is enough to get the Activity Monitor working without any issues.
<!-- @noSnoop --><script type='text/javascript' src='/module/js/rc/polyfills/promise/promise.min.js'></script>
<!-- @noSnoop --><script type='text/javascript' src='/module/js/rc/bluebird/bluebird.min.js'></script>
Sometimes an operation might take a long time to execute and there is a progress bar indicating it. The user in such cases might have no option but to just wait until it is finished. To make the Activity Monitor not accidentally log the user off, it is possible to call keepAlive() when the operation starts, followed by a release(token) when it ends. See example below.
function longRunningTask() {
return new Promise(function (resolve, reject) {
//Do something long running
resolve();
});
}
var token;
activityMonitor.keepAlive()
.then(function(keepAliveToken){
token = keepAliveToken;
return longRunningTask();
})
.then(function(){
activityMonitor.release(token); //release the token when the task is done
})
.catch(function () {
if(token){
activityMonitor.release(token); //release the token if task fails
}
});
If you have a servlet, and each request made to it should be considered user activity, you can add the UserActivityFilter to your servlet. You should only use this method if, for some reason, you cannot use the activity monitor. To set the UserActivityFilter on your servlet, add the following to your web.xml file.
<filter>
<filter-name>myServletUserActivityFilter</filter-name>
<filter-class>javax.baja.web.filters.UserActivityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myServletUserActivityFilter</filter-name>
<servlet-name>myServlet</servlet-name>
</filter-mapping>
Copyright © 2000-2019 Tridium Inc. All rights reserved.