### Javascript
```
const room = await chatClient.rooms.get('basketball-stream', {occupancy: {enableEvents: true}});
```
### React
```
import * as Ably from 'ably';
import { LogLevel } from '@ably/chat';
import { ChatClientProvider, ChatRoomProvider } from '@ably/chat/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")
```
### Android
```
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(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(roomId = "basketball-stream") {
typing {
heartbeatThrottle = 5.seconds
}
presence {
enableEvents = true
}
occupancy {
enableEvents = true
}
}
```
### Android
```
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.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()
```
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.
### 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}
);
};
```
### 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;
};
```