Skip to content

Commit

Permalink
Merged bluetooth_scanner into ble_scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
the-bay-kay committed Mar 20, 2024
1 parent 6bd3977 commit 0387633
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"cordova-plugin-app-version": "0.1.14",
"cordova-plugin-customurlscheme": "5.0.2",
"cordova-plugin-device": "2.1.0",
"cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.2",
"cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.3",
"cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2",
"cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.6",
"cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.2",
Expand Down
1 change: 0 additions & 1 deletion setup/android_sdk_packages
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build-tools;33.0.2
build-tools;34.0.0
emulator
extras;google;google_play_services
patcher;v4
platform-tools
platforms;android-30
platforms;android-31
Expand Down
4 changes: 2 additions & 2 deletions www/js/bluetooth/BluetoothCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { Card, List } from 'react-native-paper';
import { StyleSheet } from 'react-native';

type Props = any;
const BluetoothCard = (device: Props) => {
const BluetoothCard = ({ device }: Props) => {
return (
<Card style={cardStyles.card}>
<Card.Title
title={`Name: ${device.name}`}
titleVariant="titleLarge"
subtitle={`ID: ${device.id}`}
left={() => <List.Icon icon={device.is_paired ? 'bluetooth-connect' : 'bluetooth-off'} />}
left={() => <List.Icon icon={device.is_paired ? 'bluetooth' : 'bluetooth-off'} />}
/>
</Card>
);
Expand Down
23 changes: 6 additions & 17 deletions www/js/bluetooth/BluetoothScanPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { StyleSheet, Modal, ScrollView, SafeAreaView, View, Text } from 'react-native';
import { gatherBluetoothData, startBLEScanning } from './blueoothScanner';
import { StyleSheet, Modal, ScrollView, SafeAreaView, View } from 'react-native';
import { gatherBluetoothData, startBLEScanning } from './bluetoothScanner';
import { logWarn, displayError, displayErrorMsg } from '../plugin/logger';
import { getConfig } from '../config/dynamicConfig';
import BluetoothCard from './BluetoothCard';
import { Appbar, useTheme, Button } from 'react-native-paper';

Expand All @@ -25,28 +24,18 @@ const BluetoothScanPage = ({ ...props }: any) => {

// Function to run Bluetooth Classic test and update logs
const runBluetoothClassicTest = async () => {
let permissionFunction;
// Depending on user platform, handle requesting the permissions differently
if (window['cordova'].platformId == 'android') {
permissionFunction = window['cordova'].plugins.BEMDataCollection.bluetoothScanPermissions();
} else {
permissionFunction = window['bluetoothClassicSerial'].initializeBluetooth();
}
if (!permissionFunction) {
displayErrorMsg('PlatformID Not Found', 'OSError');
// Classic not currently supported on iOS
if (window['cordova'].platformId == 'ios') {
displayErrorMsg('Sorry, iOS is not supported!', 'OSError');
return;
}

try {
const response = await permissionFunction();
let response = await window['cordova'].plugins.BEMDataCollection.bluetoothScanPermissions();
if (response != 'OK') {
displayErrorMsg('Please Enable Bluetooth!', 'Insufficient Permissions');
return;
}
if (window['cordova'].platformId == 'ios') {
displayErrorMsg('Sorry, iOS is not supported!', 'OSError');
return;
}
} catch (e) {
displayError(e, 'Insufficient Permissions');
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@ export function gatherBluetoothData(t): Promise<string[]> {
logDebug('Running bluetooth discovery test!');

// Device List "I/O"
function handleLogs(pairingType: Boolean, devices: Array<BluetoothClassicDevice>) {
let logs: string[] = [];
function updatePairingStatus(pairingType: boolean, devices: Array<BluetoothClassicDevice>) {
devices.forEach((device) => {
device.is_paired;
device.is_paired = pairingType;
});
return logs;
return devices;
}

// Plugin Calls
const unpairedDevicesPromise = new Promise((res, rej) => {
window['bluetoothClassicSerial'].discoverUnpaired(
(devices: Array<BluetoothClassicDevice>) => {
res(handleLogs(false, devices));
res(updatePairingStatus(false, devices));
},
(e: Error) => {
displayError(e, 'Error');
Expand All @@ -51,7 +50,7 @@ export function gatherBluetoothData(t): Promise<string[]> {
const pairedDevicesPromise = new Promise((res, rej) => {
window['bluetoothClassicSerial'].list(
(devices: Array<BluetoothClassicDevice>) => {
res(handleLogs(true, devices));
res(updatePairingStatus(true, devices));
},
(e: Error) => {
displayError(e, 'Error');
Expand Down

0 comments on commit 0387633

Please sign in to comment.