Click or drag to resize

JoinRoomRequest Class

Joins the current user in a Room.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.RequestsJoinRoomRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class JoinRoomRequest : BaseRequest
Constructors
Remarks
If the operation is successful, the current user receives a ROOM_JOIN event; otherwise the ROOM_JOIN_ERROR event is fired. This usually happens when the Room is full, or the password is wrong in case of password protected Rooms.

Depending on the Room configuration defined upon its creation (see the RoomSettings.Events setting), when the current user joins it, the following events might be fired: USER_ENTER_ROOM, dispatched to the other users inside the Room to warn them that a new user has arrived; USER_COUNT_CHANGE, dispatched to all clients which subscribed the Group to which the Room belongs, to update the count of users inside the Room.

Examples
The following example makes the user join an existing Room:
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom);
    sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError);

    // Join a Room called "Lobby"
    sfs.Send( new JoinRoomRequest("Lobby") );
}

void OnJoinRoom(BaseEvent evt) {
    Console.WriteLine("Room joined successfully: " + (Room)evt.Params["room"]);                         // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Room joined successfully: " + (Room)evt.Params["room"]);        // UWP
}

void OnJoinRoomError(BaseEvent evt) {
    Console.WriteLine("Room joining failed: " + (string)evt.Params["errorMessage"]);                        // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Room joining failed: " + (string)evt.Params["errorMessage"]);       // UWP
}
See Also