The Rooms interface manages the lifecycle of chat rooms.
Access it via the rooms property on a ChatClient instance.
1
val rooms = chatClient.roomsCreate or retrieve a room
suspend rooms.get(roomName: String, initOptions: MutableRoomOptions.() -> Unit): RoomCreate or retrieve a Room instance. Optionally provide custom configuration to the room using a DSL builder.
Call release() when the Room is no longer needed. If a call to get() is made for a room that is currently being released, then it will only return when the release operation is complete.
If a call to get() is made, followed by a subsequent call to release() before it returns, then an error is thrown.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
val room = chatClient.rooms.get("basketball-stream") {
typing {
heartbeatThrottle = 5.seconds
}
presence {
enableEvents = false
}
occupancy {
enableEvents = true
}
messages {
rawMessageReactions = false
defaultMessageReactionType = MessageReactionType.Unique
}
}
// When finished with the room
chatClient.rooms.release("basketball-stream")Parameters
The get() method takes the following parameters:
namerequiredStringoptionsoptionalRoomOptionsReturns
This is a suspend function. It returns the new or existing Room instance, or throws a ChatException. It also throws if the room already exists with different options, or if release() is called before get() returns.
Release a room
suspend rooms.release(name: String): UnitReleases a room, freeing its resources and detaching it from Ably.
After release, the room object is no longer usable. To use the room again, call get() to create a new instance.
1
chatClient.rooms.release("my-room")Parameters
The release() method takes the following parameters:
namerequiredStringReturns
Unit
This is a suspend function. It completes when the room is fully released, or throws a ChatException on failure.
Subscription
A Subscription is a functional interface returned by subscribe() and onStatusChange() methods throughout the SDK. It provides a single method to deregister the listener.
unsubscribe()Unit