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.
rook-bluetooth
Advanced tools
RookMotion Bluetooth is a React Hook library that contains the Bluetooth management to get easy the integration with RookMotion services, in this package you could find two hooks in order to do connect with sensors.
RookMotion Bluetooth is a React Hook library that contains the Bluetooth management to get easy the integration with RookMotion services, in this package you could find two hooks in order to do connect with sensors.
useSensorManager
: this hook is in charge of read the battery, bpm and stepsuseSensorScanner
: this hooks is in charge to discover the sensors that are around.npm i rook-bluetooth
or
yarn add rook-bluetooth
This package uses the react-native-ble-manager please follow the installation in order to continue.
Next is necessary to set a provider to start the package, set this provider at the highest level of your component tree
import {RookMotionProvider} from "rook-provider";
<RookMotionProvider token="YOUR-TOKEN">
<Your-Components />
</RookMotionProvider>
NOTE: If you already setted the RookmotionWrapper skip this step
useSensorManager
useSensorManager: ({ emitter, showAlert, stepsEnable }: useSensorManagerProps) => SensorManager;
import { useSensorManager } from 'rook-bluetooth';
Return
batteryLevel: number;
bpm: number;
connectedPeripheral?: BLPeripheral;
discoveredSensors: Array<BLPeripheral>;
isReady: boolean;
isScanning: boolean;
stepCount: number;
connect: (peripheral: BLPeripheral) => Promise<boolean>;
disconnect: () => void;
startScan: (timeout: number) => void;
Example
import React, {FC, useEffect, useState} from 'react';
import {useNavigation} from '@react-navigation/native';
import {Box, useToast} from 'native-base';
import {NativeEventEmitter, NativeModules} from 'react-native';
import {BLPeripheral, useSensorManager} from 'rook-bluetooth';
type BLEConnectProps = {
sensor: BLPeripheral | null;
connected: (result: boolean) => void;
};
export const BLEConnect: FC<BLEConnectProps> = ({sensor, connected}) => {
const navigation = useNavigation();
const toast = useToast();
const [connecting, setConnecting] = useState(false);
const {isReady, batteryLevel, bpm, stepCount, connect, disconnect} =
useSensorManager({
emitter: new NativeEventEmitter(NativeModules.BleManager),
showAlert: true,
stepsEnable: true,
});
useEffect(() => {
if (isReady) {
setTimeout(() => {
attemptToConnect();
}, 200);
}
}, [isReady, sensor]);
useEffect(() => {
if (!navigation.isFocused()) {
disconnect();
}
}, [navigation]);
useEffect(() => {
console.log('bpm', bpm);
console.log('batteryLevel', batteryLevel);
console.log('stepCount', stepCount);
}, [bpm, batteryLevel, stepCount]);
const attemptToConnect = async (): Promise<any> => {
if (connecting || !sensor) {
return;
}
setConnecting(true);
try {
const result = await connect(sensor);
if (result) {
toast.show({description: 'Connection successfully'});
connected(true);
} else {
throw new Error();
}
} catch (error) {
connected(false);
toast.show({description: 'Unable to connect'});
}
};
return <Box />;
};
useSensorScanner
useSensorScanner: ({ emitter, showAlert, }: useSensorScannerProps) => SensorScanner;
import { useSensorScanner } from 'rook-bluetooth';
Return
discoveredSensors: Array<BLPeripheral>;
isReady: boolean;
isScanning: boolean;
startScan: (timeout: number) => void;
Example
/* eslint-disable react-hooks/exhaustive-deps */
import React, {FC, useEffect, useState} from 'react';
import {useNavigation} from '@react-navigation/native';
import {Box, useToast} from 'native-base';
import {NativeEventEmitter, NativeModules} from 'react-native';
import {BLPeripheral, useSensorManager} from 'rook-bluetooth';
type BLEConnectProps = {
sensor: BLPeripheral | null;
connected: (result: boolean) => void;
};
export const BLEConnect: FC<BLEConnectProps> = ({sensor, connected}) => {
const navigation = useNavigation();
const toast = useToast();
const [connecting, setConnecting] = useState(false);
const {isReady, batteryLevel, bpm, stepCount, connect, disconnect} =
useSensorManager({
emitter: new NativeEventEmitter(NativeModules.BleManager),
showAlert: true,
stepsEnable: true,
});
useEffect(() => {
if (isReady) {
setTimeout(() => {
attemptToConnect();
}, 200);
}
}, [isReady, sensor]);
useEffect(() => {
if (!navigation.isFocused()) {
disconnect();
}
}, [navigation]);
useEffect(() => {
console.log('bpm', bpm);
console.log('batteryLevel', batteryLevel);
console.log('stepCount', stepCount);
}, [bpm, batteryLevel, stepCount]);
const attemptToConnect = async (): Promise<any> => {
if (connecting || !sensor) {
return;
}
setConnecting(true);
try {
const result = await connect(sensor);
if (result) {
toast.show({description: 'Connection successfully'});
connected(true);
} else {
throw new Error();
}
} catch (error) {
connected(false);
toast.show({description: 'Unable to connect'});
}
};
return <Box />;
};
FAQs
RookMotion Bluetooth is a React Hook library that contains the Bluetooth management to get easy the integration with RookMotion services, in this package you could find two hooks in order to do connect with sensors.
The npm package rook-bluetooth receives a total of 6 weekly downloads. As such, rook-bluetooth popularity was classified as not popular.
We found that rook-bluetooth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.