new SFSRoom()

Developers never istantiate the SFSRoom class: this is done internally by the SmartFoxServer 2X API.

The Room is the basic structure used to group users connected to SmartFoxServer 2X. The client API is not aware of all the Rooms existing on the server side, but only of those that are joined by the user and those in the Room Groups that have been subscribed. Subscribing to one or more Groups allows the client to listen to Room events in specific "areas" of the Zone, without having to retrieve and keep synchronized the details of all available Rooms, thus reducing the traffic between the client and the server considerably.

The list of available Rooms is created after a successful login and it is kept updated continuously by the server.

See also
SmartFox#roomManager
CreateRoomRequest
JoinRoomRequest
SubscribeRoomGroupRequest
UnsubscribeRoomGroupRequest
ChangeRoomNameRequest
ChangeRoomPasswordStateRequest
ChangeRoomCapacityRequest

Properties

read-only

capacity  number

Returns the maximum amount of users, including spectators, that can be contained in this Room.

See also
ChangeRoomCapacityRequest
read-only

groupId  string

Returns the Room Group name. Each Group is identified by a unique string (its name or id) and it represents a different "container" for Rooms.

Room Groups enable developers to organize Rooms under different types or categories and let clients select only those Groups they are interested in, in order to receive their events only. This is done via the SubscribeRoomGroupRequest and UnsubscribeRoomGroupRequest requests.

See also
SubscribeRoomGroupRequest
UnsubscribeRoomGroupRequest
read-only

id  number

Indicates the id of this Room. The id is unique and it is generated by the server when the Room is created.

read-only

isGame  boolean

Indicates whether this is a Game Room or not.

read-only

isHidden  boolean

Indicates whether this Room is hidden or not. This is a utility flag that can be used by developers to hide certain Rooms from the interface of their application.

read-only

isJoined  boolean

Indicates whether the client joined this Room or not. Use the JoinRoomRequest request to join a new Room.

See also
JoinRoomRequest
read-only

isPasswordProtected  boolean

Indicates whether this Room requires a password to be joined or not. This flag depends on the Room's password set when the Room is created or by means of the ChangeRoomPasswordStateRequest request.

See also
ChangeRoomPasswordStateRequest
read-only

maxSpectators  number

Returns the maximum number of spectators allowed in this Room (Game Rooms only). If allowed, the maxSpectators value can be changed through the ChangeRoomCapacityRequest request.

See also
ChangeRoomCapacityRequest
read-only

maxUsers  number

Returns the maximum number of users allowed in this Room. In case of Game Rooms, this is the maximum number of players. If allowed, the maxUsers value can be changed through the ChangeRoomCapacityRequest request.

See also
ChangeRoomCapacityRequest
read-only

name  string

Indicates the name of this Room. Two Rooms in the same Zone can't have the same name. If allowed, the name can be changed through the ChangeRoomNameRequest request.

See also
ChangeRoomNameRequest

properties  object

Defines a generic utility object that can be used to store custom Room data. The values added to this object are for client-side use only and are never transmitted to the server or to the other clients.

read-only

spectatorCount  number

Returns the current number of spectators in this Room (Game Rooms only).

read-only

userCount  number

Returns the current number of users in this Room. In case of Game Rooms, this is the number of players.

Methods

containsUser(user) → boolean

Indicates whether the specified user is currently inside this Room or not.

Parameter

Name Type Optional Description

user

SFSUser

 

The SFSUser object representing the user whose presence in this Room must be checked.

Returns

boolean true if the user is inside this Room; false otherwise.

containsVariable(varName) → boolean

Indicates whether this Room has the specified Room Variable set or not.

Parameter

Name Type Optional Description

varName

string

 

The name of the Room Variable whose existance in this Room must be checked.

See also
SFSRoomVariable
Returns

boolean true if a Room Variable with the passed name exists in this Room.

getPlayerList() → Array of SFSUser

Retrieves the list of SFSUser objects representing the players currently inside this Room (Game Rooms only).

Returns

Array of SFSUser The list of SFSUser objects representing the users who joined the Room as players.

getRoomManager() → SFSRoomManager

Retrieves a reference to the Room Manager which manages this Room.

Returns

SFSRoomManager The Room Manager to which this Room is associated.

getSpectatorList() → Array of SFSUser

Retrieves the list of SFSUser objects representing the spectators currently inside this Room (Game Rooms only).

Returns

Array of SFSUser The list of SFSUser objects representing the users who joined the Room as spectators.

getUserById(id) → SFSUser

Retrieves a SFSUser object from its id property.

Parameter

Name Type Optional Description

id

number

 

The id of the user to be found.

Returns

SFSUser An object representing the user, or undefined if no user with the passed id exists in this Room.

getUserByName(name) → SFSUser

Retrieves a SFSUser object from its name property.

Parameter

Name Type Optional Description

name

string

 

The name of the user to be found.

Returns

SFSUser An object representing the user, or undefined if no user with the passed name exists in this Room.

getUserList() → Array of SFSUser

Retrieves the list of SFSUser objects representing all the users currently inside this Room.

Returns

Array of SFSUser The list of SFSUser objects representing the users who joined the Room.

getVariable(varName) → SFSRoomVariable

Retrieves a Room Variable from its name.

Parameter

Name Type Optional Description

varName

string

 

The name of the Room Variable to be retrieved.

See also
SFSRoom#getVariables
SetRoomVariablesRequest
Returns

SFSRoomVariable The object representing the Room Variable, or undefined if no Room Variable with the passed name exists in this Room.

getVariables() → Array of SFSRoomVariable

Retrieves all the Room Variables of this Room.

See also
SFSRoom#getVariable
SetRoomVariablesRequest
Returns

Array of SFSRoomVariable The list of SFSRoomVariable objects associated with this Room.

toString() → string

Returns a string that contains the Room id, name and id of the Group to which it belongs.

Returns

string The string representation of the SFSRoom object.