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
This event is fired in response to the AddBuddyRequest if the operation is successful.
| Name | Type | Description |
|---|---|---|
buddy | SFSBuddy | The object representing the Buddy that was added. |
BUDDY_BLOCK
This event is fired in response to the BlockBuddyRequest if the operation is successful.
| Name | Type | Description |
|---|---|---|
buddy | SFSBuddy | The object representing the Buddy that was blocked/unblocked. |
BUDDY_ERROR
This event is fired in response to the AddBuddyRequest, the BlockBuddyRequest and more.
| Name | Type | Description |
|---|---|---|
errorMessage | string | The message that describes the error. |
errorCode | number | The error code. |
BUDDY_LIST_INIT
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.
| Name | Type | Description |
|---|---|---|
buddyList | Array.<SFSBuddy> | A list of objects representing all the Buddies in the Buddy List of the current User. |
myBuddyVars | Array.<SFSBuddyVariable> | The list of all Buddy Variable objects associated with the current User. |
BUDDY_MESSAGE
This event is fired in response to the BuddyMessageRequest.
| Name | Type | Description |
|---|---|---|
buddy | SFSBuddy | The object representing the sender of the message. If the isItMe parameter is true, the value of this parameter is null. |
isItMe | boolean | true if the sender of the message is the current User. |
message | string | The text of the message. |
data | SFSObject | An object containing additional custom parameters. |
BUDDY_ONLINE_STATE_CHANGE
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.
| Name | Type | Description |
|---|---|---|
buddy | SFSBuddy | The object representing the Buddy that changed its own online state. If the isItMe parameter is true, the value of this parameter is null. |
isItMe | boolean | true if the online state was changed by the current User. |
BUDDY_REMOVE
This event is fired in response to the RemoveBuddyRequest if the operation is successful.
| Name | Type | Description |
|---|---|---|
buddy | SFSBuddy | The object representing the Buddy that was removed. |
BUDDY_VARIABLES_UPDATE
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.
| Name | Type | Description |
|---|---|---|
buddy | SFSBuddy | The object representing the Buddy that updated its own Buddy Variables. If the isItMe parameter is true, the value of this parameter is null. |
changedVars | Array.<string> | The list of names of the Buddy Variables that were changed (or created for the first time). |
isItMe | boolean | true if the Buddy Variables were updated by the current User. |