1.0.2 • Published 4 years ago

online-status-event v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

online-status-event

Wrapper around window.navigator.onLine to let you know when your network is up or down.

Install

$ npm online-status-event

Usage

import { isOnline, start, stop } from 'online-status-event'

function handleOnlineStatus (status) {
    if (status) {
        // do something if online
    } else {
        // do something if offline
    }
}

// Manual check if the status is online or offline
handleOnlineStatus(isOnline())

// Listen to status changes and handle it accordingly
const statusEvent = start()
statusEvent.on('status', handleOnlineStatus)

API

Functions

FunctionArgumentsReturnsDescription
isOnlinenonebooleanChecks network status
startnoneobjectStarts listening to status changes
stopnoneobjectStops listening to status changes

Events

NameParamsDescription
statusstatus(boolean)Emits a status event with one boolean param value to indicate network status

License

MIT Copyright (c) 2019 John Nguyen