active-detector
Detect whether browser user's active state.
Install
yarn add active-detector
Usage
Example
See demo here.
Quick Start
import { AD, USER_STATE, ActiveRange } from 'active-detector'
const ad = new AD({
inactiveThresh: 5000
})
ad.getState()
ad.ActiveRange()
ad.on('active', console.log('turn to active'))
ad.on('inactive', console.log('turn to inactive'))
Options
Configuration of active-detector.
constructor(options?: Partial<ActiveDetectorOptions>);
Add Listener
The callbacks will be invoked when user from inactive to active, or from active to inactive.
active-detector use tiny-emitter as the callback controller.
on: (action: USER_STATE, cb: Function) => void
off: (action: USER_STATE, cb: Function) => void
once: (action: USER_STATE, cb: Function) => void
Get Current State
Get current user state.
getState: () => USER_STATE;
Get Active Time Ranges
Get current active time ranges. The start/end time is an Unix timestamp.
getRanges: () => ActiveRange[];