SFSBuddyEvent

Represents all the event types related to the Buddy List System dispatched by the SmartFoxServer Client API.


Constants contained in this object (see Events below) are used to register event listeners; when an event is dispatched, an object containing event-specific parameters is passed to the listener. Parameters are described under each event type; to avoid typing errors, get parameter names from the EventParam class.

Example

This example shows the generic approach to follow to listen to events.

function someMethod()
{
	sfs.addEventListener(SFSBuddyEvent.BUDDY_LIST_INIT, onBuddyListInitialized, this);
	sfs.addEventListener(SFSBuddyEvent.BUDDY_ERROR, onBuddyError, this)

	// Initialize the Buddy List system
	sfs.send(new InitBuddyListRequest());
}

function onBuddyListInitialized(evtParams)
{
	console.log("Buddy List system initialized successfully");
	
	// Retrieve my buddies list
	const buddies = evtParams[EventParam.BuddyList];

	// Display the online buddies in a list component in the application interface
	...
}

function onBuddyError(evtParams)
{
	console.log("The following error occurred while executing a buddy-related request: " + evtParams[EventParam.ErrorMessage]);
}

Events

BUDDY_ADD

Event type dispatched when a Buddy is added successfully to the Buddy List of the current User.

This event is fired in response to the AddBuddyRequest if the operation is successful.

Properties
NameTypeDescription
buddySFSBuddyThe object representing the Buddy that was added.

BUDDY_BLOCK

Event type dispatched when a Buddy is blocked or unblocked successfully by the current User.

This event is fired in response to the BlockBuddyRequest if the operation is successful.

Properties
NameTypeDescription
buddySFSBuddyThe object representing the Buddy that was blocked/unblocked.

BUDDY_ERROR

Event type dispatched when an error occurs while executing a request related to the Buddy List System.

This event is fired in response to the AddBuddyRequest, the BlockBuddyRequest and more.

Properties
NameTypeDescription
errorMessagestringThe message that describes the error.
errorCodenumberThe error code.

BUDDY_LIST_INIT

Event type dispatched when the Buddy List System is successfully initialized on the client.

This event is fired in response to the InitBuddyListRequest if the operation is successful.

After the Buddy List System initialization, the client returns to its previous custom state (if any - see SFSBuddyManager#myState property). The online/offline state, nickname and persistent Buddy Variables are all loaded and broadcast inside the system. In particular, the online state (see SFSBuddyManager#myOnlineState property) determines if the User will appear online to other Users having it in their Buddy List.

Properties
NameTypeDescription
buddyListArray.<SFSBuddy>A list of objects representing all the Buddies in the Buddy List of the current User.
myBuddyVarsArray.<SFSBuddyVariable>The list of all Buddy Variable objects associated with the current User.

BUDDY_MESSAGE

Event type dispatched when a message from a Buddy is received by the current User.

This event is fired in response to the BuddyMessageRequest.

Properties
NameTypeDescription
buddySFSBuddyThe object representing the sender of the message. If the isItMe parameter is true, the value of this parameter is null.
isItMebooleantrue if the sender of the message is the current User.
messagestringThe text of the message.
dataSFSObjectAn object containing additional custom parameters.

BUDDY_ONLINE_STATE_CHANGE

Event type dispatched when a Buddy in the Buddy List of the current User changes its online state.

This event is fired in response to the GoOnlineRequest to those clients which have the User as a Buddy, but also to the sender of the request. As in this case the value of the buddy parameter is null (because the User is not Buddy to itself of course), the isItMe parameter should be used to check if the current User is the one which changed its own online state.

Properties
NameTypeDescription
buddySFSBuddyThe object representing the Buddy that changed its own online state. If the isItMe parameter is true, the value of this parameter is null.
isItMebooleantrue if the online state was changed by the current User.

BUDDY_REMOVE

Event type dispatched when a Buddy is removed successfully from the Buddy List of the current User.

This event is fired in response to the RemoveBuddyRequest if the operation is successful.

Properties
NameTypeDescription
buddySFSBuddyThe object representing the Buddy that was removed.

BUDDY_VARIABLES_UPDATE

Event type dispatched when a Buddy in the Buddy List of the current User updates one or more Buddy Variables.

This event is fired in response to the SetBuddyVariablesRequest to those clients which have the User as a Buddy, but also to the sender of the request. As in this case the value of the buddy parameter is null (because the User is not Buddy to itself of course), the isItMe parameter should be used to check if the current User is the one which updated its own Buddy Variables.

Properties
NameTypeDescription
buddySFSBuddyThe object representing the Buddy that updated its own Buddy Variables. If the isItMe parameter is true, the value of this parameter is null.
changedVarsArray.<string>The list of names of the Buddy Variables that were changed (or created for the first time).
isItMebooleantrue if the Buddy Variables were updated by the current User.