This is a react-native library for tracing close contact between 2 mobile devices by exchanging ephemeral tokens over BLE (Bluetooth Low Energy).
The library will do the following:
- Advertise message with specific service_uuid and generated ephemeral token
- Scan for for BLE signals with a specific service_uuid and store the relevant scanned data into local device storage
- Provide simple API for JS to init these tasks in background and retrieve the scanned tokens
- Integrate with a module that will provide ephemerally encrypted tokens (might be optional part of the lib)
There is a chance this lib will be updated after Google & Apple will release the full Contact Tracing API solution.
- iOS limitation of using ble while the app in the background - linkÂ
- Estimate the distance between 2 devices without violating user's privacy, using the data we can send over the ble
Functionality | Android | iOS |
---|---|---|
Scan in foreground | âś… | âś… |
Advertise in foreground | âś… | âś… |
Scan in background | âś… | TODO |
Advertise in background | âś… | TODO |
Save scanned data into local DB | âś… | âś… |
Return scanned data to JS | âś… | âś… |
Pass scannng & advertising configuration from JS (intervals..) | âś… | âś… |
Integration with tokens provider | TODO | TODO |
Tests | TODO | TODO |
Features for rssi calibration (GPS, Proximity) | WIP | TODO |
The Example project can be used as a reference of how to use the rn-contact-tracing API and as a helpful tool to fine-tune the scanning/advertising configuration
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
yarn add rn-contact-tracing
or
npm install rn-contact-tracing --save
Android - Steps to manually link the library
include ':rn-contact-tracing'
project(':rn-contact-tracing').projectDir = new File(rootProject.projectDir, '../node_modules/rn-contact-tracing/lib/android')
dependencies {
...
implementation project(":rn-contact-tracing")
}
On top, where imports are:
import moh.gov.il.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());
...
);
}
- iOS 10+
- Android API 21+
setConfig
getConfig
startBLEService
stopBLEService
startBLEScan
stopBLEScan
startBLEAdvertise
stopAdvertise
getScansByKey
getAllDevices
exportAllScansCsv
exportAllDevicesCsv
cleanDevicesDB
cleanScansDB
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 milisecscanInterval
- the time in milisec between every scanadvertiseDuration
- advertising duration in milisec (up to 180000ms)advertiseInterval
- the time in milisec between every advertisingtoken
- temporary token to advertise (for testing)
For Android
advertiseTXPowerLevel
- advertise TX power level docsscanMatchMode
- match mode for Bluetooth LE scan filters hardware match docsnotificationTitle
- the title of the foreground service notificationnotificationContent
- the content of the foreground service notification
SpecialBle.getConfig((config) => {
....
})
Gets the scanning & advertising configuration options that are currently defined in the library
SpecialBle.startBLEService(config);
Starts BLE background task scanning for a specific - config is optional
SpecialBle.stopBLEService();
Stops the background service and all the tasks the service executing
SpecialBle.startBLEScan(config);
Starts BLE scanning in foreground - config is optional
SpecialBle.stopBLEScan();
Starts BLE scanning
SpecialBle.advertise(config);
Starts BLE advertising in foreground - config is optional
SpecialBle.stopAdvertise();
Stops BLE advertising
SpecialBle.getScansByKey(token, (scans) => {
...
})
Get list of scans events for a specific token, each object contains:
scan_id
- unique idscan_timestamp
- epoch time of the scan event inpublic_key
- token keyscan_address
- scaned device addressscan_rssi
- rssi strengthscan_tx
- tx strengthscan_protocol
- the protocol used to scan the data (currently GAP/GATT)
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 eventdevice_last_timestamp
- epoch time of the last scan eventpublic_key
- token keydevice_address
- scaned device addressdevice_rssi
- rssi strongest valuedevice_tx
- tx strongest valuedevice_protocol
- the protocol used to scan the data (currently GAP/GATT)
SpecialBle.exportAllScansCsv();
Export the full Scans events DB to csv file
SpecialBle.exportAllDevicesCsv();
Export the full Devices DB to csv file
SpecialBle.cleanDevicesDB();
Clear all scanned devices
SpecialBle.cleanScansDB();
Clear all scans
scanningStatus
- event can be true/falseadvertisingStatus
- event can be true/falsefoundDevice
- event has 2 params: {event.device_name, event.device_address}error
- {event.error_message}
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
TBD