-
Notifications
You must be signed in to change notification settings - Fork 196
Idle and Idleprovider
Idle
, once watch()
is called, will start a timeout which if expires, will enter a warning state countdown. Once the countdown reaches zero, idle
will broadcast a timeout event indicating the user has timed out (where your app should log them out or whatever you like). If the user performs an action that triggers a watched DOM event that bubbles up to document.body
, this will reset the idle/warning state and start the process over again.
The following methods can be used to configure Idle
:
-
interrupt(events) (
string
, default'mousemove keydown DOMMouseScroll mousewheel mousedown'
): These are the DOM events the service will watch to reset the idle timeout. Multiple events should be separated by a space. Note: Prior to v1.0, this method is calledactiveOn
. -
idle(seconds) (
integer
, default is 20min): The idle timeout duration in seconds. After this amount of time passes without the user performing an action that triggers one of the watched DOM events, the user is considered idle. Note: Prior to v1.0, this method is calledidleDuration
. -
timeout(seconds) (
integer
, default is 30s): The amount of time the user has to respond (in seconds) before they have been considered timed out. Set to0
orfalse
to disable this feature, if you wantIdle
to nothing but detect when a user is idle or not forever. Note: Prior to v1.0, this method is calledwarningDuration
, and could not be disabled; it always had to have a positive integer value. -
autoResume(string) (default is
idle
): Possible values areoff
/false
,idle
/true
, ornotIdle
. Whentrue
oridle
, user activity will automatically interrupt the warning countdown and reset the idle state. Iffalse
oroff
, you will need to manually callwatch()
when you want to start watching for idleness again. IfnotIdle
, user activity will only automatically interrupt if the user is not yet idle. -
keepalive(enabled) (
boolean
, default istrue
): Whentrue
, theKeepalive
service is automatically stopped and started as needed.
-
running(): returns whether or not the
watch()
has been called and it is watching for idleness. - idling(): returns whether or not the user appears to be idle.
- watch(): starts watching for idleness, or resets the idle/warning state and continues watching.
- unwatch(): stops watching for idleness, and resets the idle/warning state.
-
setIdle(int) (new: v1.0.0): updates the idle value (see
IdleProvider.idle()
above) and restarts the watch if its running. -
setTimeout(int) (new: v1.0.0): updates the timeout value (see
IdleProvider.timeout()
above) and restarts the watch if its running. - getIdle() (new: v1.1.0): gets the current idle value.
- getTimeout() (new: v1.1.0): gets the current timeout value.
The events Idle
watches are configurable. It is important to note that if the watched user events are prevented from bubbling up, Idle
will not be reset and thus not work properly. Usually this is not a problem.
By default, Idle
will start Keepalive
when watch()
is called, and stop it when unwatch()
is called. It will also stop Keepalive
when the user goes idle, and start when they return. It will immediately ping once when they return, and then resume on the usual Keepalive
interval after that.