diff --git a/packages/mesh/src/server/room-manager.ts b/packages/mesh/src/server/room-manager.ts index 8746825..babede4 100644 --- a/packages/mesh/src/server/room-manager.ts +++ b/packages/mesh/src/server/room-manager.ts @@ -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} 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 { + 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.