```javascript
const room = await chatClient.rooms.get('basketball-stream', {occupancy: {enableEvents: true}});
```
```react
const realtimeClient = new Ably.Realtime({ key: 'your-api-key', clientId: 'clientId' });
const chatClient = new ChatClient(realtimeClient);
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(roomId = "basketball-stream")
```
```jetpack
val room = chatClient.rooms.get(roomId = "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(enter: 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(roomId = "basketball-stream") {
typing {
heartbeatThrottle = 5.seconds
}
presence {
enableEvents = true
}
occupancy {
enableEvents = true
}
}
```
```jetpack
val room = chatClient.rooms.get(roomId = "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) | `presence.enableEvents` | `true` |
| [Occupancy](https://ably.com/docs/chat/rooms/occupancy) | `occupancy.enableEvents` | `false` |
| [Typing indicators](https://ably.com/docs/chat/rooms/typing) | `typing.heartbeatThrottleMs` | `10000` |
```javascript
await rooms.release('basketball-stream');
```
```swift
try await rooms.release(named: "basketball-stream")
```
```kotlin
rooms.release("basketball-stream")
```
```jetpack
rooms.release("basketball-stream")
```
```javascript
await room.attach();
```
```react
const MyComponent = () => {
const { attach } = useRoom();
return (
);
};
```
```swift
try await room.attach()
```
```kotlin
room.attach()
```
```jetpack
room.attach()
```
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#subscribe) method. Add listeners before attaching to avoid missing any messages or events.
### Detach from a room
```javascript
await room.detach();
```
```swift
try await room.detach()
```
```kotlin
room.detach()
```
```jetpack
room.detach()
```
```javascript
const currentStatus = room.status;
// The error related to the current room status
const currentError = room.error;
```
```react
const MyComponent = () => {
const { roomStatus, roomError } = useMessages({
listener: (message) => {
console.log('Received message: ', message);
},
});
return (
Room status is: {roomStatus}
Room error is: {roomError}
);
};
```
```swift
let status = room.status
```
```kotlin
val status = room.status
```
```jetpack
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())
}
```
```jetpack
const MyComponent = () => {
useOccupancy({
onRoomStatusChange: (roomStatusChange) => {
console.log('Room status change:', roomStatusChange);
},
onDiscontinuity: (error) => {
console.log('Discontinuity detected:', error);
},
});
return Occupancy Component;
};
```