### Javascript
```
const {unsubscribe} = room.occupancy.subscribe((event) => {
console.log(event);
});
```
### React
```
import { useOccupancy } from '@ably/chat/react';
const MyComponent = () => {
const { connections, presenceMembers } = useOccupancy({
listener: (occupancyEvent) => {
console.log('Number of users connected is: ', occupancyEvent.occupancy.connections);
console.log('Number of members present is: ', occupancyEvent.occupancy.presenceMembers);
},
});
return (
Number of users connected is: {connections}
Number of members present is: {presenceMembers}
);
};
```
### Swift
```
let occupancySubscription = room.occupancy.subscribe()
for await event in occupancySubscription {
occupancyInfo = "Connections: \(event.occupancy.presenceMembers) (\(event.occupancy.connections))"
}
```
### Kotlin
```
val subscription = room.occupancy.subscribe { event: OccupancyEvent ->
println("Number of users connected is: ${event.occupancy.connections}")
println("Number of members present is: ${event.occupancy.presenceMembers}")
}
```
### Android
```
import androidx.compose.material.*
import androidx.compose.runtime.*
import com.ably.chat.Room
import com.ably.chat.extensions.compose.collectAsOccupancy
@Composable
fun OccupancyComponent(room: Room) {
val occupancy by room.collectAsOccupancy()
Text("Number of users connected: ${occupancy.connections}")
Text("Number of members present: ${occupancy.presenceMembers}")
}
```
### Occupancy event structure
The following is the structure of an occupancy event:
#### Json
```
{
"type": "occupancy.updated",
"occupancy": {
"connections": 103,
"presenceMembers": 95
}
}
```
#### Json
```
{
"connections": 103,
"presenceMembers": 95
}
```
#### Javascript
```
// Initial subscription
const { unsubscribe } = room.occupancy.subscribe((event) => {
console.log(event);
});
// To remove the listener
unsubscribe();
```
#### Kotlin
```
// Initial subscription
val (unsubscribe) = room.occupancy.subscribe { event ->
println(event)
}
// To remove the listener
unsubscribe()
```
### Javascript
```
const occupancy = room.occupancy.current;
```
### Swift
```
let occupancy = room.occupancy.current
```
### Kotlin
```
val occupancy = room.occupancy.current
```
### Android
```
val occupancy = room.occupancy.current
```
### Json
```
{
"connections": 103,
"presenceMembers": 95,
}
```
The following are the properties of the occupancy data:
| Property | Description | Type |
| -------- | ----------- | ---- |
| `connections` | The number of connections in the room. | `Number` |
| `presenceMembers` | The number of users entered into the [presence set](https://ably.com/docs/chat/rooms/presence.md?source=llms.txt) of the room. | `Number` |
## Retrieve room occupancy
### Javascript
```
const occupancy = await room.occupancy.get();
```
### Swift
```
let occupancy = try await room.occupancy.get()
```
### Kotlin
```
val occupancy = room.occupancy.get()
```
### Android
```
val occupancy = room.occupancy.get()
```
### Json
```
{
"connections": 103,
"presenceMembers": 95,
}
```
The following are the properties of an occupancy data:
| Property | Description | Type |
| -------- | ----------- | ---- |
| `connections` | The number of connections in the room. | `Number` |
| `presenceMembers` | The number of users entered into the [presence set](https://ably.com/docs/chat/rooms/presence.md?source=llms.txt) of the room. | `Number` |
## Related Topics
- [Messages](https://ably.com/docs/chat/rooms/messages.md?source=llms.txt): Send, update, delete, and receive messages in chat rooms.
- [Message history](https://ably.com/docs/chat/rooms/history.md?source=llms.txt): Retrieve previously sent messages from history.
- [Presence](https://ably.com/docs/chat/rooms/presence.md?source=llms.txt): Use presence to see which users are online and their user status.
- [Message reactions](https://ably.com/docs/chat/rooms/message-reactions.md?source=llms.txt): React to chat messages
- [Typing indicators](https://ably.com/docs/chat/rooms/typing.md?source=llms.txt): Display typing indicators in a room so that users can see when someone else is writing a message.
- [Room reactions](https://ably.com/docs/chat/rooms/reactions.md?source=llms.txt): Enable users to send reactions at the room level, based on what is happening in your application, such as a goal being scored in your livestream.
- [Share media](https://ably.com/docs/chat/rooms/media.md?source=llms.txt): Share media such as images, videos, or files in a chat room.
- [Message replies](https://ably.com/docs/chat/rooms/replies.md?source=llms.txt): Add reply functionality to messages in a chat room.
## Documentation Index
To discover additional Ably documentation:
1. Fetch [llms.txt](https://ably.com/llms.txt?source=llms.txt) for the canonical list of available pages.
2. Identify relevant URLs from that index.
3. Fetch target pages as needed.
Avoid using assumed or outdated documentation paths.