feat: Implement server-initiated status refresh for new device detection and client-requested full status updates.
This commit is contained in:
@@ -631,6 +631,10 @@ const dashboardHTML = `<!DOCTYPE html>
|
||||
|
||||
if (!devices[mac]) {
|
||||
// New device, request full refresh
|
||||
console.log('New device detected (' + mac + '), requesting refresh...');
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'get_status' }));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -961,6 +965,11 @@ wss.on('connection', async (ws) => {
|
||||
}
|
||||
}
|
||||
ws.send(JSON.stringify({ type: 'set_config_result', success }));
|
||||
} else if (data.type === 'get_status') {
|
||||
// Client requested full status refresh
|
||||
const devices = await getStatusData();
|
||||
const rules = await getRulesStatus();
|
||||
ws.send(JSON.stringify({ type: 'init', devices, rules }));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Status] Error processing message:', err);
|
||||
|
||||
Reference in New Issue
Block a user