new JoinRoomInvitationRequest(targetRoom, invitedUserNames[, params][, expirySeconds][, asSpectator])

Creates a new JoinRoomInvitationRequest instance. The instance must be passed to the SmartFox.send() method for the request to be executed.

This request invites other users/players to join a Room. 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. If the invitation is accepted, the client automatically joins the target Room.

Depending on the Room's settings this invitation can be sent by the Room's owner only or by any other user in the Room. This behavior can be set via the RoomSettings.allowOwnerOnlyInvitation parameter.

NOTE: spectators in a Game Room are not allowed to invite other users; only players are.

An invitation can also specify the amount of time given to each invitee to reply. Default is 30 seconds. A positive answer will attempt to join the user in the designated Room. For Game Rooms the asSpectator flag can be toggled to join the invitee as player or spectator (default = player).

There aren't any specific notifications sent back to the inviter after the invitee's response. Users that have accepted the invitation will join the Room while those who didn't reply or turned down the invitation won't generate any event. In order to send specific messages (e.g. chat), just send a private message back to the inviter.

Example

This example invites two more users in the current game.

function inviteMorePeople()
{
	sfs.addEventListener(SFS2X.SFSEvent.USER_ENTER_ROOM, onUserJoin, this);

	var invitedUsers = ["Fozzie", "Piggy"];
	var theRoom = sfs.getRoomByName("The Garden");

	var params = new SFS2X.SFSObject();
	params.putUtfString("msg", "You are invited in this Room: " + theRoom.name);

	sfs.send(new SFS2X.JoinRoomInvitationRequest(theRoom, invitedUsers, params));
}

function onUserJoin(evtParams)
{
	console.log("User joined Room: " + evtParams.user.name);
}

Parameters

Name Type Optional Description

targetRoom

 

 

The Room to join (must have free user/player slots).

invitedUserNames

 

 

An array of user names to invite.

params

 

Yes

A SFSOobject containing any relevant parameter or message to be sent to the invited users (for example an invitation message).

Defaults to null.

expirySeconds

 

Yes

The time given to the invitee to reply to the invitation.

Defaults to 30.

asSpectator

 

Yes

In Game Rooms only, indicates if the invited user(s) should join as spectator(s) instead of player(s).

Defaults to false.

See also
SmartFox#send
InvitationReplyRequest
SFSEvent.INVITATION
SFSEvent.INVITATION_REPLY