Exemplo n.º 1
0
  public static String createUserLeftMessage(UserProfile joinee) {
    final JSONObject messageTemplate = new JSONObject();

    messageTemplate.put("type", "user_left");
    messageTemplate.put("id", joinee.getId());

    return messageTemplate.toString();
  }
Exemplo n.º 2
0
  public static String createGameOverMessage(@Nullable UserProfile winner) {
    final JSONObject messageTemplate = new JSONObject();

    messageTemplate.put("type", "game_over");
    if (winner != null) messageTemplate.put("id", winner.getId());
    else messageTemplate.put("id", JSONObject.NULL);

    return messageTemplate.toString();
  }
Exemplo n.º 3
0
  public static String createUserStateChangedMessage(
      UserProfile user, boolean isReady, boolean contentLoaded) {
    final JSONObject messageTemplate = new JSONObject();

    messageTemplate.put("type", "user_state_changed");
    messageTemplate.put("id", user.getId());
    messageTemplate.put("isReady", isReady);
    messageTemplate.put("contentLoaded", contentLoaded);

    return messageTemplate.toString();
  }
Exemplo n.º 4
0
  public static String createUserJoinedMessage(
      UserProfile joinee, boolean isReady, boolean contentLoaded) {
    final JSONObject messageTemplate = new JSONObject();

    messageTemplate.put("type", "user_joined");
    messageTemplate.put("id", joinee.getId());
    messageTemplate.put("isReady", isReady);
    messageTemplate.put("contentLoaded", contentLoaded);
    messageTemplate.put("name", joinee.getLogin());
    messageTemplate.put("score", joinee.getScore());
    if (joinee.getUserpicPath() == null) messageTemplate.put("userpic_path", JSONObject.NULL);
    else messageTemplate.put("userpic_path", joinee.getUserpicPath());

    return messageTemplate.toString();
  }