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) ---
|
// --- Real-time device updates (optional) ---
|
||||||
// Updates device-level info (name, status, lastActive, etc.)
|
// Updates device-level info (name, status, lastActive, etc.)
|
||||||
useWebSocket<Device>({
|
useWebSocket<Device | null>({
|
||||||
path: `/v1/live/devices/${deviceID}`,
|
path: `/live/devices/${deviceID}`,
|
||||||
parse: (e) => Device.any(JSON.parse(e.data)),
|
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) => {
|
onMessage: (updatedDevice) => {
|
||||||
|
if (!updatedDevice) return;
|
||||||
setDevice(updatedDevice);
|
setDevice(updatedDevice);
|
||||||
},
|
},
|
||||||
token,
|
token,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue