Skip to content

Commit

Permalink
iOS beacon scanning confirmed working
Browse files Browse the repository at this point in the history
- Successfully detected beacon on iOS
- Minor changes to JSX to properly render `logToDom()`
- Renamed Bluetooth Classic Scan to reflect purpose
  • Loading branch information
the-bay-kay committed Mar 21, 2024
1 parent 0387633 commit 3ed6974
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions www/js/bluetooth/BluetoothScanPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { StyleSheet, Modal, ScrollView, SafeAreaView, View } from 'react-native';
import { gatherBluetoothData, startBLEScanning } from './bluetoothScanner';
import { logWarn, displayError, displayErrorMsg } from '../plugin/logger';
import { StyleSheet, Modal, ScrollView, SafeAreaView, View, Text } from 'react-native';
import { gatherBluetoothClassicData } from './bluetoothScanner';
import { logWarn, displayError, displayErrorMsg, logDebug } from '../plugin/logger';
import BluetoothCard from './BluetoothCard';
import { Appbar, useTheme, Button } from 'react-native-paper';
import { BluetoothClassicDevice } from '../types/BluetoothDevices';

/**
* The implementation of this scanner page follows the design of
Expand All @@ -16,7 +17,7 @@ import { Appbar, useTheme, Button } from 'react-native-paper';

const BluetoothScanPage = ({ ...props }: any) => {
const { t } = useTranslation();
const [logs, setLogs] = useState<string[]>([]);
const [logs, setLogs] = useState<BluetoothClassicDevice[]>([]);
const [testLogs, setTestLogs] = useState<string[]>([]);
const [isScanning, setIsScanning] = useState(false);
const [isClassic, setIsClassic] = useState(false);
Expand All @@ -43,7 +44,7 @@ const BluetoothScanPage = ({ ...props }: any) => {

try {
setIsScanning(true);
const newLogs = await gatherBluetoothData(t);
const newLogs = await gatherBluetoothClassicData(t);
setLogs(newLogs);
} catch (error) {
logWarn(error);
Expand All @@ -65,23 +66,19 @@ const BluetoothScanPage = ({ ...props }: any) => {
setTestLogs((prevLogs) => [...prevLogs, message]);
};

logToDom('HELLO');
logToDom('HELLO2');

let delegate = new window['cordova'].plugins.locationManager.Delegate();
logToDom(delegate);

delegate.didDetermineStateForRegion = function (pluginResult) {
logToDom('[BLE] didDetermineStateForRegion');
logToDom(JSON.stringify(pluginResult));
logToDom(JSON.stringify(pluginResult, null, 2));
window['cordova'].plugins.locationManager.appendToDeviceLog(
'[DOM] didDetermineStateForRegion: ' + JSON.stringify(pluginResult),
'[DOM] didDetermineStateForRegion: ' + JSON.stringify(pluginResult, null, 2),
);
};

delegate.didStartMonitoringForRegion = function (pluginResult) {
logToDom('[BLE] didStartMonitoringForRegion');
logToDom(JSON.stringify(pluginResult));
logDebug('[BLE] didStartMonitoringForRegion');
logDebug(JSON.stringify(pluginResult));
};

delegate.didRangeBeaconsInRegion = function (pluginResult) {
Expand All @@ -90,7 +87,7 @@ const BluetoothScanPage = ({ ...props }: any) => {
};

var uuid = '426C7565-4368-6172-6D42-6561636F6E73';
var identifier = 'Louis-Beacon';
var identifier = 'BlueCharm_98105';
var minor = 4949;
var major = 3838;

Expand Down Expand Up @@ -177,8 +174,8 @@ const BluetoothScanPage = ({ ...props }: any) => {
</Button>
<BluetoothCardList devices={logs} />
<ScrollView>
{testLogs.map((l) => (
<div>{l}</div>
{testLogs.map((log, index) => (
<Text key={index}>{log}</Text>
))}
</ScrollView>
</div>
Expand Down
2 changes: 1 addition & 1 deletion www/js/bluetooth/bluetoothScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const KatieTestBeacon: BLEBeaconDevice = {
* @param t is the i18next translation function
* @returns an array of strings containing device data, formatted ['ID: id Name: name']
*/
export function gatherBluetoothData(t): Promise<string[]> {
export function gatherBluetoothClassicData(t): Promise<BluetoothClassicDevice[]> {
return new Promise((resolve, reject) => {
logDebug('Running bluetooth discovery test!');

Expand Down

0 comments on commit 3ed6974

Please sign in to comment.