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

rn-contact-tracing

v0.0.4

Published

React Native Library For Contact Tracing Over BLE (Bluetooth Low Energy) To Fight COVID-19 Pandemic

Downloads

8

Readme

CI

RN-Contact-Tracing

WIP Library - Don't Use in Production

About

This is a react-native library for tracing close contact between 2 mobile devices by exchanging tokens over BLE (Bluetooth Low Energy).

The library eventually will do the following:

  1. Advertise messages with specific service_uuid and generated token
  2. Scan for for BLE signals with a specific service_uuid and store the relevant data into local device storage
  3. Provide simple API for JS to init these tasks in background and retrieve the scanned tokens

This is temporary implementation until Google & Apple will release the full Contact Tracing API solution.

Working plan

Functionality | Andorid | iOS | :------------ | :-------------| :-------------| Scan in foreground | :white_check_mark: | :white_check_mark: | Advertise in foreground | :white_check_mark: | :white_check_mark: | Scan in background | :white_check_mark: | TODO | Advertise in background | :white_check_mark: | TODO | Save scanned data into local DB | :white_check_mark: | WIP | Return scanned data to JS | :white_check_mark: | TODO | Pass scannng & advertising configuration from JS (intervals..) | :white_check_mark: | TODO | Integration with tokens provider |TODO|TODO| Deal with permissions and reboot/app update |WIP|TODO| Tests |TODO|TODO|] Features for rssi calibration (GPS, Proximity) |WIP|TODO|

Getting started

How to run the example project

npm install
cd example/ios
pod install
For Android - npm run android 
For iOS - npm run ios

In Android - Click on Request Location Permission button

Installation

yarn add rn-contact-tracing

or

npm install rn-contact-tracing --save

android/settings.gradle

include ':rn-contact-tracing'
project(':rn-contact-tracing').projectDir = new File(rootProject.projectDir, '../node_modules/rn-contact-tracing/lib/android')

android/app/build.gradle

dependencies {
   ...
   implementation project(":rn-contact-tracing")
}

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

On top, where imports are:

import com.wix.specialble.SpecialBlePackage;

Add the RNLocationPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.asList(
            List<ReactPackage> packages = new PackageList(this).getPackages();
            ...
            packages.add(new SpecialBlePackage());
            ...
    );
}

Supported Platforms

  • iOS 10+
  • Android API 21+

Methods

Summary


Details

setConfig(config)

   SpecialBle.setConfig(config);

Sets configuration options that will be used in scanning & advertising tasks.

Parameters:

| Name | Type | Required | Description | | ------ | ------ | -------- | ----------- | | config | object | Yes | See below. |

Supported options:

  • serviceUUID - the ServiceUUID which identify the BLE broadcast you are going to advertise and scan for.
  • scanDuration - scanning duration in milisec
  • scanInterval - the time in milisec between every scan
  • advertiseDuration - advertising duration in milisec (up to 180000ms)
  • advertiseInterval - the time in milisec between every advertising

For Android

  • advertiseTXPowerLevel - advertise TX power level docs
  • scanMatchMode - match mode for Bluetooth LE scan filters hardware match docs
  • notificationTitle - the title of the foreground service notification
  • notificationContent - the content of the foreground service notification

getConfig(callback)

   SpecialBle.getConfig((config) => {
    ....
   })

Gets the scanning & advertising configuration options that are currently defined in the library


startBLEService(config)

SpecialBle.startBLEService(config);

Starts BLE background task scanning for a specific - config is optional


stopBLEService()

SpecialBle.stopBLEService();

Stops the background service and all the tasks the service executing


startBLEScan(config)

SpecialBle.startBLEScan(config);

Starts BLE scanning in foreground - config is optional


stopBLEScan()

SpecialBle.stopBLEScan();

Starts BLE scanning


advertise(config)

SpecialBle.advertise(config);

Starts BLE advertising in foreground - config is optional


stopAdvertise()

SpecialBle.stopAdvertise();

Stops BLE advertising


getScansByKey(token, callback)

 SpecialBle.getScansByKey(token, (scans) => {
    ...
 })

Get list of scans events for a specific token, each object contains:

  • scan_id - unique id
  • scan_timestamp - epoch time of the scan event in
  • public_key - token key
  • scan_address - scaned device address
  • scan_rssi - rssi strength
  • scan_tx - tx strength
  • scan_protocol - the protocol used to scan the data (currently GAP/GATT)

getAllDevices()

 SpecialBle.getAllDevices((devices) => {
       setDevices(devices)
   })

Get list of unique devices that were scanned, each object contains:

  • device_first_timestamp - epoch time of the first scan event
  • device_last_timestamp - epoch time of the last scan event
  • public_key - token key
  • device_address - scaned device address
  • device_rssi - rssi strongest value
  • device_tx - tx strongest value
  • device_protocol - the protocol used to scan the data (currently GAP/GATT)

exportAllScansCsv()

 SpecialBle.exportAllScansCsv();

Export the full Scans events DB to csv file


exportAllDevicesCsv()

SpecialBle.exportAllDevicesCsv();

Export the full Devices DB to csv file


cleanDevicesDB()

SpecialBle.cleanDevicesDB();

Clear all scanned devices


cleanScansDB()

SpecialBle.cleanScansDB();

Clear all scans


Events from Native to JS

  • scanningStatus - event can be true/false
  • advertisingStatus - event can be true/false
  • foundDevice - event has 2 params: {event.device_name, event.device_address}
  • error - {event.error_message}
Why did we build this lib?

Due to COVID-19 pandemic, several groups and health authorities released apps that will help to identify and notify people that are at risk of exposure.

Some of these apps are written with RN and based on tracking user location which is not enough such as Hamagen, and they willing to add BLE based functionality.

There are lots of great libs that expose ble functionality for RN, i.e react-native-ble-plx & react-native-ble-manager but we wanted reduce the amount of dependancies as much as possible and exectue very specfic BLE functionality in background.

In addition, we looked at several great apps written for the same purpose in native, but each one of them is not written in a way that we could use as a stand-alone library. OpenTrace) - includes the full business logic (UI..) that we don't want to use. DP^3T Project - include cryptography logic that we prefer to replace

Privacy (what do we advertise and save to DB)

TBD

Limitations

TBD

References

  • https://github.com/opentrace-community
  • ....