Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor() {
super();
// enables the console.logs from the Bluetooth source code
this._bluetooth.debug = true;
// using an event listener instead of the 'onDiscovered' callback of 'startScanning'
this._bluetooth.on(Bluetooth.device_discovered_event, (eventData: any) => {
const perip = eventData.data as Peripheral;
let index = -1;
this.peripherals.some((p, i) => {
if (p.UUID === perip.UUID) {
index = i;
return true;
}
return false;
});
console.log('Peripheral found:', JSON.stringify(eventData.data), index);
if (index === -1) {
this.peripherals.push(perip);
} else {
this.peripherals.setItem(index, perip);
}
});