WebSockets & Real-Time Communication

What strategies should be used for WebSocket connection pooling?
class WebSocketPool {
    constructor(maxConnections = 5) {
        this.pool = new Map();
        this.maxConnections = maxConnections;
    }

    async getConnection(userId) {
        if (this.pool.has(userId)) {
            return this.pool.get(userId);
        }

        if (this.pool.size >= this.maxConnections) {
            const oldestUserId = this.findOldestConnection();
            await this.removeConnection(oldestUserId);
        }

        const connection = await this.createConnection(userId);
        this.pool.set(userId, connection);
        return connection;
    }

    async removeConnection(userId) {
        const connection = this.pool.get(userId);
        if (connection) {
            await connection.close();
            this.pool.delete(userId);
        }
    }
}
Next Question (14/17)