Skip to main content

Room

Room

Represents a room on the server. Manages the connection to the server and the datastore.

Static Methods

GetRegionsListAsync

Task<GetRegionsListResponse> GetRegionsListAsync(GetRegionsListOptions options, CancellationToken cancellationToken = null)

Gets the server regions available to host rooms for a Normcore app.

A task that represents the asynchronous operation. The task result contains the regions returned by the matcher.

  • options:The parameters used to configure the request.
  • cancellationToken:A cancellation token that can be used to cancel the asynchronous operation.
  • Events

    connectionStateChanged

    event ConnectionStateChanged connectionStateChanged

    Invoked when the connection state changes. When the state changes to the [Normal.Realtime.Room.ConnectionState.Error](Normal.Realtime.Room.ConnectionState#error) and [Normal.Realtime.Room.ConnectionState.Disconnected](Normal.Realtime.Room.ConnectionState#disconnected) states the subscriber can access the [Normal.Realtime.Room.disconnectEvent](Normal.Realtime.Room#disconnectevent) property to determine the reason.

    rpcMessageReceived

    event RPCMessageReceived rpcMessageReceived

    onWillWrite

    event RoomEventHandler onWillWrite

    onWillRead

    event RoomEventHandler onWillRead

    onDidWrite

    event RoomEventHandler onDidWrite

    onDidRead

    event RoomEventHandler onDidRead

    Properties

    name

    string name { get; }

    The name of the room.

    quickmatchRoom

    bool quickmatchRoom { get; }

    Whether the room was created using the Quickmatch backend.

    quickmatchRoomGroupName

    string quickmatchRoomGroupName { get; }

    The name of the room group this room belongs to, if it is a Quickmatch room.

    quickmatchRoomCode

    string quickmatchRoomCode { get; }

    A short code which identifies the room in the room group, if it is a Quickmatch room.

    quickmatchRoomCapacity

    int? quickmatchRoomCapacity { get; }

    The number of clients that can be simultaneously connected to the room, if it is a Quickmatch room.

    region

    RegionMetadata? region { get; }

    The server region the room is hosted in.

    This will be null until connected to the server.

    clientID

    int clientID { get; }

    The ID of the local client on the server.

    This will be -1 until connected to the server.

    time

    double time { get; }

    The server time on this frame in unix epoch time format (seconds since 00:00:00 UTC on January 1, 1970).

    This value can be used to drive animations and is backed by a monotonic clock with sub-millisecond precision. This value has latency from the server removed.

    dateTime

    DateTime? dateTime { get; }

    The server date and time on this frame (UTC).

    This value can be used to drive day/night cycles, for example. It is directly derived from . Will be null when the room is not yet in the state.

    ping

    float ping { get; }

    The local client's last known ping with the server in milliseconds.

    connectionState

    ConnectionState connectionState { get; }

    The connection state of the room.

    disconnectEvent

    DisconnectEvent disconnectEvent { get; }

    The disconnect data for the last disconnect event. Access only within the [Normal.Realtime.Room.connectionStateChanged](Normal.Realtime.Room#connectionstatechanged) callback for [Normal.Realtime.Room.ConnectionState.Error](Normal.Realtime.Room.ConnectionState#error) and [Normal.Realtime.Room.ConnectionState.Disconnected](Normal.Realtime.Room.ConnectionState#disconnected).

    connecting

    bool connecting { get; }

    True if the room is connecting to the server.

    connected

    bool connected { get; }

    True if the room is connected to the server.

    disconnected

    bool disconnected { get; }

    True if the room is disconnected or in an error state.

    offlineMode

    bool offlineMode { get; }

    True if the client was started in offline mode with no networking capabilities.

    datastoreFrameDuration

    double datastoreFrameDuration { get; set; }

    debugLogging

    bool debugLogging { get; set; }

    realtime

    Component realtime { get; set; }

    datastore

    Datastore datastore { get; }

    Methods

    Dispose

    void Dispose()

    Connect

    void Connect(string roomName, ConnectOptions connectOptions)

    Connect to a room.

  • roomName:The name of the room to connect to. All clients that connect to the same room name will end up on the same room server. Must be less than 512 characters in length.
  • connectOptions:An optional struct that can be used to set the appKey, matcherURL, roomModel, and more.
  • ConnectDirectlyToQuickmatchRoom

    void ConnectDirectlyToQuickmatchRoom(string roomGroupName, string roomCode, ConnectOptions connectOptions)

    Connect to an existing Quickmatch room.

  • roomGroupName:The room group the room belongs to.
  • roomCode:The short code identifying which room in the room group to connect to.
  • connectOptions:An optional struct that can be used to set the appKey, matcherURL, roomModel, and more.
  • ConnectToNextAvailableQuickmatchRoom

    void ConnectToNextAvailableQuickmatchRoom(string roomGroupName, int capacity, ConnectOptions connectOptions)

    Connect to a room using Quickmatch.

    The client will connect to a room in the Quickmatch room group that has remaining capacity. If all rooms in the room group are full, the client connects to a new room added to the room group. When searching for remaining capacity, the capacity specified when each room was originally added is used. Therefore, if the client is connected to an existing room, the capacity of the room may be different from the requested capacity. To reconnect to a Quickmatch room, store the after the room is first connected and use ConnectDirectlyToQuickmatchRoom() with that room code later. However, reconnecting is not guaranteed, as the room may be filled with new clients before the reconnect is initiated.

  • roomGroupName:The room group to search for rooms in. Must be 1-32 characters in length, start with a letter, and end with an alphanumeric character. Hyphens and underscores are permitted.
  • capacity:If all existing Quickmatch rooms in the room group are full, or none exist yet, this specifies the number of clients that can be simultaneously connected to the new room. Must be larger than 1 and no greater than 500.
  • connectOptions:An optional struct that can be used to set the appKey, matcherURL, roomModel, and more.
  • Disconnect

    void Disconnect()

    Disconnect from the room.

    Tick

    void Tick(double deltaTime)

    SendRPCMessage

    bool SendRPCMessage(byte[] data, bool reliable)

    SendRPCMessage

    bool SendRPCMessage(byte[] data, int dataLength, bool reliable)

    CreateAudioInputStream

    AudioInputStream CreateAudioInputStream(bool voice, int sampleRate, int channels)

    GetAudioOutputStream

    AudioOutputStream GetAudioOutputStream(int clientID, int streamID)

    GetConnectionStatistics

    ConnectionStatistics? GetConnectionStatistics(ChannelFlags channels = All)

    Gets the connection statistics for the room.

    This can be used to monitor the quality of the connection to the server. Connection statistics are not available in WebGL builds.

    The connection statistics for the specified channels. Will be until connected and the first batch of statistics is collected, or when in a WebGL build.

  • channels:The channel(s) to get the statistics for. The resulting channel statistics will be the total across all the selected channels.