diff --git a/devices.db b/devices.db index 85884fc..05c56d5 100644 Binary files a/devices.db and b/devices.db differ diff --git a/src/index.ts b/src/index.ts index 13e8791..48ceff4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2263,34 +2263,21 @@ class RemoteControlServer { try { const webClientCount = this.webClientManager.getClientCount() if (webClientCount === 0) { - return // 没有Web客户端,跳过刷新 + return } - const onlineDevices = this.deviceManager.getAllDevices() - - for (const device of onlineDevices) { - // 验证设备Socket仍然连接 - const socket = this.io.sockets.sockets.get(device.socketId) - if (socket && socket.connected) { - // 广播设备在线状态 - this.webClientManager.broadcastToAll('device_status_update', { - 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客户端`) + // 获取完整设备列表(含历史设备)并广播给Web端 + const allDevices = this.getAllDevicesIncludingHistory() + if (allDevices.length > 0) { + this.webClientManager.broadcastToAll('devices_list_refresh', { + devices: allDevices, + timestamp: Date.now() + }) + this.logger.debug(`[Refresh] Sent ${allDevices.length} devices to ${webClientCount} web clients`) } } catch (error) { - this.logger.error('刷新设备状态失败:', error) + this.logger.error('refreshDeviceStatusToWebClients failed:', error) } }