/UserPresenceTracker

Small browser JS component to track when user is inactive (abscent) for a given amount of time and when he is back

Primary LanguageJavaScript

UserPresenceTracker

Small browser JS component to track when user is inactive (abscent) for a given amount of time and when he is back. Written in TypeScript.

To use it get the download

/src/UserPresenceTracker.js

and


var tracker = new UserPresenceTracker.Tracker(window, onInactive , onActivityResume, timeoutMs, window.$);

All dependencies are passed throught the constructor.
window - global window object, will be used for timeout setting and addEventListener's if jQuery isn't present.
onInactive - a () => void funtion called when specifiend timeoutMs has passed without user activity
onActivityResume - a () => void function called when user is active again
timeoutMs - timoeut in milliseconds, if this amount of time passes without user activity - user is considered inactive
window.$ - jQuery library. If you are using evergreen browsers - code should work without it, for legacy - make sure you pass it.

Tesing and development

Make sure you install global cli tools for Grunt and Karma:


npm install grunt-cli -g
npm install karma-cli -g

To launch TypeScript compiler with watch use


grunt

If you don't use TypeScript, you can delete .ts files at any moment and continue working with the last .js transpilation result.

To launch unit tests with watch


karma start karma.conf.js
karma start karma-no-jQuery.conf.js