Class SFSUserVariable

  • All Implemented Interfaces:
    UserVariable, Variable

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

    User Variables are particularly useful to store custom user data that must be "visible" to the other users, such as a profile, a score, a status message, etc. User Variables can be set by means of the SetUserVariablesRequest request; they support the following data types (also nested): Boolean, int, Number, String, SFSObject, SFSArray. A User Variable can also be null.

    User Variables can be 'private' (starting from SFS2X v2.12 with client API v1.7): this flag allows to limit the visibility of variables to their owner only. In other words User Variables marked as private are not sent to other users, even if located in the same Room.

    See Also:
    User, SetUserVariablesRequest, SFSObject, SFSArray
    • Constructor Detail

      • SFSUserVariable

        public SFSUserVariable​(java.lang.String name,
                               java.lang.Object value,
                               int type)
        Creates a new SFSUserVariable instance.
        Parameters:
        name - The name of the User Variable.
        value - The value of the User Variable; valid data types are: Boolean, int, Number, String, SFSObject, SFSArray. The value can also be null.
        type - The type of the User 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 UserVariable fromSFSArray​(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)
        * API internal usage only *
      • newPrivateVariable

        public static SFSUserVariable newPrivateVariable​(java.lang.String name,
                                                         java.lang.Object value)
        Creates a new private User Variable.

        Private User Variables are not broadcast to other users: they are only visible on the server side and in the owner's client application.

        Parameters:
        name - The name of the User Variable
        value - The value of the User Variable; valid data types are: Boolean, int, Number, String, SFSObject, SFSArray. The value can also be null.
      • isPrivate

        public boolean isPrivate()
        Description copied from interface: UserVariable
        Indicates whether this User Variable is private or not.

        A private User Variable is visible only to its owner; any changes made to the variable will be transmitted to the owner only.

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

        Specified by:
        isPrivate in interface UserVariable
        Returns:
        whether or not the variable is private
      • setPrivate

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object