Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function peripheralReducer(state, action) {
if (action.action == "add") {
let peripheral = action.peripheral;
console.log(peripheral);
if (state.has(peripheral.id)) {
return state; // No state change
}
if (!peripheral.advertising.serviceUUIDs || peripheral.advertising.serviceUUIDs.length == 0 || peripheral.advertising.serviceUUIDs[0].toLowerCase() != 'adaf0100-4369-7263-7569-74507974686e') {
return state;
}
console.log(peripheral);
var newMap = new Map(state);
newMap.set(peripheral.id, peripheral);
return newMap;
} else if (action.action == "scan") {
BleManager.scan([], 3).then((results) => {
console.log('Scanning...');
});
} else if (action.action == "clear") {
state.clear();
}
return state;
}
startScan() {
if (!this.state.scanning) {
//this.setState({peripherals: new Map()});
BleManager.scan([], 3, true).then((results) => {
console.log('Scanning...');
this.setState({scanning:true});
});
}
}
startScan = () => {
this.peripherals = [];
this.setState({
is_scanning: true
});
BleManager.scan([], 3, true)
.then(() => {
console.log('scan started');
});
}
startScan() {
if (!this.state.scanning) {
this.setState({peripherals: new Map()});
BleManager.scan([], 3, true).then((results) => {
console.log('Scanning...');
this.setState({scanning:true});
});
}
}
return new Promise( (resolve, reject) =>{
BleManager.scan([], 5, true)
.then( () => {
console.log('Scan started');
resolve();
}).catch( (err)=>{
console.log('Scan started fail');
reject(err);
});
});
}
return new Promise( (resolve, reject) =>{
BleManager.scan([], 5, true)
.then( () => {
console.log('Scan started');
resolve();
}).catch( (err)=>{
console.log('Scan started fail');
reject(err);
});
});
}
BleManager.start().then(() => {
BleManager.scan([], 10, false).then(() => {
NativeAppEventEmitter.addListener(
"BleManagerDiscoverPeripheral",
data => {
if (data.name === null) {
for (let i = 0; i < this.props.addedDevice.length; i += 1) {
if (data.id === this.props.addedDevice[i].macAddress) {
dup += 1;
}
}
for (let i = 0; i < devices.length; i += 1) {
if (data.id === devices[i].macAddress) {
dup1 += 1;
}
}
if (dup === 0) {
if (dup1 === 0) {