Giter VIP home page Giter VIP logo

sleep-tracker-js's Introduction

sleeper-tracker-js

Sleep tracker JS is a component for tracking user inactivity on a web application. This component manages several pages opened

Get started

const sleepTrackerInstance = sleepTracker({
    timeout: 60, // in minutes, By default is 30 minutes
    delayCallAwake: 10
});
sleepTrackerInstance.on("beforeasleep", function() {
    // Your code to open modal to ask if user is awake ! If ok call sleepTrackerInstance.awake();
});
sleepTrackerInstance.on("awakened", function() {
    // Your code after user indicate on other page he awake. If modal is open, you can close it
});
sleepTrackerInstance.on("awake", function() {
    // Your code to execute after to indicate to the server user is awake
});
sleepTrackerInstance.on("asleep", function() {
    // Your code to execute because user is asleep. example logout, black screen, ...
});

CDN

You can use this CDN link

<script src="https://cdn.jsdelivr.net/gh/GBonnaire/sleep-tracker-js@latest/dist/sleeptracker.min.js"></script>

NPM

npm install @guillaumebonnaire/sleep-tracker-js

import sleepTracker from '@guillaumebonnaire/sleep-tracker-js';

Documentation

Options of component

Option name Description Type Default Value
timeout time out when user is considered comme asleep. In minutes int 30
timeoutBeforeAsleep Minutes before time out when application ask if user is awake. In minutes int 2
detectActivity If component detect activity like keydown, scroll, focus boolean true
delayCallAwake Delay between 2 trigger event "awake". In minutes int 5
keyStorage Key used to store data in localStorage string based on hostname
onload on load event function (Object: component) null
oninit on init event function (Object: component) null
debug debug mode, verbose all event triggered on console boolean false

functions of component

Function name Description Syntax Return
on Function to defined a function triggered by the component on(String: event, Function: callback) avoid
asleep Function to indicate user is asleep asleep() avoid
wakeup Function to indicate user is wakeup wakeup() avoid
awake Function to indicate user is awake awake() avoid
isAwake Function to check if user is awake isAwake() boolean

Events of component

Event name Description Syntax
asleep Triggered when user is asleep function (Object: component)
beforeasleep Triggered some minutes before time out will be trigger function (Object: component)
wakeup Triggered when user is wakeup (before asleep) function (Object: component)
awake Triggered when user is awake (activity) function (Object: component)
awakened Triggered when user is awakened (trigger is beforeasleep is triggered) function (Object: component)
init Triggered when component is init function (Object: component)
load Triggered when component is loaded function (Object: component)

sleep-tracker-js's People

Contributors

gbonnaire avatar

Stargazers

 avatar

Watchers

 avatar

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.