Rooms API

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


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.
These methods also call EnsurePlayConnection which initializes the needed mechanisms in the PlayResolver if necessary. EnsurePlayConnection can also be called directly for initialization.

Room management

After we have the available regions we can start managing Rooms, for instance:
async Task<RoomData> CreateRoom(string region, RoomCreationOptions options = null)
CreateRoom in PlayResolver.cs allows us to create a Room in the region we send it.
the RoomCreationOptions is used to optionally specify:
  • a Room name
  • the maximum 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 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, bool isSimulator = false)
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.
When joining a Room, the method is optionally supplied if the connecting Client is a Simulator, as well.
The RoomsConnectDialog demonstrates both of these cases in CreateRoom when called with true for autoJoin and in JoinRoom respectively.
RemoveRoom in PlayResolver.cs allows us to close a Room. The uniqueID can be either the one we get back from CreateRoom or one of the ones we got from FetchRooms, but roomToken (Room's Secret) is only returned by CreateRoom.
async Task RemoveRoom(string region, ulong uniqueID, string roomToken)
Last modified 2mo ago