npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-connectivity-tracker

v2.0.4

Published

Checks wether the connection is valid

Downloads

153

Readme

react-native-connectivity-tracker

Why?

Because we can no longer trust that react-native connectivity changes are valid, so we have to double check before we trust the result. Here's the RN issue

How?

The only thing this library does is, whenever a network change event get's dispatched by NetInfo, we verify that the connection is alive by pinging google.

p.s: On production we verify by checking if our server is up (by overriding verifyServersAreUp) but you don't have to do that.

Versions:

  • react-native >= 0.58 --> react-native-connectivity tracker > 2.0.0
  • react-native < 0.58 --> react-native-connectivity tracker > 1.0.0

Installation:

yarn install react-native-connectivity-tracker

Extra steps on if you're using version >= 2.0.0 (not needed if on a previous version)

Either follow the instructions in the React Native documentation to manually link the framework or link using Cocoapods by adding this to your Podfile:

pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'

Make the following changes:

android/settings.gradle

include ':react-native-community-netinfo'
project(':react-native-community-netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android')

android/app/build.gradle

dependencies {
   ...
   implementation project(':react-native-community-netinfo')
}

android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.reactnativecommunity.netinfo.NetInfoPackage;

Add the NetInfoPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.asList(
            new MainReactPackage(),
            new NetInfoPackage()
    );
}

Usage:

import ConnectivityTracker from 'react-native-connectivity-tracker';

const onConnectivityChange = (isConnected, timestamp, connectionInfo) => {
    console.log(`isConnected: ${isConnected}, when: ${timestamp} more info: ${JSON.stringify(connectionInfo)}`)
    // connectionInfo is only available if attachConnectionInfo is set to true
}

ConnectivityTracker.init({
    onConnectivityChange,
    attachConnectionInfo: false,
    onError: msg => console.log(msg),
    // verifyServersAreUp: () => store.dispatch(checkOurServersAreUp()),
});

Params:

|Key | Type | Default | Definition | | --- | --- | ---- | ----------- | | onConnectivityChange | function(bool, Date, Object) | - | This is the main callback you should care about. It get's dispatched whenever there's a connectivity change. | | attachConnectionInfo | boolean | false | Attaches more details about the connection on the onConnectivityChange callback (3rd param) | | alsoVerifyOnlineStatuses | boolean | false | By default we only verify the connectivity whenever we receive an offline status. By turning this on we'll also verify online statuses too. | | dispatchOldEventsToo | boolean | false | By default we only dispatch the latest event we received from NetInfo. By turning this on we'll dispatch EVERYTHING. Caution, the order of events is not guaranteed if this is set to true. | | onError | function | - | Pass a function here if you want to log errors. | | verifyServersAreUp | function | - | This overrides the default verification method. Feel free to disregard this, unless want to use your own verification method, instead of relying to google responces. This function can return either a result (true or false) or a Promise |

Methods:

|Key | Definition | | --- | ----------- | | tryConnection | This is a tottally optional method that you can call when you wish to check for a connectivity status on demand. Returnes a promise.|