Add activity tracker
This commit is contained in:
40
js/plugin/activity.ts
Normal file
40
js/plugin/activity.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
export const ActivityMixin = (SuperClass) => {
|
||||
return class ActivityMixinClass extends SuperClass {
|
||||
activityTriggered = false;
|
||||
_activityCooldown = 15000;
|
||||
_activityTimeout;
|
||||
constructor() {
|
||||
super();
|
||||
for (const ev of ["pointerdown", "pointermove", "keydown"]) {
|
||||
window.addEventListener(ev, () => this.activityTrigger());
|
||||
}
|
||||
this.addEventListener("fully-update", () => {
|
||||
this.activityTrigger();
|
||||
});
|
||||
}
|
||||
|
||||
activityTrigger() {
|
||||
if (!this.activityTriggered) {
|
||||
this.sendUpdate({
|
||||
activity: true,
|
||||
});
|
||||
}
|
||||
this.activityTriggered = true;
|
||||
clearTimeout(this._activityTimeout);
|
||||
this._activityTimeout = setTimeout(
|
||||
() => this.activityReset(),
|
||||
this._activityCooldown
|
||||
);
|
||||
}
|
||||
|
||||
activityReset() {
|
||||
clearTimeout(this._activityTimeout);
|
||||
if (this.activityTriggered) {
|
||||
this.sendUpdate({
|
||||
activity: false,
|
||||
});
|
||||
}
|
||||
this.activityTriggered = false;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -9,6 +9,7 @@ import { RequireInteractMixin } from "./require-interact";
|
||||
import { FullyMixin } from "./fullyKiosk";
|
||||
import { BrowserStateMixin } from "./browser";
|
||||
import { ServicesMixin } from "./services";
|
||||
import { ActivityMixin } from "./activity";
|
||||
import "./popups";
|
||||
import { PopupMixin } from "./popups";
|
||||
import pjson from "../../package.json";
|
||||
@@ -59,11 +60,13 @@ import pjson from "../../package.json";
|
||||
*/
|
||||
export class BrowserMod extends ServicesMixin(
|
||||
PopupMixin(
|
||||
BrowserStateMixin(
|
||||
CameraMixin(
|
||||
MediaPlayerMixin(
|
||||
ScreenSaverMixin(
|
||||
FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))
|
||||
ActivityMixin(
|
||||
BrowserStateMixin(
|
||||
CameraMixin(
|
||||
MediaPlayerMixin(
|
||||
ScreenSaverMixin(
|
||||
FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user