JoinRoomRequest
Joins the current user in a Room.
new JoinRoomRequest(room[, password][, roomIdToLeave][, asSpectator])
Creates a new JoinRoomRequest instance. The instance must be passed to the SmartFox.send() method for the request to be executed.
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.
Example
This 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.JoinRoomRequest("Lobby"));
}
function onRoomJoined(evtParams)
{
console.log("Room joined successfully: " + evtParams.room);
}
function onRoomJoinError(evtParams)
{
console.log("Room joining failed: " + evtParams.errorMessage);
}
Parameters
Name | Type | Optional | Description |
---|---|---|---|
room |
|
|
The id or the name of the Room to be joined. A SFSRoom object can be passed too. |
password |
|
Yes |
The password of the Room, in case it is password protected. Defaults to |
roomIdToLeave |
|
Yes |
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. Defaults to |
asSpectator |
|
Yes |
Defaults to |