diff --git a/chat-android/src/main/java/com/ably/chat/ChatClient.kt b/chat-android/src/main/java/com/ably/chat/ChatClient.kt index e043411..6a1d06d 100644 --- a/chat-android/src/main/java/com/ably/chat/ChatClient.kt +++ b/chat-android/src/main/java/com/ably/chat/ChatClient.kt @@ -12,7 +12,7 @@ interface ChatClient { /** * The rooms object, which provides access to chat rooms. */ - val room: Room + val rooms: Rooms /** * The underlying connection to Ably, which can be used to monitor the clients diff --git a/chat-android/src/main/java/com/ably/chat/Rooms.kt b/chat-android/src/main/java/com/ably/chat/Rooms.kt new file mode 100644 index 0000000..e4fd7ff --- /dev/null +++ b/chat-android/src/main/java/com/ably/chat/Rooms.kt @@ -0,0 +1,37 @@ +package com.ably.chat + +/** + * Manages the lifecycle of chat rooms. + */ +interface Rooms { + /** + * Get the client options used to create the Chat instance. + */ + val clientOptions: ClientOptions + + /** + * Gets a room reference by ID. The Rooms class ensures that only one reference + * exists for each room. A new reference object is created if it doesn't already + * exist, or if the one used previously was released using release(roomId). + * + * Always call `release(roomId)` after the Room object is no longer needed. + * + * @param roomId The ID of the room. + * @param options The options for the room. + * @throws {@link ErrorInfo} if a room with the same ID but different options already exists. + * @returns Room A new or existing Room object. + */ + fun get(roomId: String, options: RoomOptions): Room + + /** + * Release the Room object if it exists. This method only releases the reference + * to the Room object from the Rooms instance and detaches the room from Ably. It does not unsubscribe to any + * events. + * + * After calling this function, the room object is no-longer usable. If you wish to get the room object again, + * you must call {@link Rooms.get}. + * + * @param roomId The ID of the room. + */ + suspend fun release(roomId: String) +}