Socket
Socket
Sign inDemoInstall

rn-hardware-info

Package Overview
Dependencies
0
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rn-hardware-info

A backend API that retrieves peformance information of hardware to React Native Apps


Version published
Weekly downloads
1
decreased by-50%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

RN-Hardware-Info

For Android

Installation

  • Add the following dependency to package.json: "rn-hardware-info": "TobyX-Corp/RN-Hardware-Info#master"

  • Run npm install in the project directory

Mostly automatic installation(autolinking from RN 0.60 and later versions)

$ react-native link rn-hardware-info

How to use

import RnHardwareInfo from 'rn-hardware-info';

Check and Request Permissions:

Wifi Usage Permission:

MainView.checkWifiUsagePermission((permsn_cb) => {
  #TODO
})

Getting Data

// get cpu frequency
RnHardwareInfo.getDeviceCpuFreqNow((cpu_cb) => {
  #TODO
})
// get ram usage
RnHardwareInfo.getDeviceMemInfo((ram_cb) => {
  #TODO
})
// get battery temperature
RnHardwareInfo.getBatteryTemperature((temp_cb) => {
  #TODO
})
// get network stats
RnHardwareInfo.getNetworkStats((down_cb, up_cb) => {
  #TODO
})

For IOS

Installation

  • Add the following dependency to package.json: "rn-hardware-info": "TobyX-Corp/RN-Hardware-Info#master"

  • Run npm install in the project directory

  • Run pod install in the ios directory

Mostly automatic installation(autolinking from RN 0.60)

$ react-native link rn-hardware-info

How to use

RnHardwareInfo.getAppUsage((error, usage) => {
  if (error) {
    console.log(error);
  } else {
    console.log(usage.cpu_usage);
    console.log(usage.memory_usage);
    console.log(usage.download_speed);
    console.log(usage.upload_speed);
  }
});

Example

import React, {useState, useEffect} from 'react';
import RnHardwareInfo from 'rn-hardware-info';

//Display hardware info eg. cpu
const DeviceInfo = () => {
  const [cpu, setCpu] = useState('0');

  useEffect(() => {
    const interval = setInterval(() => {
      if (RnHardwareInfo != null) {
        RnHardwareInfo.getAppUsage((error, usage) => {
          if (error) {
            console.log(error);
          } else {
            console.log('get app usage');
            console.log(usage);
            setCpu(usage.cpu_usage);
          }
        });
      }
    }, 1000);
    return () => clearInterval(interval);
  }, []);
  
  return (
    <View style={styles.container}>
      <Text> CPU Usage: {cpu}%</Text>
    </View>
  );
};

Keywords

FAQs

Last updated on 25 Oct 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc