goog.module('gep.provider.AutoResetProvider');
const {EventTarget} = goog.require('goog.events');
/**
* This provider (singleton) provides the possibility of an automatic reset of the application.
* After 7 minutes of inactivity, the page is reloaded so that the start can be seen again.
* Application case would be a display in an exhibition.
* By default this function is not active. It can be activated via the url parameter `autoreset=1`.
* @extends {EventTarget}
*/
class AutoResetProvider extends EventTarget
{
constructor()
{
super();
/**
* Timeout id reference
* @type {number}
* @private
*/
this.id_ = 0;
/**
* Time limit for inactivity
* @type {number}
*/
this.time = 7 * 60 * 1000;
/**
* Parameter that indicates whether the provider is enabled.
* @type {boolean}
*/
this.enabled = window['AUTORESET'] === 'on';
}
/**
* Starts a new monitoring period with the specified limit of inactivity.
*/
start()
{
if(this.enabled)
{
this.cancel();
this.id_ = setTimeout(() => {
window.location.reload();
}, this.time);
}
}
/**
* Stops the monitoring of inactivity. Useful if a longer inactivity of the user is to be foreseen, e.g. when watching a longer video.
*/
cancel()
{
if(this.enabled)
{
clearTimeout(this.id_);
}
}
}
goog.addSingletonGetter(AutoResetProvider);
exports = AutoResetProvider;