### Javascript
```
const room = await chatClient.rooms.get('basketball-stream', {occupancy: {enableEvents: true}});
```
### React
```
import { createClient } from '@ably/pubsub-device';
import { createChatClient, LogLevel } from '@ably/chat';
import { ChatClientProvider, ChatRoomProvider } from '@ably/chat/react';
const pubsubDeviceClient = createClient({ key: 'your-api-key', clientId: 'clientId' });
const chatClient = createChatClient(pubsubDeviceClient);
const App = () => {
return (
);
};
```
### Swift
```
let room = try await chatClient.rooms.get(named: "basketball-stream", options: .init(occupancy: .init(enableEvents: true)))
```
### Kotlin
```
val room = chatClient.rooms.get(name = "basketball-stream")
```
### Android
```
val room = chatClient.rooms.get(name = "basketball-stream")
```
### Javascript
```
const options: RoomOptions = {
typing: {
heartbeatThrottleMs: 5000,
},
presence: {
enableEvents: true,
},
occupancy: {
enableEvents: true,
},
};
const room = await chatClient.rooms.get('basketball-stream', options);
```
### Swift
```
let presence = PresenceOptions(enableEvents: false)
let typing = TypingOptions(heartbeatThrottle: 5.0) // seconds
// using defaults for reactions and occupancy
let options = RoomOptions(presence: presence, typing: typing, occupancy: .init())
let room = try await chatClient.rooms.get(named: "basketball-stream", options: options)
```
### Kotlin
```
val room = chatClient.rooms.get("basketball-stream") {
typing {
heartbeatThrottle = 5.seconds
}
presence {
enableEvents = true
}
occupancy {
enableEvents = true
}
}
```
### Android
```
val room = chatClient.rooms.get("basketball-stream") {
typing {
heartbeatThrottle = 5.seconds
}
presence {
enableEvents = true
}
occupancy {
enableEvents = true
}
}
```
The details of the options available to each feature are documented on their respective pages:
| Feature | `RoomOption` | Default settings |
| ------- | ------------ | ---------------- |
| [Presence](https://ably.com/docs/chat/rooms/presence.md) | `presence.enableEvents` | `true` |
| [Occupancy](https://ably.com/docs/chat/rooms/occupancy.md) | `occupancy.enableEvents` | `false` |
| [Typing indicators](https://ably.com/docs/chat/rooms/typing.md) | `typing.heartbeatThrottleMs` | `10000` |
#### Javascript
```
await rooms.release('basketball-stream');
```
#### Swift
```
try await rooms.release(named: "basketball-stream")
```
#### Kotlin
```
rooms.release("basketball-stream")
```
#### Android
```
rooms.release("basketball-stream")
```
### Javascript
```
await room.attach();
```
### React
```
import { useRoom } from '@ably/chat/react';
const MyComponent = () => {
const { attach } = useRoom();
return (
);
};
```
### Swift
```
try await room.attach()
```
### Kotlin
```
room.attach()
```
### Android
```
room.attach()
```
> Resilient room state.
>
> Rooms maintain their state during temporary disruptions, with all messages received in correct order and [zero message loss](https://ably.com/docs/platform/architecture/connection-recovery.md).
As soon as a client is attached to a room, Ably will begin streaming messages and events to them. To receive the messages and events in your application code, you need to add listeners to the events that you are interested in by subscribing, for example using the [`messages.subscribe()`](https://ably.com/docs/chat/rooms/messages.md#subscribe) method. Add listeners before attaching to avoid missing any messages or events.
> **Note**
>
> Attaching to a room is simply a way for the client to tell Ably that this client is interested in receiving messages and events from the room. It is not a persistent state and it does not confer membership to the room. Rooms are only attached for the duration of the connection.
>
> Ably Chat currently does not offer a room membership feature where clients belong to rooms long-term. Ably Chat does provide [presence](https://ably.com/docs/chat/rooms/presence.md), which is a way to share information about the users currently in a room, for example to share a status message or a profile picture.
### Detach from a room
#### Javascript
```
await room.detach();
```
#### Swift
```
try await room.detach()
```
#### Kotlin
```
room.detach()
```
#### Android
```
room.detach()
```
### Javascript
```
const currentStatus = room.status;
// The error related to the current room status
const currentError = room.error;
```
### React
```
import { useMessages } from '@ably/chat/react';
const MyComponent = () => {
const { roomStatus, roomError } = useMessages({
listener: (message) => {
console.log('Received message: ', message);
},
});
return (
Room status is: {roomStatus}
Room error is: {roomError?.message}
);
};
```
### Swift
```
let status = room.status
```
### Kotlin
```
val status = room.status
```
### Android
```
val status = room.status
```
### Javascript
```
const { off } = room.onStatusChange((change) =>
console.log(change));
```
### Swift
```
let statusSubscription = room.onStatusChange()
for await status in statusSubscription {
print("Room status: \(status)")
}
```
### Kotlin
```
val (off) = room.onStatusChange { statusChange: RoomStatusChange ->
println(statusChange.toString())
}
```
### Android
```
import androidx.compose.material.*
import androidx.compose.runtime.*
import com.ably.chat.Room
import com.ably.chat.extensions.compose.collectAsStatus
@Composable
fun MyComponent(room: Room) {
val roomStatus by room.collectAsStatus()
LaunchedEffect(roomStatus) {
println("Room status changed to: $roomStatus")
}
Text("Room status: $roomStatus")
}
```
### Javascript
```
off();
```
### Kotlin
```
off()
```
### React
```
import { useOccupancy } from '@ably/chat/react';
const MyComponent = () => {
useOccupancy({
onRoomStatusChange: (roomStatusChange) => {
console.log('Room status change:', roomStatusChange);
},
onDiscontinuity: (error) => {
console.log('Discontinuity detected:', error);
},
});
return Occupancy Component;
};
```