Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

offline-timer

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

offline-timer

Dead simple plugin showing how long user is offline.

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 02 Apr 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc