Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
react-native-ble-advertiser
Advanced tools
A react-native implementation for sending BLE advertisements
Bluetooth Advertiser & Scanner for React Native. This is in a very early development focused in contact tracing applications. Please use with caution.
npm install react-native-ble-advertiser --save
or
yarn add react-native-ble-advertiser
In the AndroidManifest.xml file, add the Bluetooth permissions
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
On your plist file, add the following keys:
<key>NSLocationWhenInUseUsageDescription</key>
<string>...</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>...</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>bluetooth-le</string>
</array>
Import the module
import BLEAdvertiser from 'react-native-ble-advertiser'
Define your company ID and broadcast your service UUID with additional manufactoring data:
BLEAdvertiser.setCompanyId(0x00); // Your Company's Code
BLEAdvertiser.broadcast([UUID], [ManufacturerData], {}) // The service UUID and additional manufacturer data.
.then(success => console.log('Broadcasting Sucessful', success))
.catch(error => console.log('Broadcasting Error', error));
Available Advertising Options:
{
advertiseMode: BLEAdvertiser.<
ADVERTISE_MODE_LOW_POWER,
ADVERTISE_MODE_BALANCED,
ADVERTISE_MODE_LOW_LATENCY,
ADVERTISE_MODE_LOW_POWER>,
txPowerLevel: BLEAdvertiser.<
ADVERTISE_TX_POWER_LOW,
ADVERTISE_TX_POWER_HIGH,
ADVERTISE_TX_POWER_LOW,
ADVERTISE_TX_POWER_MEDIUM,
ADVERTISE_TX_POWER_ULTRA_LOW>,
connectable: <false,true>,
includeDeviceName: <false,true>,
includeTxPowerLevel: <false,true>
}
Stop broadcasting
BLEAdvertiser.stopBroadcast()
.then(success => console.log("Stop Broadcast Successful", success))
.catch(error => console.log("Stop Broadcast Error", error));
Import the modules
import BLEAdvertiser from 'react-native-ble-advertiser'
import { NativeEventEmitter, NativeModules } from 'react-native';
Register a listener to collect the devices through ReactNative events.
const eventEmitter = new NativeEventEmitter(NativeModules.BLEAdvertiser);
eventEmitter.addListener('onDeviceFound', (deviceData) => {
console.log(deviceData);
});
Scan by Service UUID
BLEAdvertiser.setCompanyId(0x00); // Your Company's Code
BLEAdvertiser.scanByService([UUID], {}) // service UUID and options
.then(success => console.log("Scan Successful", success))
.catch(error => console.log("Scan Error", error));
Scan by your company ID and additional data (Android only).
BLEAdvertiser.setCompanyId(0x00); // Your Company's Code
BLEAdvertiser.scan([ManufacturerData], {}) // manufacturer data and options
.then(success => console.log("Scan Successful", success))
.catch(error => console.log("Scan Error", error));
Available Scanning Options:
{
scanMode: BLEAdvertiser.<
SCAN_MODE_BALANCED,
SCAN_MODE_LOW_LATENCY,
SCAN_MODE_LOW_POWER,
SCAN_MODE_OPPORTUNISTIC>,
matchMode: BLEAdvertiser.<
MATCH_MODE_AGGRESSIVE,
MATCH_MODE_STICKY>,
numberOfMatches: BLEAdvertiser.<
MATCH_NUM_FEW_ADVERTISEMENT,
MATCH_NUM_MAX_ADVERTISEMENT,
MATCH_NUM_ONE_ADVERTISEMENT>,
reportDelay: <int>
}
Stop scanning
BLEAdvertiser.stopScan()
.then(success => console.log("Stop Scan Successful", success))
.catch(error => console.log("Stop Scan Error", error));
const eventEmitter = new NativeEventEmitter(NativeModules.BLEAdvertiser);
onBTStatusChange = eventEmitter.addListener('onBTStatusChange', (enabled) => {
console.log("Bluetooth status: ", enabled);
});
Fork the repo to your GitHub user.
Clone to your computer.
git clone https://github.com/vitorpamplona/react-native-ble-advertiser.git
./repack.sh <android,ios> <devicename>
npx react-native <run-android, run-ios --device>
Pull requests are welcome :)
npm pack
cd example
npm i $NPMFILE
cd ios
pod install
cd ..
npx react-native run-android
FAQs
A react-native implementation for sending BLE advertisements
The npm package react-native-ble-advertiser receives a total of 73 weekly downloads. As such, react-native-ble-advertiser popularity was classified as not popular.
We found that react-native-ble-advertiser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.