UNPKG

matterbridge-roborock-vacuum-plugin

Version:
50 lines 1.67 kB
import { ClientRouter } from '../roborockCommunication/routing/clientRouter.js'; /** Manages ClientRouter instances per user with caching and cleanup. */ export default class ClientManager { logger; clients = new Map(); constructor(logger) { this.logger = logger; } /** Get or create ClientRouter for a user. */ get(userdata) { const username = userdata.username; if (!userdata || username.trim().length === 0) { throw new Error('Username cannot be empty'); } if (!this.clients.has(username)) { this.clients.set(username, new ClientRouter(this.logger, userdata)); } const client = this.clients.get(username); if (!client) { throw new Error(`Failed to create client for user: ${username}`); } return client; } /** Disconnect and remove a user's client. */ destroy(username) { const client = this.clients.get(username); if (client) { try { client.disconnect(); } catch (error) { this.logger.error(`Error disconnecting client for ${username}:`, error); } this.clients.delete(username); } } /** Disconnect all clients (for shutdown). */ destroyAll() { for (const [username, client] of this.clients) { try { client.disconnect(); } catch (error) { this.logger.error(`Error disconnecting client for ${username}:`, error); } } this.clients.clear(); } } //# sourceMappingURL=clientManager.js.map