Files
server/dist/managers/WebClientManager.d.ts

132 lines
3.4 KiB
TypeScript
Raw Normal View History

2026-02-09 16:34:01 +08:00
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