An open API service indexing awesome lists of open source software.

https://github.com/annexare/idledetect

A TypeScript library for inactivity timer, which utilises `IdleDetector` API where possible or a fallback to `window.setTimeout` approach.
https://github.com/annexare/idledetect

cypress-tests idledetector inactivity-timer timeout typescript

Last synced: about 2 months ago
JSON representation

A TypeScript library for inactivity timer, which utilises `IdleDetector` API where possible or a fallback to `window.setTimeout` approach.

Awesome Lists containing this project

README

        

# Idle Detect

[![IdleDetect Tests](https://github.com/annexare/IdleDetect/actions/workflows/tests.yml/badge.svg)](https://github.com/annexare/IdleDetect/actions/workflows/tests.yml)
[![Monthly Downloads](https://img.shields.io/npm/dm/idle-detect.svg)](https://www.npmjs.com/package/idle-detect)

A TypeScript library for inactivity timer, which utilises [IdleDetector API](https://developer.mozilla.org/en-US/docs/Web/API/IdleDetector) where possible or a fallback to `window.setTimeout` approach.

## Usage

```bash
npm install idle-detect
```

```ts
import IdleDetect from 'idle-detect'
// Or, if you don't want to use still experimental IdleDetector API:
// import { IdleDetect } from 'idle-detect/dist/IdleDetect'

const onInactive = () => {
console.info('User is inactive now')
}
const idleDetect = new IdleDetect(15 * 60, onInactive)

// Start timer, e.g. when user is logged in
idleDetect.start()

// End timer, e.g. when user is logged out
idleDetect.cleanupAndStop()
```