rnn

react-native-network-connection-class

React Native Android Bridge to Facebook's Network Connection Class

Showing:

Popularity

Downloads/wk

1

GitHub Stars

3

Maintenance

Last Commit

5yrs ago

Contributors

0

Package

Dependencies

0

License

Unlicense

Type Definitions

Tree-Shakeable

No?

Categories

Readme

React Native Network Connection Class

Android Bridge to Facebook's Network Connection Class

Network Connection Class is an Android library that allows you to figure out the quality of the current user's internet connection. The connection gets classified into several "Connection Classes" that make it easy to develop against.

NPM

Installation

1) npm i --save react-native-network-connection-class

or manually:
Add repository to package.json
"react-native-device-year-class": "git+ssh://git@github.com:manuelkch/react-native-network-connection-class.git"

2) Run
npm install

or manually:
git clone the directory to [node_modules/react-native-network-connection-class]

Add it to your react-native project

react-native link react-native-network-connection-class

or manually

  • In android/setting.gradle

    ...
    include ':react-native-network-connection-class'
    project(':react-native-network-connection-class').projectDir = new File(settingsDir, '../node_modules/react-native-network-connection-class/android')
    
    
  • In android/app/build.gradle

    ...
    dependencies {
        ...
        compile project(':react-native-network-connection-class')
    }
    
    
  • register module in MainApplication.java

      import com.ymc.NetworkConnectionClass.Package;  
      ...
    
      protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
                  new MainReactPackage(),
                  new Package() // <-- Add this line.
          );
      }
    

Example

...
import NetworkConnectionClass from 'react-native-network-connection-class'  
    ...
    //listen to connection class changes
    DeviceEventEmitter.addListener('connectionClassChange', function(e: Event) {
        // new state
    console.warn(e.state)
  })
    ...
    //get current class string (POOR, MODERATE,GOOD or EXCELENT)
    NetworkConnectionClass.getCurrentQuality().then((status) => {
        //current state
        console.warn(status)
    })
    ...
    //start/stop sampling bandwith data on newtork activities
    NetworkConnectionClass.startSampling()
    .fetch('https://jsonplaceholder.typicode.com/photos')
        .then(function(response) {
            NetworkConnectionClass.stopSampling()
            ...
    })
    ...
    // get boolean if sampling thread is running
    NetworkConnectionClass.getSamplingState().then((isSampling) => {
        console.warn(isSampling)
    })

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial