end-user-activity-monitor
v1.0.0
Published
A library that detects when user becomes active or idle
Downloads
345
Maintainers
Readme
end-user-activity-monitor
EUAMonitor is a fast, lightweight and flexible library that detects when user becomes idle or active. Can be used as ES2015 module import or can be loaded with script tag.
Installation
npm i end-user-activity-monitor
Usage
ES2015 module import:
import { Agent } from "end-user-activity-monitor";
// ...
const activityDetectorAgent = new Agent({ idleInterval: 5000 });
//start activity monitoring
activityDetectorAgent.startMonitor();
//subscribe to activity changes: active/idle
activityDetectorAgent.activityObservable().subscribe(status => console.log("activity status:", status));
//stop activity monitoring after 30 secs
setTimeout(() => activityDetectorAgent.stopMonitor(), 30000);
The consumer also can use the library by loading it via a script tag:
<!DOCTYPE html>
<html>
...
<script src="dist/end-user-activity-monitor.js"></script>
<script>
//create activity detector agent which fires activity idle event if end user is not active for 5 seconds
const activityDetectorAgent = new EUAMonitor.Agent({ idleInterval: 5000 });
//start activity monitoring
activityDetectorAgent.startMonitor();
//subscribe to activity changes: active/idle
activityDetectorAgent.activityObservable().subscribe(status => console.log("activity status:", status));
//stop activity monitoring after 30 secs
setTimeout(() => activityDetectorAgent.stopMonitor(), 30000);
</script>
</html>
API
//create acrivity detector with idle interval in milliseconds
const agent = new EUAMonitor.Agent({ idleInterval: 5000 });
//start activity monitroing
agent.startMonitor();
//stop activity monitroing
agent.stopMonitor();
//subscribe to activity changes
agent.activityObservable().subscribe(status => console.log("activity status:", status));
//check if end user is active
agent.isActive();
//check if end user is idle
agent.isIdle();