1.0.7 • Published 6 years ago

offline-timer v1.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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!")
  }
})
1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago