Class SFSBuddyVariable

  • All Implemented Interfaces:
    BuddyVariable, Variable

    public class SFSBuddyVariable
    extends BaseVariable
    implements BuddyVariable
    The SFSBuddyVariable object represents a SmartFoxServer Buddy Variable entity on the client. It is a custom value attached to a Buddy object in a Buddy List that gets automatically synchronized between client and server on every change.

    Buddy Variables work with the same principle of the User and Room Variables. The only difference is the logic by which they get propagated to other users. While Room and User Variables are usually broadcast to all clients in the same Room, Buddy Variables updates are sent to all users who have the owner of the Buddy Variable in their Buddy Lists.

    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 Buddy Variable can also be null.

    There is also a special convention that allows Buddy Variables to be set as "offline". Offline Buddy Variables are persistent values which are made available to all users who have the owner in their Buddy Lists, whether that Buddy is online or not. In order to make a Buddy Variable persistent, its name should start with a dollar sign ($). This conventional character is contained in the OFFLINE_PREFIX constant.

    See Also:
    OFFLINE_PREFIX, Buddy, SetBuddyVariablesRequest, SFSObject, SFSArray
    • Field Detail

      • OFFLINE_PREFIX

        public static final java.lang.String OFFLINE_PREFIX
        The prefix to be added to a Buddy Variable name to make it persistent. A persistent Buddy Variable is made available to all users who have the owner in their Buddy Lists, whether that Buddy is online or not.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SFSBuddyVariable

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

        public boolean isOffline()
        Description copied from interface: BuddyVariable
        Indicates whether the Buddy Variable is persistent or not.

        By convention any Buddy Variable whose name starts with the dollar sign ($) will be regarded as persistent and stored locally by the server. Persistent Buddy Variables are also referred to as "offline variables" because they are available to all users who have the owner in their Buddy Lists, whether that Buddy is online or not.

        Specified by:
        isOffline in interface BuddyVariable
      • toString

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