Socket
Socket
Sign inDemoInstall

connection-state

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connection-state

Detect online and offline network state.


Version published
Maintainers
1
Created
Source

Connection state npm npm type definitions

Detect online and offline network state.

You can see it in action here filipchalupa.cz/connection-state. Try to disconnect your device from the internet after loading the page.

Installation

npm install connection-state

Usage

import { connectionState } from 'connection-state'

const connection = connectionState()

console.log(`You are ${connection.getState()}.`)
// connection.getState() returns 'online' or 'offline'

connection.addListener((state) => {
	console.log(`Your connection state has changed. You are now ${state}.`)
})
// state is 'online' or 'offline'

Endpoints

You can specify endpoints to check if you are online. The library will try to fetch the endpoints. If it succeeds, you are online. If it fails, you are offline.

const connection = connectionState({
	endpoints: ['https://www.google.com'],
})

Development

  • Install dependencies: npm ci
  • Run: npm run dev

Keywords

FAQs

Package last updated on 10 May 2023

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