Class SFS2X.Requests.Game.InviteUsersRequest

Sends a generic invitation to a list of users.

Class Summary
Constructor Attributes Constructor Name and Description
 
SFS2X.Requests.Game.InviteUsersRequest(invitedUsers, secondsForAnswer, params)
Creates a new InviteUsersRequest instance.

Class Detail

SFS2X.Requests.Game.InviteUsersRequest(invitedUsers, secondsForAnswer, params)
Creates a new InviteUsersRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

This request sends a generic invitation to a list of users. Invitations can be used for different purposes, such as requesting users to join a game or visit a specific Room, asking the permission to add them as buddies, etc. Invited users receive the invitation as an invitation event dispatched to their clients: they can accept or refuse it by means of the InvitationReplyRequest request, which must be sent within the specified amount of time.

The following example sends an invitation to join the current user in his private Room; the invitation contains a custom message and the Room name and password, so that the recipient clients can join the Room if the users accept the invitation:

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.INVITATION_REPLY, onInvitationReply, this);
	
	// Choose the invitation recipients
	var friend1 = sfs.userManager.getUserByName("Piggy");
	var friend2 = sfs.userManager.getUserByName("Gonzo");
	
	// Set the custom invitation details
	var params = {};
	params.msg = "Would you like to join me in my private room?";
	params.roomName = "Kermit's room";
	params.roomPwd = "drowssap";
	
	// Send the invitation; recipients have 20 seconds to reply before the invitation expires
	sfs.send(new SFS2X.Requests.Game.InviteUsersRequest([friend1, friend2], 20, params));
}

function onInvitationReply(evtParams)
{
	// If at least one recipient accepted the invitation, make me join my private Room to meet him there
	if (evtParams.reply == SFS2X.Entities.Invitation.InvitationReply.ACCEPT)
	{
		var currentRoom = sfs.lastJoinedRoom;
		
		if (currentRoom.name != "Kermit's room")
			sfs.send(new SFS2X.Requests.System.JoinRoomRequest("Kermit's room"));
	}
	else
	{
		console.log(evtParams.invitee + " refused the invitation");
	}
}
Parameters:
{Array} invitedUsers
A list of SFSUser objects, each representing a user to send the invitation to.
{Number} secondsForAnswer
The number of seconds available to each invited user to reply to the invitation (recommended range: 15 to 40 seconds).
{Object} params Optional, Default: null
An object containing custom parameters containing additional invitation details.
See also:
SFS2X.SmartFox#send
SFS2X.Entities.SFSUser
SFS2X.Requests.Game.InvitationReplyRequest
SFS2X.SFSEvent.INVITATION
SFS2X.SFSEvent.INVITATION_REPLY