guarding device web socket a little better
This commit is contained in:
parent
55bff3af00
commit
4546796db9
1 changed files with 17 additions and 3 deletions
|
|
@ -203,10 +203,24 @@ export default function DevicePage() {
|
|||
|
||||
// --- Real-time device updates (optional) ---
|
||||
// Updates device-level info (name, status, lastActive, etc.)
|
||||
useWebSocket<Device>({
|
||||
path: `/v1/live/devices/${deviceID}`,
|
||||
parse: (e) => Device.any(JSON.parse(e.data)),
|
||||
useWebSocket<Device | null>({
|
||||
path: `/live/devices/${deviceID}`,
|
||||
parse: (e) => {
|
||||
try {
|
||||
const raw = JSON.parse(e.data);
|
||||
const dev = Device.any(raw);
|
||||
if (!dev?.settings) {
|
||||
console.warn("[ws] received device without settings:", raw);
|
||||
return null;
|
||||
}
|
||||
return dev;
|
||||
} catch (err) {
|
||||
console.warn("[ws] failed to parse device:", err);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
onMessage: (updatedDevice) => {
|
||||
if (!updatedDevice) return;
|
||||
setDevice(updatedDevice);
|
||||
},
|
||||
token,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue