Class SFS2X.Requests.System.JoinRoomRequest

Joins the current user in a Room.

Class Summary
Constructor Attributes Constructor Name and Description
 
SFS2X.Requests.System.JoinRoomRequest(room, password, roomIdToLeave, asSpect)
Creates a new JoinRoomRequest instance.

Class Detail

SFS2X.Requests.System.JoinRoomRequest(room, password, roomIdToLeave, asSpect)
Creates a new JoinRoomRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

This request joins the current user in a Room. If the operation is successful, the current user receives a roomJoin event; otherwise the roomJoinError 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: userEnterRoom, dispatched to the other users inside the Room to warn them that a new user has arrived; userCountChange, dispatched to all clients which subscribed the Group to which the Room belongs, to update the count of users inside the Room.

The following example makes the user join an existing Room:

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN, onRoomJoined, this);
	sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError, this);
	
	// Join a Room called "Lobby"
	sfs.send(new SFS2X.Requests.System.JoinRoomRequest("Lobby"));
}

function onRoomJoined(evtParams)
{
	console.log("Room joined successfully: " + evtParams.room);
}

function onRoomJoinError(evtParams)
{
	console.log("Room joining failed: " + evtParams.errorMessage);
}
Parameters:
{*} room
The id or the name of the Room to be joined.
{String} password Optional
The password of the Room, in case it is password protected.
{Number} roomIdToLeave Optional, Default: the last joined Room
The id of a previously joined Room that the user should leave when joining the new Room. By default, the last joined Room is left; if a negative number is passed, no previous Room is left.
{Boolean} asSpect Optional, Default: false
true to join the Room as a spectator (in Game Rooms only).
See also:
SFS2X.SmartFox#send
SFS2X.Requests.RoomSettings#events
SFS2X.SFSEvent.ROOM_JOIN
SFS2X.SFSEvent.ROOM_JOIN_ERROR
SFS2X.SFSEvent.USER_ENTER_ROOM
SFS2X.SFSEvent.USER_COUNT_CHANGE