/**
   * Logs the current user out and clear the username and auth token. This will terminate the
   * broadcast if necessary.
   */
  public boolean logout() {
    if (getIsIngestTesting()) {
      return false;
    }

    // stop synchronously
    if (this.getIsBroadcasting()) {
      m_Stream.stop(false);
    }

    m_UserName = "";
    m_AuthToken = new AuthToken();

    if (!m_LoggedIn) {
      return false;
    }

    m_LoggedIn = false;

    // only fire the event if the logout was explicitly requested
    if (!m_ShuttingDown) {
      try {
        if (m_Listener != null) {
          m_Listener.onLoggedOut();
        }
      } catch (Exception x) {
        reportError(x.toString());
      }
    }

    setBroadcastState(BroadcastState.Initialized);

    return true;
  }
  /**
   * Terminates the broadcast.
   *
   * @return Whether or not successfully stopped
   */
  public boolean stopBroadcasting() {
    if (!this.getIsBroadcasting()) {
      return false;
    }

    ErrorCode ret = m_Stream.stop(true);
    if (ErrorCode.failed(ret)) {
      String err = ErrorCode.getString(ret);
      reportError(String.format("Error while stopping the broadcast: %s", err));
      return false;
    }

    setBroadcastState(BroadcastState.Stopping);

    return ErrorCode.succeeded(ret);
  }