add getRoomsForConnection

This commit is contained in:
nvms 2025-04-18 16:25:04 -04:00
parent af2cf5a4a4
commit 6bd9803c61

View File

@ -67,6 +67,21 @@ export class RoomManager {
await this.redis.sadd(this.connectionsRoomKey(connectionId), roomName);
}
/**
* Retrieves a list of rooms that the specified connection is currently a member of.
*
* @param {Connection | string} connection - The connection object or connection ID for which to retrieve room memberships.
* @returns {Promise<string[]>} A promise that resolves to an array of room names associated with the connection.
* @throws {Error} If the underlying Redis operation fails, the promise will be rejected with an error.
*/
async getRoomsForConnection(
connection: Connection | string
): Promise<string[]> {
const connectionId =
typeof connection === "string" ? connection : connection.id;
return await this.redis.smembers(this.connectionsRoomKey(connectionId));
}
/**
* Removes a connection from a specified room and updates Redis accordingly.
* Accepts either a Connection object or a string representing the connection ID.