Interface ClientEventListener

All Known Implementing Classes:
ClientEventAdapter

public interface ClientEventListener
Interface for Client events/callbacks. An instance of this interface should be registered with the client object to handle async events received from the server

      public class TicTacToeClientListener implements ClientEventListener {
          {@literal @}Override
          public void onLoggedIn(Client client, boolean isGameSelected) {
              if(isGameSelected)
                  client.getRooms( "Mumbai", RoomType.normal); //fetches room list from Mumbai location
          }
 
          {@literal @}Override
          public void onGetRooms(Client client, String gameName, String location, RoomType roomtype, List<RoomInfo> rooms) {
              client.joinRoom(rooms.get(0).roomId); //joins the first room in the list
          }
          //....
      }
  
  • Method Details

    • beforeServerMessageProcessed

      void beforeServerMessageProcessed​(Client client, ServerMessageType serverMessageType, String customMessageCommand, boolean isBinary, Object data)
      Event-Handler/Callback called when a message is received from the Server but before it is processed
      Parameters:
      client - - the Client which received the message
      serverMessageType - - the messageType received from Server e.g. ServerMessageType.roomJoined or ServerMessageType.gamePlayStarted or ...
      customMessageCommand - - the custom message command if the serverMessageType is a custom message
      isBinary - - whether message data is binary or not
      data - - the message data
    • afterServerMessageProcessed

      void afterServerMessageProcessed​(Client client, ServerMessageType serverMessageType, String customMessageCommand, boolean isBinary, Object data)
      Event-Handler/Callback called when a message is received from the Server but after it is processed
      Parameters:
      client - - the Client which received the message
      serverMessageType - - the messageType received from Server e.g. ServerMessageType.roomJoined or ServerMessageType.gamePlayStarted or ...
      customMessageCommand - - the custom message command if the serverMessageType is a custom message
      isBinary - - whether message data is binary or not
      data - - the message data
    • onError

      void onError​(Client client, int errorCode, String errorDesc)
      Event-Handler/Callback called when an error is triggered on the server.
      Parameters:
      client - - the Client which triggered the error
      errorCode - - the errorCode e.g. ErrorCodes.emailIdAndPasswordDoesNotMatch or ErrorCodes.seatNotFree or ...
      errorDesc - - the error description
    • onLoggedIn

      void onLoggedIn​(Client client, boolean isGameSelected)
      Event-Handler/Callback called when the Client successfully logins a user into the server
      Parameters:
      client - - the Client which loggedIn
      isGameSelected - - whether a Game is linked with this user session or not
    • onLoggedOut

      void onLoggedOut​(Client client)
      Event-Handler/Callback called when the Client successfully logouts a user from the server
      Parameters:
      client - - the client which loggedOut
    • onSessionTimedOut

      void onSessionTimedOut​(Client client)
      Event-Handler/Callback called when the Client session times out on the server
      Parameters:
      client - - the client whose session timed out
    • onServerShutdown

      void onServerShutdown​(Client client)
      Event-Handler/Callback called when the server shutsdown
      Parameters:
      client - - the Client which triggered this event
    • onGetLocations

      void onGetLocations​(Client client, String gameName, List<String> locations)
      Event-Handler/Callback called when the Client receives the location list from the Server
      Parameters:
      client - - the Client which triggered this event
      gameName - - the name of the game whose locations were requested by the Client
      locations - - the list of locations
    • onGetRooms

      void onGetRooms​(Client client, String gameName, String location, RoomType roomtype, List<RoomInfo> rooms)
      Event-Handler/Callback called when the Client receives the room list from the Server
      Parameters:
      client - - the Client which triggered this event
      gameName - - the name of the game whose room list was requested by the Client
      location - - the location whose room list was requested
      roomtype - - the type of room list e.g. RoomType.normal or RoomType.fast
      rooms - - the room list as a collection of RoomInfo objects
    • onRoomJoined

      void onRoomJoined​(Client client, Room room)
      Event-Handler/Callback called when the Client joins a room
      Parameters:
      client - - the Client which triggered this event
      room - - the room joined by this Client
    • onRoomRefreshedFromServer

      void onRoomRefreshedFromServer​(Client client, Room room)
      Event-Handler/Callback called when the room state is refreshed from the server. Gets triggered when Client receives a ServerMessageType.roomData message from the Server
      Parameters:
      client - - the Client which triggered this event
      room - - the room joined by the client
    • onSeatTaken

      void onSeatTaken​(Client client, Player playerSeated, Room room, boolean isSelf)
      Event-Handler/Callback called when any user takes a seat in the room.
      Parameters:
      client - - the Client which receives this event
      playerSeated - - the player which took seat
      room - - the room joined by this client
      isSelf - - if the user seated is the same as this Client
    • onSeatLeft

      void onSeatLeft​(Client client, Player playerLeft, Room room, boolean isSelf)
      Event-Handler/Callback called when any user leaves a seat in the room.
      Parameters:
      client - - the Client which receives this event
      playerLeft - - the player which left the seat
      room - - the room joined by this client
      isSelf - - if the user which left is the same as this Client
    • onRoomLeft

      void onRoomLeft​(Client client)
      Event-Handler/Callback called when the Client leaves the room
      Parameters:
      client - - the Client which triggered this event
    • onMessageReceivedJson

      void onMessageReceivedJson​(Client client, String command, JsonObject data)
      Event-Handler/Callback called when the Client receives a custom Json message from the server
      Parameters:
      client - - the Client which receives the message
      command - - the message command
      data - - the message data as json
    • onMessageReceivedString

      void onMessageReceivedString​(Client client, String command, String data)
      Event-Handler/Callback called when the Client receives a custom text message from the server
      Parameters:
      client - - the Client which receives the message
      command - - the message command
      data - - the message data as String
    • onMessageReceivedBytes

      void onMessageReceivedBytes​(Client client, String command, byte[] data)
      Event-Handler/Callback called when the Client receives a custom binary message from the server
      Parameters:
      client - - the Client which receives the message
      command - - the message command
      data - - the message data as a byte array
    • onGamePlayStarted

      void onGamePlayStarted​(Client client, Room room)
      Event-Handler/Callback called when game play starts in the room
      Parameters:
      client - - the Client which receives this event
      room - - the room joined by this client
    • onNextTurn

      void onNextTurn​(Client client, Player turnPlayer, JsonObject turnData, Room room, boolean isSelfTurn)
      Event-Handler/Callback called when a new turn begins
      Parameters:
      client - - the Client which receives this event
      turnPlayer - - the player whose turn it is
      turnData - - the additional data received with the event. For e.g. in a game like Poker it could be {"callValue":20}
      room - - the room joined by this client
      isSelfTurn - - whether its the turn of the client which received this event
    • onTurnPlayed

      void onTurnPlayed​(Client client, Player turnPlayer, String playerAction, JsonObject actionData, Room room, boolean isSelf)
      Event-Handler/Callback called when a player plays his/her turn
      Parameters:
      client - - the Client which receives this event
      turnPlayer - - the player who played the action
      playerAction - - the action played by the player
      actionData - - the action data if any. For e.g. in a game like Poker it could be {"amtBet":20}
      room - - the room joined by this client
      isSelf - - whether the action was played by the client which received this event
    • onOutOfTurnPlayed

      void onOutOfTurnPlayed​(Client client, Player outOfTurnPlayer, String playerAction, JsonObject actionData, Room room, boolean isSelf)
      Event-Handler/Callback called when an action is played out of turn by a player
      Parameters:
      client - - the Client which receives this event
      outOfTurnPlayer - - the player who played the action
      playerAction - - the action played by the player
      actionData - - the action data if any.
      room - - the room joined by this client
      isSelf - - whether the action was played by the client which received this event
    • onGameAction

      void onGameAction​(Client client, String gameAction, JsonObject actionData, Room room)
      Event-Handler/Callback called when a game action occurs in the game. For e.f. in a game like poker this could be flop cards dealt
      Parameters:
      client - - the Client which receives this event
      gameAction - - the game action
      actionData - - the action data. For e.g. in a game like poker this could be the value of the flop cards
      room - - the room joined by this client
    • onGamePlayEnded

      void onGamePlayEnded​(Client client, Room room, JsonObject endGameData)
      Event-Handler/Callback called when game play ends in the room
      Parameters:
      client - - the Client which receives this event
      room - - the room joined by this client
      endGameData - - the data received with the endGame event. For e.g this could be the winning seat no and the amount won
    • onRoomDestroyed

      void onRoomDestroyed​(Client client, Room room)
      Event-Handler/Callback called when the room joined by this client is destroyed
      Parameters:
      client - - the Client which receives this event
      room - - the room which was destroyed
    • onAvtarChangedOfSelf

      void onAvtarChangedOfSelf​(Client client, int newAvtarId)
      Event-Handler/Callback called when the avtar of the user loggedIn via this client changes
      Parameters:
      client - - the Client which receives this event
      newAvtarId - - the new avtarId of the user
    • onAvtarChangedOfOtherPlayer

      void onAvtarChangedOfOtherPlayer​(Client client, Player player, int newAvtarId, Room room)
      Event-Handler/Callback called when the avtar of another player is changed
      Parameters:
      client - - the Client which receives this event
      player - - the player whose avtar is changed
      newAvtarId - - the new avtarID
      room - - the room joined by this client
    • onNotEligibleToPlay

      void onNotEligibleToPlay​(Client client, Player player, Room room, String reason)
      Event-Handler/Callback called when the Client is not eligible to play the new game play that is starting
      Parameters:
      client - - the Client which receives this event
      player - - the player linked to this client
      room - - the room joined by this client
      reason - - the reason why player is not eligible
    • onSessionRejoined

      void onSessionRejoined​(Client client)
      Event-Handler/Callback called when session is rejoined by this client. This event is triggered by the method Client.rejoinSession()
      Parameters:
      client - - the Client which receives this event
    • onConnecting

      void onConnecting​(Client client)
      Event-Handler/Callback called when Client is attempting to connect to the server
      Parameters:
      client - - the Client which triggers this event
    • onConnectionSuccess

      void onConnectionSuccess​(Client client)
      Event-Handler/Callback called when Client is successfully connected to the server
      Parameters:
      client - - the Client which triggers this event
    • onConnectionFailure

      void onConnectionFailure​(Client client)
      Event-Handler/Callback called when Client is fails to connect to the server
      Parameters:
      client - - the Client which triggers this event
    • onConnectionDisconnected

      void onConnectionDisconnected​(Client client)
      Event-Handler/Callback called when Client is disconnected from the server i.e. When the Server initiates the connection close.
      Parameters:
      client - - the Client which triggers this event
    • onConnectionClosed

      void onConnectionClosed​(Client client)
      Event-Handler/Callback called when the connection to the server is closed i.e. When the Client initiates the connection close.
      Parameters:
      client - - the Client which triggers this event
    • onInvalidAction

      void onInvalidAction​(Client client, String action, String description, JsonObject errorData, Room room, boolean isOutOfTurn)
      Event-Handler/Callback called when an action played by the Client is not valid
      Parameters:
      client - - the Client which triggers this event
      action - - the action played
      description - - the error description
      errorData - - the error data containing more info about the error
      room - - the room joined by the client
      isOutOfTurn - - true if the action was played out of turn
    • onEnterGame

      void onEnterGame​(Client client, String gameName)
      Event-Handler/Callback called when Client enters/selects a game.
      Parameters:
      client - - the Client which triggers this event
      gameName - - the name of the game entered/selected
    • onExitGame

      void onExitGame​(Client client, String gameName)
      Event-Handler/Callback called when Client exits/deselects a game.
      Parameters:
      client - - the Client which triggers this event
      gameName - - the name of the game exited/deselected