new SFSBuddy()

Developers never istantiate the SFSBuddy class: this is done internally by the SmartFoxServer 2X API.

A buddy is marked out by the following characteristics:

  • Nickname: a buddy can have an optional nickname, which differs from the username used during the login process
  • Online/offline state: users can be online or offline as buddies in the Buddy List system. By default a buddy is online every time he joins a Zone, but the user can also switch the state to offline at runtime, and disappear from other user's buddy lists. This state is persistent and it is based on a reserved Buddy Variable
  • Custom state: each user can have a typical IM state such as "Available", "Away", "Occupied", etc. The state can be selected among the custom ones defined in the Zone configuration, which can be changed or enriched at any time. This state is persistent and it is based on a reserved Buddy Variable
  • Blocked buddy: buddies that are blocked in a user's buddy list won't be able to send messages to that user; also they won't be able to see if the user is online or offline in the Buddy List system.
  • Temporary buddy: a temporary buddy is added to the current user's buddy list whenever another user adds him to his own buddy list. In this way users can "see" each other and exchange messages. If the current user doesn't add that temporary buddy to his buddy list voluntarily, that buddy won't be persisted and will be lost upon disconnection.
  • Variables: Buddy Variables enable each user to show (and send updates on) specific custom informations to each user to whom he is a buddy. For example one could send realtime updates on his last activity, or post the title of the song he's listening right now, or scores, rankings and whatnot.
See also
SmartFox#buddyManager
SFSBuddyVariable

Properties

read-only

id  number

Indicates the id of this buddy. This is equal to the id assigned by SmartFoxServer to the corresponding user.

See also
SFSUser#id
read-only

isBlocked  boolean

Indicates whether this buddy is blocked in the current user's buddy list or not. A buddy can be blocked by means of a BlockBuddyRequest request.

See also
BlockBuddyRequest
read-only

isOnline  boolean

Indicates whether this buddy is online in the Buddy List system or not.

See also
GoOnlineRequest
read-only

isTemp  boolean

Indicates whether this buddy is temporary (non-persistent) in the current user's buddy list or not.

read-only

name  string

Indicates the name of this buddy. This is equal to the name of the corresponding user.

See also
SFSUser#name
read-only

nickName  string

Returns the nickname of this buddy. If the nickname is not set, null is returned.

read-only

state  string

Returns the custom state of this buddy. Examples of custom states are "Available", "Busy", "Be right back", etc. If the custom state is not set, null is returned.

The list of available custom states is returned by the SFSBuddyManager.getBuddyStates() method.

See also
SFSBuddyManager#getBuddyStates

Methods

containsVariable(varName) → boolean

Indicates whether this user has the specified Buddy Variable set or not.

Parameter

Name Type Optional Description

varName

string

 

The name of the Buddy Variable whose existance must be checked.

See also
SFSBuddyVariable
Returns

boolean true if a Buddy Variable with the passed name is set for this buddy.

getOfflineVariables() → Array of SFSBuddyVariable

Retrieves the list of persistent Buddy Variables for this buddy.

See also
SFSBuddyVariable#isOffline
Returns

Array of SFSBuddyVariable A list of SFSBuddyVariable objects corresponding to the buddy's persistent Buddy Variables.

getOnlineVariables() → Array of SFSBuddyVariable

Retrieves the list of non-persistent Buddy Variables for this buddy.

See also
SFSBuddyVariable#isOffline
Returns

Array of SFSBuddyVariable A list of SFSBuddyVariable objects corresponding to the buddy's non-persistent Buddy Variables.

getVariable(varName) → SFSBuddyVariable

Retrieves a Buddy Variable from its name.

Parameter

Name Type Optional Description

varName

string

 

The name of the Buddy Variable to be retrieved.

See also
SFSBuddy#getVariables
SetBuddyVariablesRequest
Returns

SFSBuddyVariable The object representing the Buddy Variable, or undefined if no Buddy Variable with the passed name is associated to this buddy.

getVariables() → Array of SFSBuddyVariable

Retrieves all the Buddy Variables of this user.

See also
SFSBuddy#getVariable
SetBuddyVariablesRequest
Returns

Array of SFSBuddyVariable The list of SFSBuddyVariable objects associated to the buddy.

toString() → string

Returns a string that contains the buddy id and name.

Returns

string The string representation of the SFSBuddy object.