> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/ably/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Occupancy

Occupancy enables you to view the number of users currently online in a room. This feature can be used to display user counts to highlight popular, or trending chat rooms.

## Subscribe to Room Occupancy

<Tabs>
  <Tab name="JavaScript">
    <Code>
      ```javascript theme={null}
      const {unsubscribe} = room.occupancy.subscribe((event) => {
        console.log(event);
      });
      ```
    </Code>
  </Tab>

  <Tab name="React">
    <Code>
      ```react theme={null}
      import { useOccupancy } from '@ably/chat/react';

      const MyComponent = () => {
        const { connections, presenceMembers } = useOccupancy({
          listener: (occupancyEvent) => {
            console.log('Number of users connected is: ', occupancyEvent.occupancy.connections);
          },
        });
        return (
          <div>
            <p>Number of users connected is: {connections}</p>
            <p>Number of members present is: {presenceMembers}</p>
          </div>
        );
      };
      ```
    </Code>
  </Tab>

  <Tab name="Swift">
    <Code>
      ```swift theme={null}
      let occupancySubscription = room.occupancy.subscribe()
      for await event in occupancySubscription {
        occupancyInfo = "Connections: \(event.occupancy.presenceMembers) (\(event.occupancy.connections))"
      }
      ```
    </Code>
  </Tab>

  <Tab name="Android / Kotlin">
    <Code>
      ```android theme={null}
      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}")
      }
      ```
    </Code>
  </Tab>
</Tabs>

## Retrieve Room Occupancy

<Tabs>
  <Tab name="JavaScript">
    <Code>
      ```javascript theme={null}
      const occupancy = await room.occupancy.get();
      ```
    </Code>
  </Tab>

  <Tab name="Swift">
    <Code>
      ```swift theme={null}
      let occupancy = try await room.occupancy.get()
      ```
    </Code>
  </Tab>

  <Tab name="Android / Kotlin">
    <Code>
      ```android theme={null}
      val occupancy = room.occupancy.get()
      ```
    </Code>
  </Tab>
</Tabs>

## Next Steps

* Learn about [messages](/docs/chat/rooms/messages)
* Explore [presence](/docs/chat/rooms/presence)
* Understand [typing indicators](/docs/chat/rooms/typing-indicators)
