Class JoinRoomRequest

  • All Implemented Interfaces:
    sfs2x.client.requests.IRequest

    public class JoinRoomRequest
    extends BaseRequest
    Joins the current user in a Room.

    If the operation is successful, the current user receives a roomJoin event; otherwise the roomJoinError event is fired. This usually happens when the Room is full, or the password is wrong in case of password protected Rooms.

    Depending on the Room configuration defined upon its creation (see the RoomSettings.events setting), when the current user joins it, the following events might be fired: userEnterRoom, dispatched to the other users inside the Room to warn them that a new user has arrived; userCountChange, dispatched to all clients which subscribed the Group to which the Room belongs, to update the count of users inside the Room.

    Example
    The following example makes the user join an existing Room:

     private void someMethod() {
         sfs.addEventListener(SFSEvent.ROOM_JOIN, new IEventListener() {
             public void dispatch(BaseEvent evt) throws SFSException {
                 System.out.println("Room joined successfully: " + evt.getArguments().get("room"));
             }
         });
         sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, new IEventListener() {
             public void dispatch(BaseEvent evt) throws SFSException {
                 System.out.println("Room joining failed: " + evt.getArguments().get("errorMessage"));
             }
         });
         
         // Join a Room called "Lobby"
         sfs.send(new JoinRoomRequest("Lobby"));
     }
     
    See Also:
    SFSEvent.ROOM_JOIN, SFSEvent.ROOM_JOIN_ERROR, SFSEvent.USER_ENTER_ROOM, SFSEvent.USER_COUNT_CHANGE, RoomSettings.getEvents()
    • Field Detail

      • KEY_ROOM

        public static final java.lang.String KEY_ROOM
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_USER_LIST

        public static final java.lang.String KEY_USER_LIST
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_ROOM_NAME

        public static final java.lang.String KEY_ROOM_NAME
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_ROOM_ID

        public static final java.lang.String KEY_ROOM_ID
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_PASS

        public static final java.lang.String KEY_PASS
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_ROOM_TO_LEAVE

        public static final java.lang.String KEY_ROOM_TO_LEAVE
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_AS_SPECTATOR

        public static final java.lang.String KEY_AS_SPECTATOR
        * API internal usage only *
        See Also:
        Constant Field Values
    • Constructor Detail

      • JoinRoomRequest

        public JoinRoomRequest​(java.lang.Object id,
                               java.lang.String pass,
                               java.lang.Integer roomIdToLeave,
                               boolean asSpectator)
        Creates a new JoinRoomRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
        Parameters:
        id - The id or the name of the Room to be joined.
        pass - The password of the Room, in case it is password protected.
        roomIdToLeave - The id of a previously joined Room that the user should leave when joining the new Room. By default, the last joined Room is left; if a negative number is passed, no previous Room is left.
        asSpectator - true to join the Room as a spectator (in Game Rooms only).
        See Also:
        SmartFox.send(sfs2x.client.requests.IRequest)
    • Method Detail

      • validate

        public void validate​(ISmartFox sfs)
                      throws sfs2x.client.exceptions.SFSValidationException
        * API internal usage only *
        Throws:
        sfs2x.client.exceptions.SFSValidationException
      • execute

        public void execute​(ISmartFox sfs)
        * API internal usage only *