/**
   * Sends command to retrieve phones list.
   *
   * @return is command successful.
   */
  @SuppressWarnings("unchecked")
  private boolean getPhoneList() {
    JSONObject obj = new JSONObject();
    try {
      obj.put("class", "phones");
      obj.put("function", "getlist");

      return send(obj);
    } catch (Exception e) {
      logger.error("Error retrieving phones");
      return false;
    }
  }
  /**
   * Send needed command for features.
   *
   * @param astid param from previous command.
   * @param xivoUserId param from previous command.
   * @return is command successful.
   */
  @SuppressWarnings("unchecked")
  private boolean sendFeatures(String astid, String xivoUserId) {
    if (connection == null || astid == null || xivoUserId == null) return false;

    JSONObject obj = new JSONObject();
    try {
      obj.put("class", "featuresget");
      obj.put("userid", astid + "/" + xivoUserId);

      return send(obj);
    } catch (Exception e) {
      logger.error("Error send features get command", e);
      return false;
    }
  }
  /**
   * Sends password command.
   *
   * @param sessionId the session id from previous command.
   * @param password the password to authorize.
   * @return is command successful.
   */
  @SuppressWarnings("unchecked")
  private boolean authorize(String sessionId, String password) {
    if (connection == null || sessionId == null || password == null) return false;

    JSONObject obj = new JSONObject();
    try {
      obj.put("class", "login_pass");
      obj.put("hashedpassword", Sha1Crypto.encode(sessionId + ":" + password));

      return send(obj);
    } catch (Exception e) {
      logger.error("Error login with password", e);
      return false;
    }
  }
  /**
   * Sends login command.
   *
   * @param capalistParam param from previous command.
   * @return is command successful.
   */
  @SuppressWarnings("unchecked")
  private boolean sendCapas(JSONArray capalistParam) {
    if (connection == null || capalistParam == null || capalistParam.isEmpty()) return false;

    JSONObject obj = new JSONObject();
    try {
      obj.put("class", "login_capas");
      obj.put("capaid", capalistParam.get(0));
      obj.put("lastconnwins", "false");
      obj.put("loginkind", "agent");
      obj.put("state", "");

      return send(obj);
    } catch (Exception e) {
      logger.error("Error login", e);
      return false;
    }
  }
  /**
   * Sends login command.
   *
   * @param username the username.
   * @return is command successful.
   */
  @SuppressWarnings("unchecked")
  private boolean login(String username) {
    if (connection == null || username == null) return false;

    JSONObject obj = new JSONObject();
    try {
      obj.put("class", "login_id");
      obj.put("company", "Jitsi");

      String os = "x11";
      if (OSUtils.IS_WINDOWS) os = "win";
      else if (OSUtils.IS_MAC) os = "mac";
      obj.put("ident", username + "@" + os);

      obj.put("userid", username);
      obj.put("version", "9999");
      obj.put("xivoversion", "1.1");

      return send(obj);
    } catch (Exception e) {
      logger.error("Error login", e);
      return false;
    }
  }