This module helps you detecting when the user becomes idle (does not interact with the page for some time) or active in your page.
$ npm install --save activity-detector
Or load it from unpkg:
;const activityDetector = ;activityDetector;activityDetector;
Activity detector allows you to configure some parameters:
timeToIdle: number of milliseconds of inactivity which makes activity detector transition to 'idle' (
activityEvents: the user events which make activity detector transition from 'idle' to 'active'. The default list of activityEvents is
['click', 'mousemove', 'keydown', 'DOMMouseScroll', 'mousewheel', 'mousedown', 'touchstart', 'touchmove', 'focus']
inactivityEvents: the list of events which make the activity detector transition from 'active' to 'idle' without waiting for
timeToIdletimeout. By default:
ignoredEventsWhenIdle: list of events to ignore in idle state. By default:
initialState: can be
truethe activity detector starts just after creation, when
false, it doesn't start until you call the
const activityDetector =;activityDetector;......// I want to start the activity detector now!activityDetector;
An activity detector instance has the following methods:
Initializes the activity detector in the given state. This method should only be used if you created the activity detector with the
This method receives the
initialState param. It can be
Registers an event listener for the required event
event can be
handler must be a function.
Stops the activity detector and cleans the listeners.
$ npm install$ npm test