Class SFSRoomVariable

  • All Implemented Interfaces:
    RoomVariable, Variable

    public class SFSRoomVariable
    extends BaseVariable
    implements RoomVariable
    The SFSRoomVariable object represents a SmartFoxServer Room Variable entity on the client. It is a custom value attached to a Room object that gets automatically synchronized between client and server on every change.

    Room Variables are particularly useful to store custom Room data such as a game status and other Room-level informations. Room Variables can be set by means of the SetRoomVariablesRequest request; they support the following data types (also nested): Boolean, int, Number, String, SFSObject, SFSArray. A Room Variable can also be null.

    Room Variables also support a number of specific flags:

    • Private: a private Room Variable can only be modified by its creator.
    • Persistent: a persistent Room Variable will continue to exist even if its creator has left the Room (but will be deleted when the creator will get disconnected).
    • Global: a global Room Variable will fire update events not only to all users in the Room, but also to all users in the Group to which the Room belongs (NOTE: this flag is not available on the client-side because clients are not allowed to create global Room Variables).

    See Also:
    Room, SetRoomVariablesRequest, SFSObject, SFSArray
    • Constructor Detail

      • SFSRoomVariable

        public SFSRoomVariable​(java.lang.String name,
                               java.lang.Object value,
                               int type)
        Creates a new SFSRoomVariable instance.
        Parameters:
        name - The name of the Room Variable.
        value - The value of the Room Variable; valid data types are: Boolean, int, Number, String, SFSObject, SFSArray. The value can also be null.
        type - The type of the Room Variable among those available in the VariableType class. Usually it is not necessary to pass this parameter, as the type is auto-detected from the value.
        See Also:
        VariableType
    • Method Detail

      • fromSFSArray

        public static RoomVariable fromSFSArray​(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)
        * API internal usage only *
      • isPersistent

        public boolean isPersistent()
        Description copied from interface: RoomVariable
        Indicates whether this Room Variable is persistent or not. A persistent Room Variable continues to exist in the Room after the user who created it has left it and until he disconnects.

        NOTE: setting the isPersistent property manually on an existing Room Variable returned by the API has no effect on the server and can disrupt the API functioning. This flag can be set when the Room Variable object is created by the developer only (using the new keyword).

        Specified by:
        isPersistent in interface RoomVariable
      • isPrivate

        public boolean isPrivate()
        Description copied from interface: RoomVariable
        Indicates whether this Room Variable is private or not. A private Room Variable can be modified by its owner only (the user that created it).

        NOTE: setting the isPersistent property manually on an existing Room Variable returned by the API has no effect on the server and can disrupt the API functioning. This flag can be set when the Room Variable object is created by the developer only (using the new keyword).

        Specified by:
        isPrivate in interface RoomVariable
      • setPrivate

        public void setPrivate​(boolean setPrivate)
        Description copied from interface: RoomVariable
        * API internal usage only *
        Specified by:
        setPrivate in interface RoomVariable
      • setPersistent

        public void setPersistent​(boolean persistent)
        Description copied from interface: RoomVariable
        * API internal usage only *
        Specified by:
        setPersistent in interface RoomVariable
      • toString

        public java.lang.String toString()
        Returns a string that contains the Room Variable name, type, value and isPrivate flag.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string representation of the SFSRoomVariable object.