Socket
Socket
Sign inDemoInstall

offline-timer

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    offline-timer

Dead simple plugin showing how long user is offline.


Version published
Weekly downloads
8
Maintainers
1
Install size
3.82 kB
Created
Weekly downloads
 

Readme

Source

License: MIT

Offline timer

Simple plugin for PWA showing how long user is offline (in miliseconds)

Installation

npm install offline-timer --save

API

  • getTime() returns:
    • if user is online - 0
    • if user is offline - how long user is offline (or since entering the website if he was offline when entering it) in miliseconds
  • notify(intervalInMs) when user goes offline it emits an offlineTimer event in a defined interval (e.g. every 2 sec). Sometimes with 1-2 miliseconds delay.

Usage examples

Get the information how long user was offline after coming back online:

import offlineTimer from 'offline-timer'

window.addEventListener('online', function () {
    console.log(offlineTimer.getTime())
})

Shows an alert after user is offline for 5 sec:

import offlineTimer from 'offline-timer'

const interval = 5000

offlineTimer.notify(interval)

window.addEventListener('offlineTimer', function () {
  const timeOffline = offlineTimer.getTime()

  if (timeOffline >= interval && timeOffline < 2*interval) {
      alert("You are offline for 5 seconds!")
  }
})

Keywords

FAQs

Last updated on 02 Apr 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc