Do something when a timespan of no interaction passes. Straightforward; It sets a timeout that can be reset by internal eventListeners - or through the public API. When time passes your callback is executed.
- No permission needed unlike in Chrome's IdleDetector.
- EventListeners deal with common stopPropagation uses.
- After timeout, a next timeout with the same parameters can be set.
- Time passed since last activity available before and after timeout, until a (re)start.
- Event types causing a reset are configurable.
- Typescript
Install the package as npm package. Provided are a umd-formatted file in the dist folder to require or just read and an es-module in the module folder to import.
Start watching activity, waiting for inactivity. optional replace standard events to watch:
let interval = 120000 // 20 minutes
let callback = function () {
if (window.alert('Ready to resume?')) {
inactivityListener.restart()
}
}
let events = ['touchstart', 'pointerdown']
inactivityListener.start(interval, callback[, events])
Reset timer when ticking:
inactivityListener.reset()
Report inactivity, in milliseconds:
let inactiveTime = inactivityListener.lapse
Resume listening after timeout:
inactivityListener.restart()
Remove listeners, clear timer:
inactivityListener.stop()
.../inactivity-listener/demo/inactivityListener.html