Class SFS2X.Requests.System.LeaveRoomRequest

Leaves one of the Rooms joined by the current user.

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

Class Detail

SFS2X.Requests.System.LeaveRoomRequest(room)
Creates a new LeaveRoomRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

This request makes the current user leave one of the Rooms he joined. Depending on the Room configuration defined upon its creation (see the RoomSettings.events setting), when the user leaves it, the following events might be fired: userExitRoom, dispatched to all the users inside the Room (including the current user then) to warn them that a user has gone away; userCountChange, dispatched to all clients which subscribed the Group to which the Room belongs, to update the count of users inside the Room.

The following example makes the user leave the currently joined Room and handles the respective event:

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.USER_EXIT_ROOM, onUserExitRoom, this);
	
	// Leave the last joined Room
	sfs.send(new SFS2X.Requests.System.LeaveRoomRequest());
}

function onUserExitRoom(evtParams)
{
	var room = evtParams.room;
	var user = evtParams.user;
	
	console.log("User " + user.name + " just left Room " + room.name);
}
Parameters:
{SFSRoom} room Optional, Default: null
The SFSRoom object corresponding to the Room that the current user must leave. If null, the last Room joined by the user is left.
See also:
SFS2X.SmartFox#send
SFS2X.Entities.SFSRoom
SFS2X.SFSEvent.USER_EXIT_ROOM
SFS2X.SFSEvent.USER_COUNT_CHANGE