Skip to content

Commit

Permalink
Cleanup Scanner Code, fix iOS bug
Browse files Browse the repository at this point in the history
  • Loading branch information
the-bay-kay committed Mar 23, 2024
1 parent a11b6c1 commit 71abee3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 75 deletions.
6 changes: 1 addition & 5 deletions www/js/bluetooth/BluetoothScanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ const BluetoothScanPage = ({ ...props }: any) => {
setRangeStatus(pluginResult.region.uuid.toUpperCase(), true);
} else if (pluginResult.state == 'CLRegionStateOutside') {
setRangeStatus(pluginResult.region.uuid.toUpperCase(), false);
} else {
displayErrorMsg('Error: Unknown state recorded during BLE Scanning!');
logWarn('Error: Unknown state recorded in BLE Scanning!');
return;
}
logDebug('[BLE] didDetermineStateForRegion');
logDebug(JSON.stringify(pluginResult, null, 2));
Expand Down Expand Up @@ -175,7 +171,7 @@ const BluetoothScanPage = ({ ...props }: any) => {

const BluetoothCardList = ({ devices }) => {
if (isClassic) {
// When in calssic mode, render devices as normal
// When in classic mode, render devices as normal
return (
<div>
{devices.map((device) => {
Expand Down
72 changes: 2 additions & 70 deletions www/js/bluetooth/bluetoothScanner.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import { logWarn, logDebug, displayError } from '../plugin/logger';
import { BluetoothClassicDevice, BLEBeaconDevice } from '../types/bluetoothDevices';

const LouisTestBeacon: BLEBeaconDevice = {
identifier: 'Louis-Beacon',
uuid: '426C7565-4368-6172-6D42-6561636F6E73',
broadcast_type: 'iBeacon',
major: 4949,
minor: 3838,
};
const KatieTestBeacon: BLEBeaconDevice = {
// System ID: 'DD:34:02:07:EC:04'
identifier: 'BlueCharm_98105',
uuid: '426C7565-4368-6172-6D42-6561636F6E73',
broadcast_type: 'iBeacon',
major: 4949,
minor: 3838,
};
import { logDebug, displayError } from '../plugin/logger';
import { BluetoothClassicDevice } from '../types/bluetoothDevices';

/**
* gatherBluetoothData scans for viewable Bluetooth Classic Devices
Expand Down Expand Up @@ -68,55 +52,3 @@ export function gatherBluetoothClassicData(t): Promise<BluetoothClassicDevice[]>
});
});
}

function createBLERegion(beaconData: BLEBeaconDevice) {
// throws an error if the parameters are not valid
return new window['locationManager'].BeaconRegion(
beaconData.identifier,
beaconData.uuid,
beaconData.major,
beaconData.minor,
);
}

export function startBLEScanning() {
const delegate = new window['locationManager'].Delegate();

delegate.didDetermineStateForRegion = function (pluginResult) {
logWarn('[DOM] didDetermineStateForRegion: ' + JSON.stringify(pluginResult));
window['locationManager'].appendToDeviceLog(
'[DOM] didDetermineStateForRegion: ' + JSON.stringify(pluginResult),
);
};

delegate.didStartMonitoringForRegion = function (pluginResult) {
logWarn('didStartMonitoringForRegion:' + JSON.stringify(pluginResult));
};

delegate.didRangeBeaconsInRegion = function (pluginResult) {
logWarn('[DOM] didRangeBeaconsInRegion: ' + JSON.stringify(pluginResult));
};

window['locationManager'].setDelegate(delegate);
window['locationManager'].requestWhenInUseAuthorization();

const BeaconRegion = createBLERegion(KatieTestBeacon);

window['locationManager']
.startMonitoringForRegion(BeaconRegion)
.fail(function (e) {
logWarn(e);
})
.done();
}

export function endBLEScanning() {
const beaconRegion = createBLERegion(KatieTestBeacon);

window['locationManager']
.stopMonitoringForRegion(beaconRegion)
.fail(function (e) {
console.error(e);
})
.done();
}

0 comments on commit 71abee3

Please sign in to comment.