|
|
|
@ -5,9 +5,10 @@ import { useAppStore } from "@core/stores/appStore.ts"; |
|
|
|
import { useDeviceStore } from "@core/stores/deviceStore.ts"; |
|
|
|
import { subscribeAll } from "@core/subscriptions.ts"; |
|
|
|
import { randId } from "@core/utils/randId.ts"; |
|
|
|
import { BleConnection, ServiceUuid } from "@meshtastic/js"; |
|
|
|
import { TransportWebBluetooth } from "@meshtastic/transport-web-bluetooth"; |
|
|
|
import { MeshDevice } from "@meshtastic/core"; |
|
|
|
import { useCallback, useEffect, useState } from "react"; |
|
|
|
import { useMessageStore } from "../../../core/stores/messageStore/index.ts"; |
|
|
|
import { useMessageStore } from "@core/stores/messageStore/index.ts"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
|
|
|
|
export const BLE = ( |
|
|
|
@ -30,15 +31,13 @@ export const BLE = ( |
|
|
|
|
|
|
|
const onConnect = async (bleDevice: BluetoothDevice) => { |
|
|
|
const id = randId(); |
|
|
|
const transport = await TransportWebBluetooth.createFromDevice(bleDevice); |
|
|
|
const device = addDevice(id); |
|
|
|
const connection = new MeshDevice(transport, id); |
|
|
|
connection.configure(); |
|
|
|
setSelectedDevice(id); |
|
|
|
const connection = new BleConnection(id); |
|
|
|
await connection.connect({ |
|
|
|
device: bleDevice, |
|
|
|
}); |
|
|
|
device.addConnection(connection); |
|
|
|
subscribeAll(device, connection, messageStore); |
|
|
|
|
|
|
|
closeDialog(); |
|
|
|
}; |
|
|
|
|
|
|
|
@ -71,7 +70,7 @@ export const BLE = ( |
|
|
|
onClick={async () => { |
|
|
|
await navigator.bluetooth |
|
|
|
.requestDevice({ |
|
|
|
filters: [{ services: [ServiceUuid] }], |
|
|
|
filters: [{ services: [TransportWebBluetooth.ServiceUuid] }], |
|
|
|
}) |
|
|
|
.then((device) => { |
|
|
|
const exists = bleDevices.findIndex((d) => d.id === device.id); |
|
|
|
|