Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test(peripheral) {
if (peripheral){
if (peripheral.connected){
BleManager.disconnect(peripheral.id);
}else{
BleManager.connect(peripheral.id).then(() => {
let peripherals = this.state.peripherals;
let p = peripherals.get(peripheral.id);
if (p) {
p.connected = true;
peripherals.set(peripheral.id, p);
this.setState({peripherals});
}
console.log('Connected to ' + peripheral.id);
setTimeout(() => {
/* Test read current RSSI value
BleManager.retrieveServices(peripheral.id).then((peripheralData) => {
disconnect() {
BleManager.disconnect(this.peripheralId)
.then( () => {
console.log('Disconnected');
})
.catch( (error) => {
console.log('Disconnected error:',error);
});
/* return new Promise( (resolve, reject) =>{
BleManager.disconnect(this.peripheralId)
.then( () => {
console.log('Disconnected');
resolve();
})
.catch( (error) => {
console.log('Disconnected error:',error);
reject(error);
});
disconnect() {
BleManager.disconnect(this.peripheralId)
.then( () => {
console.log('Disconnected');
})
.catch( (error) => {
console.log('Disconnected error:',error);
});
}
useEffect(() => {
if (currentAppState === 'active') {
console.log('App has come to the foreground!', bleState);
BleManager.start({showAlert: true});
BleManager.checkState();
} else {
if (peripheral) {
changeCode({"type": "disconnect", "peripheral_id": peripheral.id});
BleManager.disconnect(peripheral.id);
}
setBleState("disconnected");
}
}, [currentAppState]);
{ BleManager.disconnect(device_id); }}>
.then(() => {
BleManager.disconnect(connected_peripheral)
.then(() => {
Alert.alert('Attended', 'You have successfully attended the event. The app will now close.');
setTimeout(() => {
RNExitApp.exitApp();
}, 3000);
})
.catch((error) => {
Alert.alert('Error disconnecting', "You have successfully attended the event but there's a problem disconnecting to the peripheral, please disable bluetooth to force disconnection.");
});
})
.catch((error) => {