guarding device web socket a little better

This commit is contained in:
Carter 2026-03-06 13:05:30 -06:00
parent 55bff3af00
commit 4546796db9

View file

@ -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,