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-jarvis-template-app-sdk

v1.2.2

Published

test

Downloads

26

Readme

Jarvis Template Sdk

Features:

  • Locating proximity push

Installation


yarn add react-native-jarvis-template-app-sdk
npm install react-native-jarvis-template-app-sdk

Auto linking when using React Native >= 0.60

Setup


Android

Steps to setup in Android

1. Register permissions and Service in AndroidManifest.xml.

Example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.jarvisappsdktest">

  <!-- Require android phone supports Bluetooth Low Energy -->
  <uses-feature
    android:name="android.hardware.bluetooth_le"
    android:required="true" />

  <!-- Required permissions -->
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />

  <application
    android:name=".MainApplication">
    <!-- Your code -->

    <!-- Register SDK service here -->
    <service
      android:name="com.reactnativejarvistemplateappsdk.services.BleScannerService"
      android:exported="false"
      android:foregroundServiceType="location|dataSync" />
  </application>
</manifest>

2. Request permissions in your app

This is just example to request permissions at first access. You can build as you wish but just make sure all the following permissions is allowed before using SDK

function App() {

  const requestPermission = async (): Promise<void> => {
    if (Platform.Version >= 31) {
      if (!(await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN))) {
        await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
          {
            title: 'Bluetooth Scan Permission',
            message: 'To Run SDK',
            buttonNeutral: 'Ask Me Later',
            buttonNegative: 'Cancel',
            buttonPositive: 'OK',
          },
        );
      }
    }

    if (!(await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION))) {
      await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
        {
          title: 'Access Fine Location',
          message: 'To Run SDK',
          buttonNeutral: 'Ask Me Later',
          buttonNegative: 'Cancel',
          buttonPositive: 'OK',
        },
      );
    }

    if (!(await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION))) {
      await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
        {
          title: 'Access Coarse Location',
          message: 'To Run SDK',
          buttonNeutral: 'Ask Me Later',
          buttonNegative: 'Cancel',
          buttonPositive: 'OK',
        },
      );
    }

    if (!(await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION))) {
      await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,
        {
          title: 'Access Background Location',
          message: 'To Run SDK',
          buttonNeutral: 'Ask Me Later',
          buttonNegative: 'Cancel',
          buttonPositive: 'OK',
        },
      );
    }
  };

  useEffect(() => {
    requestPermission();
  }, []);

  return (
    <SafeAreaView style={backgroundStyle}>
      /* Your Code Here */
    </SafeAreaView>
  )
}

Second, it requires internet connected, please handle it at your side before call startScanService

Finally, make sure bluetooth service is enabled, please handle it at your side before call startScanService

3. Start and Stop SDK

How to run SDK service:

// import sdk functions
import {
  startScanService,
  stopScanService,
  BeaconInfo,
  NotificationInfo
} from 'react-native-jarvis-template-app-sdk';

function App() {

  const startJarvisSdk = async (): Promise<void> => {
    // please check all permissions allowed before start sdk
    // for example:
    const locGranted = await PermissionsAndroid.check(
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
    );
    if (!locGranted) {
      return;
    }

    // Get SDK Key from your Jarvis Account
    // Note:
    // Don't expose your sdk key in the code as below. This is just example.
    // Retrieve it through your own api instead
    const SDK_KEY = 'xxx';

    // SDK configuration
    const locatingRange = 3;
    const notificationIconFileName = 'ic_launcher_round';
    const foregroundServiceNotificationTitle = 'Jarvis SDK';
    const foregroundServiceNotificationDescription = 'We are running foreground service...';

    const onProximityPush = (device: BeaconInfo, notification: NotificationInfo, time: string) => {
      console.log(device, notification, time);
    };

    // startScanService to start sdk service in foreground
    const success = await startScanService(
      SDK_KEY,
      locatingRange,
      notificationIconFileName,
      foregroundServiceNotificationTitle,
      foregroundServiceNotificationDescription,
      onProximityPush
    );

    console.log('startJarvisSdk', success);
  };

  const stopJarvisSdk = async (): Promise<void> => {
    // stopScanService to stop foreground service
    await stopScanService();
  };

  return (
    <SafeAreaView style={backgroundStyle}>
      <Button title="START" onPress={startJarvisSdk} />
      <Button title="STOP" onPress={stopJarvisSdk} />
    </SafeAreaView>
  )
}

Methods


startScanService(sdkKey, locatingRange, notificationIconResourceName, notificationTitle, notificationDescription)

To start sdk service in foreground. It will start only one service task in foreground even when you trigger this method multiple times.

Arguments

  • sdkKey : string | Your account SDK Key
  • locatingRange : number | Range threshold for locating beacon. If you set 3, it means only detect beacon within 3 meters
  • notificationIconResourceName : string | Name of resource file for Foreground Notification Icon. The icon should be under mipmap type.
  • notificationTitle : string | Set title for Foreground Notification
  • notificationDescription : string | Set description for Foreground Notification
  • onProximityPush : (device: BeaconInfo, noti: NotificationInfo, time: string) => {} | Callback method for proximity push

stopScanService

To stop the running sdk service when no use.

Please remember to stop it when no longer use otherwise it causes your battery drain.

getServiceStatus()

To retrieve all current information from running service

Response

type JarvisServiceStatus = {
  lastDetectedSignalDateTime: number;
  serviceRunning: boolean;
  beacons: ServiceBeaconInfo[];
};
  • lastDetectedSignalDateTime: timestamp when running service get last signal from any devices found nearby inside locating range
  • serviceRunning: flag to know whether service is still running in background
  • beacons: list of devices found and notified and still received readings, when you are out of locating range for 1 minute, the device will be removed from the list

License


MIT