{
in_range: false,
},
});
-
const [isScanningClassic, setIsScanningClassic] = useState(false);
+ const [isScanningBLE, setIsScanningBLE] = useState(false);
const [isClassic, setIsClassic] = useState(false);
const { colors } = useTheme();
@@ -49,8 +49,9 @@ const BluetoothScanPage = ({ ...props }: any) => {
...device,
}));
}
+
// Function to run Bluetooth Classic test and update logs
- const runBluetoothClassicTest = async () => {
+ async function runBluetoothClassicTest() {
// Classic not currently supported on iOS
if (window['cordova'].platformId == 'ios') {
displayErrorMsg('Sorry, iOS is not supported!', 'OSError');
@@ -77,23 +78,22 @@ const BluetoothScanPage = ({ ...props }: any) => {
} finally {
setIsScanningClassic(false);
}
- };
-
- const runBLETest = async () => {
- //await startBLEScanning();
- BeaconMonitor(); // Will combine BeaconMonitor & StartBLE Scanning, if possible
- };
+ }
function setRangeStatus(uuid: string, status: boolean) {
- setSampleBLEDevices((prevDevices) => {
- const newList = prevDevices;
- newList[uuid].in_range = status;
- return newList;
- });
+ setSampleBLEDevices((prevDevices) => ({
+ ...prevDevices,
+ [uuid]: {
+ ...prevDevices[uuid],
+ in_range: status,
+ },
+ }));
}
// BLE LOGIC
- const BeaconMonitor = () => {
+ async function startBeaconScanning() {
+ setIsScanningBLE(true);
+
let delegate = new window['cordova'].plugins.locationManager.Delegate();
delegate.didDetermineStateForRegion = function (pluginResult: BLEPluginCallback) {
@@ -147,7 +147,27 @@ const BluetoothScanPage = ({ ...props }: any) => {
})
.done();
});
- };
+ }
+
+ async function stopBeaconScanning() {
+ setIsScanningBLE(false);
+
+ beaconsToArray().forEach((sampleBeacon: BLEBeaconDevice) => {
+ setRangeStatus(sampleBeacon.uuid, false); // "zero out" the beacons
+ const beaconRegion = new window['cordova'].plugins.locationManager.BeaconRegion(
+ sampleBeacon.identifier,
+ sampleBeacon.uuid,
+ sampleBeacon.major,
+ sampleBeacon.minor,
+ );
+ window['cordova'].plugins.locationManager
+ .stopMonitoringForRegion(beaconRegion)
+ .fail(function (e) {
+ logWarn(e);
+ })
+ .done();
+ });
+ }
const switchMode = () => {
setIsClassic(!isClassic);
@@ -172,13 +192,43 @@ const BluetoothScanPage = ({ ...props }: any) => {
{beaconsAsArray.map((beacon) => {
if (beacon) {
- return ;
+ return ;
}
})}
);
};
+ const ScanButton = () => {
+ if (isClassic) {
+ return (
+
+
+
+ );
+ }
+ // else, if BLE
+ return (
+
+
+
+ );
+ };
+
const BlueScanContent = () => (
{
-
-
-
+
);