# Rooms

## Rooms API

Rooms functionality can be accessed through the `PlayResolver` which includes all the methods needed to use rooms.

#### Regions

To manage rooms we must first decide which region we are working with.

```
async Task<(IReadOnlyList<string>, bool)> FetchRegions()
```

`FetchRegions` in `PlayResolver.cs` allows us to fetch the regions available for our project. This task returns a list of regions (as strings) and a boolean that indicates if the operation was successful.

```
async Task<string> FetchLocalRegions()
```

`FetchLocalRegions` in `PlayResolver.cs` returns the local region string for a local running rooms server, or null if the operation is un-successful (if the server isn't running for example).

Every other rooms API will require a region string that indicates the relevant region for the operation so these strings should not be changed before using them for other operations.

The `RoomsConnectDialog` populates a dropdown with the region strings returned by both of these methods directly for easy selection.

{% hint style="info" %}
These methods also call `EnsurePlayConnection` which initializes the needed mechanisms in the `PlayResolver` if necessary. `EnsurePlayConnection` can also be called directly for initialization.
{% endhint %}

#### Room management

After we have the available regions we can start managing rooms, for instance:

```
async Task<(Result, RoomData)> CreateRoom(string region,
                string roomName = null,
                int maxClients = 10,
                string[] tags = null,
                Dictionary<string, string> keyValues = null)
```

`CreateRoom` in `PlayResolver.cs` allows us to create a room in the region we send it.

We can also optionally specify:

* a room name
* the maximal number of clients allowed for the room
* a list of tags for room filtering and other uses
* a key-value collection for the room

This task returns the operations result and `RoomData` for the created room assuming the operation was successful.

```
async Task<IReadOnlyList<RoomData>> FetchRooms(string region,
                string[] tags = null)
```

`FetchRooms` in `PlayResolver.cs` allows us to search for available rooms in a region. We can also optionally specify tags for filtering the rooms.

This task returns a list of `RoomData` objects for the rooms available for our specifications.

```
void JoinRoom(IClient client, RoomData room)
```

`JoinRoom` in `PlayResolver.cs` connects the client that we pass to the method to the room we pass to the method. This `RoomData` object can be either the one we get back from `CreateRoom`  or one of the ones we got from `FetchRooms`.&#x20;

The `RoomsConnectDialog` demonstrates both of these cases in `CreateRoom` when called with true for autoJoin and in `JoinRoom`  respectively.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coherence.io/0.7.4/api-reference/network-sdk/rooms.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
