SFSBuddy

Represents a User inside the SmartFoxServer Buddy List System.


The Buddy entity has the following characteristics:

  • Nickname: a Buddy can have an optional nickname, which differs from the User name 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 client can also switch the state to offline at runtime, and disappear from the Buddy List of other User. This state is persistent and it is based on a reserved Buddy Variable.
  • Custom State: a Buddy can have a typical IM state such as "Available", "Away", "Occupied", etc. 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: a Buddy that is blocked in the Buddy List of a User won't be able to send messages to that User; also it 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 Buddy List of the current User whenever another User adds it to its 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 its Buddy List voluntarily, that Buddy won't be persisted and will be lost upon disconnection.
  • Variables: Buddy Variables allow each User to provide (and send updates on) specific custom information to other Users it is Buddy to (e.g. realtime updates on its last activity, the title of the song it's playing right now, scores, rankings, etc).

Members

(readonly) displayName :string

Nickname of the Buddy, or their User name if nickname is not set.

This property can be useful to display the name of the User as a Buddy, giving priority to their nickname if set.

Type:
  • string

(readonly) id :number

Identifier of the Buddy.

This is equal to the id assigned by SmartFoxServer to the corresponding User.

Type:
  • number

(readonly) isBlocked :boolean

Indicates whether the Buddy is blocked in the Buddy List of the current User.
Type:
  • boolean

(readonly) isOnline :boolean

Indicates whether the Buddy is online in the Buddy List System.
Type:
  • boolean

(readonly) isTemp :boolean

Indicates whether the Buddy is temporary (non-persistent) in the Buddy List of the current User.
Type:
  • boolean

(readonly) name :string

Name of the Buddy.

This is equal to the name of the corresponding User.

Type:
  • string

(readonly) nickname :string

Nickname of the Buddy.

The value is null if the nickname is not set.

Type:
  • string

(readonly) state :string

Current custom state of the 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#buddyStates property. The value is null if the state is not set.

Type:
  • string

Methods

containsVariable(varName) → {boolean}

Indicates whether the Buddy has the specified Buddy Variable set.
Parameters:
NameTypeDescription
varNamestringThe name of the Buddy Variable whose existance must be checked.
Returns:
true if a Buddy Variable with the passed name is found.
Type: 
boolean

getOfflineVariables() → {Array.<SFSBuddyVariable>}

Returns the list of persistent Buddy Variables belonging to the Buddy.
Returns:
A list of objects representing the offline Buddy Variables.
Type: 
Array.<SFSBuddyVariable>

getOnlineVariables() → {Array.<SFSBuddyVariable>}

Returns the list of non-persistent Buddy Variables belonging to the Buddy.
Returns:
A list of objects representing the online Buddy Variables.
Type: 
Array.<SFSBuddyVariable>

getVariable(varName) → {SFSBuddyVariable}

Retrieves a Buddy Variable by its name.
Parameters:
NameTypeDescription
varNamestringThe name of the Buddy Variable to be retrieved.
Returns:
The object representing the Buddy Variable, or null if no Buddy Variable with the passed name belongs to the Buddy.
Type: 
SFSBuddyVariable

getVariables() → {Array.<SFSBuddyVariable>}

Returns all Buddy Variables belonging to the Buddy.
Returns:
A list of objects representing the Buddy Variables.
Type: 
Array.<SFSBuddyVariable>

toString() → {string}

Returns a string containing the Buddy name and id.
Returns:
The string representation of the SFSBuddy object.
Type: 
string