import { useCallback, useEffect, useState } from "react"; import { Mono } from "@components/generic/Mono.js"; import { Button } from "@components/UI/Button.js"; import { useAppStore } from "@core/stores/appStore.js"; import { useDeviceStore } from "@core/stores/deviceStore.js"; import { subscribeAll } from "@core/subscriptions.js"; import { randId } from "@core/utils/randId.js"; import { Constants, IBLEConnection } from "@meshtastic/meshtasticjs"; export const BLE = (): JSX.Element => { const [bleDevices, setBleDevices] = useState([]); const { addDevice } = useDeviceStore(); const { setSelectedDevice } = useAppStore(); const updateBleDeviceList = useCallback(async (): Promise => { setBleDevices(await navigator.bluetooth.getDevices()); }, []); useEffect(() => { void updateBleDeviceList(); }, [updateBleDeviceList]); const onConnect = async (BLEDevice: BluetoothDevice) => { const id = randId(); const device = addDevice(id); setSelectedDevice(id); const connection = new IBLEConnection(id); await connection.connect({ device: BLEDevice, }); device.addConnection(connection); subscribeAll(device, connection); }; return (
{bleDevices.map((device, index) => ( ))} {bleDevices.length === 0 && ( No devices paired yet. )}
); };