Skip to content

ganapativs/netinfo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

netinfo

Get network connection details of device in browser using navigator.connection API.

This package uses Expanded Network API and currently supported in latest version of chrome.

MIT Licence Open Source Love

Dependency Status devDependency Status

npm version GitHub version Bower version

Installation

  • NPM
npm install netinfo
  • Yarn
yarn add netinfo

Usage

import getNetInfo from 'netinfo';
// Other options ;)
// let getNetInfo = require('netinfo');
// <script src="./minified/index.js"></script>

/** 
* Calling `getNetInfo()` returns current network connection details of device as object
* {
*   downlink: 6.4,
*   downlinkMax: Infinity,
*   effectiveType: "4g",
*   rtt: 350,
*   type: "wifi"
* }
*/
const currentNetInfo = getNetInfo();

// Optionally you can listen to net info changes
// This callback will be called when there is change in net info
let onNetInfoChange = (newNetInfo) => {
    // Do something here
};
currentNetInfo.addChangeListener(onNetInfoChange);
// Somewhere later in code, Remove net info change listener callback
currentNetInfo.removeChangeListener(onNetInfoChange);

License

MIT © Ganapati V S

forthebadge forthebadge

Releases

No releases published

Packages

No packages published