feat:客服
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
findDeviceInBleScan,
|
||||
isBluetoothApiSupported,
|
||||
rssiToSignalLevel,
|
||||
scanBluetoothDevices,
|
||||
} from '@/utils/bluetooth'
|
||||
import { sameId } from '@/utils/device-id'
|
||||
@@ -79,26 +78,28 @@ export async function refreshDevicePresence(
|
||||
})
|
||||
|
||||
void Promise.allSettled(
|
||||
nextDevices
|
||||
.filter((device) => device.deviceId && targets.some((item) => sameId(item.deviceId, device.deviceId)))
|
||||
.map(async (device) => {
|
||||
const found = findDeviceInBleScan(
|
||||
{ mac: device.mac, name: device.name },
|
||||
scanned,
|
||||
{ strictName: true },
|
||||
)
|
||||
const present = !!found
|
||||
try {
|
||||
await updateDeviceRuntime({
|
||||
deviceId: device.deviceId!,
|
||||
status: present ? '1' : '2',
|
||||
bluetoothConnected: present ? '1' : '0',
|
||||
signalLevel: present ? rssiToSignalLevel(found?.RSSI) : '0',
|
||||
})
|
||||
} catch (err) {
|
||||
logPresence('updateRuntime failed', err)
|
||||
}
|
||||
}),
|
||||
targets.map(async (device) => {
|
||||
const found = findDeviceInBleScan(
|
||||
{ mac: device.mac, name: device.name },
|
||||
scanned,
|
||||
{ strictName: true },
|
||||
)
|
||||
const present = !!found
|
||||
const nextStatus = present ? '1' : '2'
|
||||
const nextBluetooth = present ? '1' : '0'
|
||||
if (device.status === nextStatus && device.bluetoothConnected === nextBluetooth) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updateDeviceRuntime({
|
||||
deviceId: device.deviceId!,
|
||||
status: nextStatus,
|
||||
bluetoothConnected: nextBluetooth,
|
||||
})
|
||||
} catch (err) {
|
||||
logPresence('updateRuntime failed', err)
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
return nextDevices
|
||||
|
||||
Reference in New Issue
Block a user