Class SFS2X.Requests.Game.JoinRoomInvitationRequest
Sends an invitation to other users/players to join a specific Room.
Constructor Attributes | Constructor Name and Description |
---|---|
SFS2X.Requests.Game.JoinRoomInvitationRequest(targetRoom, invitedUserNames, params, expirySeconds, asSpectator)
Creates a new JoinRoomInvitationRequest instance.
|
Class Detail
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.
The following 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 = {}; params.msg = "You are invited in this Room: " + theRoom.name; sfs.send(new SFS2X.Requests.Game.JoinRoomInvitationRequest(theRoom, invitedUsers, params)); } function onUserJoin(evtParams) { console.log("User joined Room: " + evtParams.user.name); }
- Parameters:
- {SFSRoom} targetRoom
- The Room to join (must have free user/player slots).
- {Array} invitedUserNames
- An array of user names to invite.
- {Object} params Optional, Default: null
- An object containing any relevant parameter or message to be sent to the invited users (for example an invitation message).
- {Number} expirySeconds Optional, Default: 30
- The time given to the invitee to reply to the invitation.
- {Boolean} asSpectator Optional, Default: false
- In Game Rooms only, indicates if the invited user(s) should join as spectator(s) instead of player(s).