Coder Social home page Coder Social logo

annexare / idledetect Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 0.0 70 KB

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

License: MIT License

TypeScript 100.00%
typescript idledetector timeout inactivity-timer cypress-tests

idledetect's Introduction

Idle Detect

IdleDetect Tests Monthly Downloads

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

Usage

npm install idle-detect
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()

idledetect's People

Contributors

dmythro avatar

Stargazers

 avatar  avatar

idledetect's Issues

IdleDetectIsomorph.js:39 Uncaught TypeError: (intermediate value).cleanupAndStop is not a function

When I block permission after 5 seconds and a timer times out, I got the error
image

setTimeoutConnection = async () => { 
  this.timeout = setTimeout(
      this.onInactive,
      CONNECTION_TIMEOUT
    )
  try {
    const idleDetect = new IdleDetect(
      CONNECTION_TIMEOUT / 1000, // Unit: Second
      this.onInactive
    )
    idleDetect.start()
    if ((await window.IdleDetector.requestPermission()) === 'granted') {
      if (this.timeout) {
        clearTimeout(this.timeout)
      }
    }
  } catch {
    // Ignore errors
  }
}

Chrome: Version 104.0.5112.101
Ubuntu: 20.04

It doesn't catch `screenState` on Ubuntu

It doesn't run this.handle() when I lock my screen

if (userState === UserIdleState.idle || screenState === ScreenIdleState.locked) {
    this.handleIdle();
}

OS: Ubuntu 20.04.4 LTS

Did you test it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.