SFSBuddyVariable
The Buddy Variable entity representation on the client.
Method
new SFSBuddyVariable(name, value[, type])
Creates a new SFSBuddyVariable instance.
A SFSBuddyVariable is a custom value attached to a SFSBuddy 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.
Buddy Variables are particularly useful to store custom user data that must be "visible" to the buddies only, such as a profile, a ranking, a status message, etc.
Buddy Variables can be set by means of the SetBuddyVariablesRequest request; they support the following data types (also nested):
boolean, 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 List, 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.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
name |
|
|
The name of the Buddy Variable. |
value |
|
|
The value of the Buddy Variable; it can also be |
type |
|
Yes |
The type id 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. Defaults to |
- Extends
- BaseVariable
- See also
- VariableType
- SFSBuddy
- SetBuddyVariablesRequest
Properties
OFFLINE_PREFIX string
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 List, whether that Buddy is online or not.
isNull unknown
Indicates if the Variable is null
.
- Inherited from
- BaseVariable#isNull
isOffline boolean
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 List, whether that Buddy is online or not.
name unknown
Indicates the name of this variable.
- Inherited from
- BaseVariable#name
type unknown
Indicates the type of this Variable.
Possibly returned strings are: null
, boolean
, int
, double
, string
, SFSObject
, SFSArray
.
- Inherited from
- BaseVariable#type
value unknown
Returns the value of this variable.
- Inherited from
- BaseVariable#value
Method
toString() → string
Returns a string that contains the Buddy Variable name, type and value.
- Returns
-
string
The string representation of the SFSBuddyVariable object.