Class SFS2X.Requests.BuddyList.GoOnlineRequest

Toggles the current user's online/offline state as buddy in other users' buddy lists.

Class Summary
Constructor Attributes Constructor Name and Description
 
Creates a new GoOnlineRequest instance.

Class Detail

SFS2X.Requests.BuddyList.GoOnlineRequest(online)
Creates a new GoOnlineRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

All clients who have the current user as buddy in their buddy list will receive the buddyOnlineStateChange event and see the SFSBuddy.isOnline method return its value accordingly. The same event is also dispatched to the current user, who sent the request, so that the application interface can be updated accordingly. Going online/offline as buddy doesn't affect the user connection, the currently joined Zone and Rooms, etc.

The online state of a user in a buddy list is handled by means of a reserved and persistent Buddy Variable.

NOTE: this request can be sent if the Buddy List system was previously initialized only (see the InitBuddyListRequest request description).

The following example changes the user online state in the Buddy List system:

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSBuddyEvent.BUDDY_ONLINE_STATE_CHANGE, onBuddyOnlineStateChanged, this);
	
	// Put myself offline in the Buddy List system
	sfs.send(new SFS2X.Requests.BuddyList.GoOnlineRequest(false));
}

function onBuddyOnlineStateChanged(evtParams)
{
	// As the state change event is dispatched to me too,
	// I have to check if I am the one who changed his state
	
	var isItMe = evtParams.isItMe;
	
	if (isItMe)
		console.log("I'm now " + (sfs.buddyManager.getMyOnlineState() ? "online" : "offline"));
	else
		console.log("My buddy " + evtParams.buddy.name + " is now " + (evtParams.buddy.isOnline() ? "online" : "offline"));
}
Parameters:
{Boolean} online
true to make the current user available (online) in the Buddy List system; false to make him not available (offline).
See also:
SFS2X.SmartFox#send
SFS2X.Managers.BuddyManager#getMyOnlineState
SFS2X.Entities.SFSBuddy#isOnline
SFS2X.SFSBuddyEvent.BUDDY_ONLINE_STATE_CHANGE