```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}")
}
```
```jetpack
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
```
```jetpack
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) 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()
```
```jetpack
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) of the room. | Number |