Click or drag to resize

StrixNetworkLeaveRoom Method (RoomLeaveEventHandler, FailureEventHandler, RequestConfig)

Leaves the match room this client is currently a member of (if any).

Namespace:  SoftGear.Strix.Unity.Runtime
Assembly:  StrixUnityRuntime (in StrixUnityRuntime.dll) Version: 1.5.0
public void LeaveRoom(
	RoomLeaveEventHandler handler,
	FailureEventHandler failureHandler,
	RequestConfig config = null


Type: SoftGear.Strix.Unity.Runtime.EventRoomLeaveEventHandler
This callback is invoked when leaving the room has finished successfully.
Type: SoftGear.Strix.Unity.Runtime.EventFailureEventHandler
This callback is invoked in case of a failure.
config (Optional)
Type: SoftGear.Strix.Client.Core.RequestRequestConfig
If not null, used to configure the request timeout. Default timeout is 30 seconds. See RequestConfig for more details.
If you are the owner of the room, it gets destroyed.

Possible exception types in FailureEventArgs's cause:
ErrorCodeException Strix error which can be further separated by an error code:
ConnectionErrorFailed to send the request because of a connection error.
RequestTimeoutServer did not respond within the specified timeout interval.
RoomNotFoundRoom is not found or you're not a member of the room.
In this example we first connect to a master server to be able to create a match room named "Fire Tournament 2". After that we search for rooms that have the word "Tournament" in their name to see if the search results contain our newly created room. Then we try to leave the room. Since we just created it we should be the only member, and when the last member leaves the room it is automatically destroyed on the server. After leaving the room we repeat the search to see that the room is no longer there.

Note: Be sure to change the placeholder values of applicationId and host to the real ones that can be found on the Strix Cloud application information tab.
using SoftGear.Strix.Client.Core.Model.Manager.Filter.Builder;
using SoftGear.Strix.Unity.Runtime;
using System;
using System.Collections.Generic;
using UnityEngine;

public class LeaveRoomExample : MonoBehaviour
    void Start()
        var strixNetwork = StrixNetwork.instance;

        strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
            host: "",
            connectEventHandler: _ => {
                Debug.Log("Connection established.");

                    new RoomProperties {
                        name = "Fire Tournament 2",
                        password = "66e3f2nk",
                        capacity = 20,
                        key1 = 4.0,
                        properties = new Dictionary<string, object> { { "description", "The first major tournament of the new season." } }
                    new RoomMemberProperties { name = "Braille" },
                    handler: __ => {
                        Debug.Log("Room created.");

                        SearchForTournament(() => {
                                handler: ___ => {
                                    Debug.Log("Left the room successfully.");
                                    SearchForTournament(() => { });
                                failureHandler: leaveError => Debug.LogError("Could not leave the room. Reason: " + leaveError.cause)
                    failureHandler: createRoomError => Debug.LogError("Could not create room. Reason: " + createRoomError.cause)
            errorEventHandler: connectError => Debug.LogError("Connection failed. Reason: " + connectError.cause)

    void SearchForTournament(Action onFinish)
            condition: ConditionBuilder.Builder().Field("name").Contains("Tournament").Build(),
            limit: 10,
            offset: 0,
            handler: searchResult => {
                Debug.Log("Number of rooms: " + searchResult.roomInfoCollection.Count);
            failureHandler: searchError => Debug.LogError("Search failed. Reason: " + searchError.cause)
See Also