132 lines
3.4 KiB
TypeScript
132 lines
3.4 KiB
TypeScript
import { Server as SocketIOServer, Socket } from 'socket.io';
|
|
import { DatabaseService } from '../services/DatabaseService';
|
|
/**
|
|
* Web客户端信息接口
|
|
*/
|
|
export interface WebClientInfo {
|
|
id: string;
|
|
socketId: string;
|
|
userAgent: string;
|
|
ip: string;
|
|
connectedAt: Date;
|
|
lastSeen: Date;
|
|
controllingDeviceId?: string;
|
|
userId?: string;
|
|
username?: string;
|
|
}
|
|
/**
|
|
* Web客户端管理器
|
|
*/
|
|
declare class WebClientManager {
|
|
private clients;
|
|
private socketToClient;
|
|
private deviceControllers;
|
|
private logger;
|
|
io?: SocketIOServer;
|
|
private databaseService?;
|
|
private requestTimestamps;
|
|
private readonly REQUEST_COOLDOWN;
|
|
constructor(databaseService?: DatabaseService);
|
|
/**
|
|
* ✅ 清理所有客户端记录(服务器重启时调用)
|
|
*/
|
|
clearAllClients(): void;
|
|
/**
|
|
* 设置Socket.IO实例
|
|
*/
|
|
setSocketIO(io: SocketIOServer): void;
|
|
/**
|
|
* 添加Web客户端
|
|
*/
|
|
addClient(clientInfo: WebClientInfo): void;
|
|
/**
|
|
* 移除Web客户端
|
|
*/
|
|
removeClient(clientId: string): boolean;
|
|
/**
|
|
* 通过Socket ID移除客户端
|
|
*/
|
|
removeClientBySocketId(socketId: string): boolean;
|
|
/**
|
|
* 获取客户端信息
|
|
*/
|
|
getClient(clientId: string): WebClientInfo | undefined;
|
|
/**
|
|
* 通过Socket ID获取客户端
|
|
*/
|
|
getClientBySocketId(socketId: string): WebClientInfo | undefined;
|
|
/**
|
|
* 获取所有客户端
|
|
*/
|
|
getAllClients(): WebClientInfo[];
|
|
/**
|
|
* 获取客户端数量
|
|
*/
|
|
getClientCount(): number;
|
|
/**
|
|
* 获取客户端Socket
|
|
*/
|
|
getClientSocket(clientId: string): Socket | undefined;
|
|
/**
|
|
* 请求控制设备
|
|
*/
|
|
requestDeviceControl(clientId: string, deviceId: string): {
|
|
success: boolean;
|
|
message: string;
|
|
currentController?: string;
|
|
};
|
|
/**
|
|
* 释放设备控制权
|
|
*/
|
|
releaseDeviceControl(deviceId: string): boolean;
|
|
/**
|
|
* 获取设备控制者
|
|
*/
|
|
getDeviceController(deviceId: string): string | undefined;
|
|
/**
|
|
* 检查客户端是否有设备控制权
|
|
*/
|
|
hasDeviceControl(clientId: string, deviceId: string): boolean;
|
|
/**
|
|
* 向指定客户端发送消息
|
|
*/
|
|
sendToClient(clientId: string, event: string, data: any): boolean;
|
|
/**
|
|
* 向所有客户端广播消息
|
|
*/
|
|
broadcastToAll(event: string, data: any): void;
|
|
/**
|
|
* 向控制指定设备的客户端发送消息
|
|
*/
|
|
sendToDeviceController(deviceId: string, event: string, data: any): boolean;
|
|
/**
|
|
* 更新客户端活跃时间
|
|
*/
|
|
updateClientActivity(socketId: string): void;
|
|
/**
|
|
* 清理不活跃的客户端
|
|
*/
|
|
cleanupInactiveClients(timeoutMs?: number): void;
|
|
/**
|
|
* 获取客户端统计信息
|
|
*/
|
|
getClientStats(): {
|
|
total: number;
|
|
controlling: number;
|
|
idle: number;
|
|
};
|
|
/**
|
|
* 🔐 恢复用户的设备权限
|
|
*/
|
|
restoreUserPermissions(userId: string, clientId: string): void;
|
|
/**
|
|
* 🔐 设置客户端用户信息
|
|
*/
|
|
setClientUserInfo(clientId: string, userId: string, username: string): void;
|
|
/**
|
|
* 🛡️ 记录权限操作审计日志
|
|
*/
|
|
private logPermissionOperation;
|
|
}
|
|
export default WebClientManager;
|
|
//# sourceMappingURL=WebClientManager.d.ts.map
|