fix: 设备状态刷新改为全量设备列表广播

- refreshDeviceStatusToWebClients改为广播完整设备列表(devices_list_refresh事件)
- 替代原来逐个设备广播device_status_update的方式
- 确保Web端能同步到所有设备的最新状态
This commit is contained in:
wdvipa
2026-02-15 17:33:45 +08:00
parent 5ed65090b9
commit af927dd9b4
2 changed files with 10 additions and 23 deletions

Binary file not shown.

View File

@@ -2263,34 +2263,21 @@ class RemoteControlServer {
try { try {
const webClientCount = this.webClientManager.getClientCount() const webClientCount = this.webClientManager.getClientCount()
if (webClientCount === 0) { if (webClientCount === 0) {
return // 没有Web客户端跳过刷新 return
} }
const onlineDevices = this.deviceManager.getAllDevices() // 获取完整设备列表(含历史设备)并广播给Web端
const allDevices = this.getAllDevicesIncludingHistory()
for (const device of onlineDevices) { if (allDevices.length > 0) {
// 验证设备Socket仍然连接 this.webClientManager.broadcastToAll('devices_list_refresh', {
const socket = this.io.sockets.sockets.get(device.socketId) devices: allDevices,
if (socket && socket.connected) { timestamp: Date.now()
// 广播设备在线状态 })
this.webClientManager.broadcastToAll('device_status_update', { this.logger.debug(`[Refresh] Sent ${allDevices.length} devices to ${webClientCount} web clients`)
deviceId: device.id,
status: {
online: true,
connected: true,
lastSeen: Date.now(),
inputBlocked: device.inputBlocked || false
}
})
}
}
if (onlineDevices.length > 0) {
this.logger.debug(`🔄 已刷新 ${onlineDevices.length} 个设备状态给 ${webClientCount} 个Web客户端`)
} }
} catch (error) { } catch (error) {
this.logger.error('刷新设备状态失败:', error) this.logger.error('refreshDeviceStatusToWebClients failed:', error)
} }
} }