Class SFS2X.Entities.SFSRoom

The SmartFoxServer Room entity representation on the client.

Class Summary
Constructor Attributes Constructor Name and Description
 
SFS2X.Entities.SFSRoom(id, name, groupId)
Creates a new SFSRoom instance.

Field Summary

Method Summary

Class Detail

SFS2X.Entities.SFSRoom(id, name, groupId)
Creates a new SFSRoom instance.

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.

NOTE: developers never istantiate a SFSRoom manually: this is done by the SmartFoxServer 2X API internally. Creating an instance and passing it to the API can disrupt its functioning. You should use the CreateRoomRequest request instead.

Parameters:
{Number} id
The Room id.
{String} name
The Room name.
{String} groupId Optional, Default: "default"
The id of the Group to which the Room belongs.
See also:
SFS2X.SmartFox#roomManager
SFS2X.Requests.System.CreateRoomRequest
SFS2X.Requests.System.JoinRoomRequest
SFS2X.Requests.System.SubscribeRoomGroupRequest
SFS2X.Requests.System.UnsubscribeRoomGroupRequest
SFS2X.Requests.System.ChangeRoomNameRequest
SFS2X.Requests.System.ChangeRoomPasswordStateRequest
SFS2X.Requests.System.ChangeRoomCapacityRequest

Field Detail

{String} groupId
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.

NOTE: setting the groupId property manually has no effect on the server and can disrupt the API functioning. This must be set when creating the Room.

Default Value:
"default"
See also:
SFS2X.Requests.System.SubscribeRoomGroupRequest
SFS2X.Requests.System.UnsubscribeRoomGroupRequest
{Number} id
Indicates the id of this Room.

NOTE: the id is unique and it is generated by the server when the Room is created. Setting it manually has no effect on the server and can disrupt the API functioning.

{Boolean} isGame
Indicates whether this is a Game Room or not.

NOTE: setting the isGame property manually has no effect on the server and can disrupt the API functioning. This flag must be set when creating the Room.

{Boolean} isHidden
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.

NOTE: setting the isHidden property manually has no effect on the server and can disrupt the API functioning. This flag must be set when creating the Room.

{Boolean} isJoined
Indicates whether the client joined this Room or not.

NOTE: setting the isJoined property manually has no effect on the server and can disrupt the API functioning. Use the JoinRoomRequest request to join a new Room instead.

See also:
SFS2X.Requests.System.JoinRoomRequest
{Boolean} isPasswordProtected
Indicates whether this Room requires a password to be joined or not.

NOTE: setting the isPasswordProtected property manually has no effect on the server and can disrupt the API functioning. This flag depends on the Room's password set when the Room is created or by means of the ChangeRoomPasswordStateRequest request.

See also:
SFS2X.Requests.System.ChangeRoomPasswordStateRequest
{Number} maxSpectators
Returns the maximum number of spectators allowed in this Room (Game Rooms only).

NOTE: setting the maxSpectators property manually has no effect on the server and can disrupt the API functioning. This flag must be set when creating the Game Room.

{Number} maxUsers
Returns the maximum number of users allowed in this Room. In case of Game Rooms, this is the maximum number of players.

NOTE: setting the maxUsers property manually has no effect on the server and can disrupt the API functioning. This flag must be set when creating the Room.

{String} name
Indicates the name of this Room. Two Rooms in the same Zone can't have the same name.

NOTE: setting the name property manually has no effect on the server and can disrupt the API functioning. Use the ChangeRoomNameRequest request instead.

See also:
SFS2X.Requests.System.ChangeRoomNameRequest
{Object} properties
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.

Method Detail

  • {Boolean} containsUser(user)
    Indicates whether the specified user is currently inside this Room or not.
    Parameters:
    {SFSUser} user
    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.
  • {Boolean} containsVariable(varName)
    Indicates whether this Room has the specified Room Variable set or not.
    Parameters:
    {String} varName
    The name of the Room Variable whose existance in this Room must be checked.
    Returns:
    {Boolean} true if a Room Variable with the passed name exists in this Room.
  • {Number} getCapacity()
    Returns the maximum amount of users, including spectators, that can be contained in this Room.
    Returns:
    {Number} Maximum number of users that can enter the Room.
  • {Array} getPlayerList()
    Retrieves the list of SFSUser objects representing the players currently inside this Room (Game Rooms only).
    Returns:
    {Array} The list of SFSUser objects representing the users who joined the Room as players.
  • {RoomManager} getRoomManager()
    Retrieves a reference to the Room Manager which manages this Room.
    Returns:
    {RoomManager} The Room Manager to which this Room is associated.
  • {Number} getSpectatorCount()
    Returns the current number of spectators in this Room (Game Rooms only).
    Returns:
    {Number} Current number of spectators in the Room.
  • {Array} getSpectatorList()
    Retrieves the list of SFSUser objects representing the spectators currently inside this Room (Game Rooms only).
    Returns:
    {Array} The list of SFSUser objects representing the users who joined the Room as spectators.
  • {SFSUser} getUserById(id)
    Retrieves a SFSUser object from its id property.
    Parameters:
    {Number} id
    The id of the user to be found.
    Returns:
    {SFSUser} An object representing the user, or null if no user with the passed id exists in this Room.
  • {SFSUser} getUserByName(name)
    Retrieves a SFSUser object from its name property.
    Parameters:
    {String} name
    The name of the user to be found.
    Returns:
    {SFSUser} An object representing the user, or null if no user with the passed name exists in this Room.
  • {Number} getUserCount()
    Returns the current number of users in this Room. In case of Game Rooms, this is the number of players.
    Returns:
    {Number} Current number of users in the Room.
  • {Array} getUserList()
    Retrieves the list of SFSUser objects representing all the users currently inside this Room.
    Returns:
    {Array} The list of SFSUser objects representing the users who joined the Room.
  • {SFSRoomVariable} getVariable(varName)
    Retrieves a Room Variable from its name.
    Parameters:
    {String} varName
    The name of the Room Variable to be retrieved.
    Returns:
    {SFSRoomVariable} The object representing the Room Variable, or null if no Room Variable with the passed name exists in this Room.
    See also:
    SFS2X.Entities.Variables.SFSRoomVariable
    SFS2X.Requests.System.SetRoomVariablesRequest
  • {Array} getVariables()
    Retrieves all the Room Variables of this Room.
    Returns:
    {Array} The list of SFSRoomVariable objects associated with this Room.
    See also:
    SFS2X.Entities.Variables.SFSRoomVariable
  • {String} toString()
    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.