All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.agora.rtm.RtmConfig Maven / Gradle / Ivy

package io.agora.rtm;

import io.agora.common.internal.CalledByNative;
import io.agora.rtm.RtmConstants;
import io.agora.rtm.RtmConstants.RtmAreaCode;
import io.agora.rtm.RtmConstants.RtmLogLevel;
import io.agora.rtm.RtmEncryptionConfig;
import io.agora.rtm.RtmLogConfig;
import io.agora.rtm.RtmProxyConfig;
import java.util.EnumSet;

/**
 *  Configurations for RTM Client.
 */
public class RtmConfig {
  /**
   * The App ID of your project.
   */
  private final String appId;

  /**
   * The ID of the user.
   */
  private final String userId;

  /**
   * The callbacks reports to the app on RTM SDK runtime events.
   */
  private final RtmEventListener eventListener;

  /**
   * The region for connection. This advanced feature applies to scenarios that
   * have regional restrictions.
   *
   * For the regions that Agora supports, see #AREA_CODE.
   *
   * After specifying the region, the SDK connects to the Agora servers within
   * that region.
   */
  private final EnumSet areaCode;

  /**
   * Presence timeout in seconds, specify the timeout value when you lost connection between sdk
   * and rtm service.
   */
  private final int presenceTimeout;

  /**
   * Whether to use String user IDs, if you are using RTC products with Int user IDs,
   * set this value as 'false'. Otherwise errors might occur.
   */
  private final boolean useStringUserId;

  /**
   * The config for customer set log path, log size and log level.
   */
  private final RtmLogConfig logConfig;

  /**
   * The config for proxy setting
   */
  private final RtmProxyConfig proxyConfig;

  /**
   * The config for encryption setting
   */
  private final RtmEncryptionConfig encryptionConfig;

  public static class Builder {
    // required parameters
    private final String appId;
    private final String userId;

    // optional parameters -- initialized to default values
    private RtmEventListener eventListener;
    private EnumSet areaCode = EnumSet.of(RtmAreaCode.GLOB);
    private int presenceTimeout = 300;
    private boolean useStringUserId = true;
    private RtmLogConfig logConfig = new RtmLogConfig();
    private RtmProxyConfig proxyConfig = new RtmProxyConfig();
    private RtmEncryptionConfig encryptionConfig = new RtmEncryptionConfig();

    public Builder(String appId, String userId) {
      this.appId = appId;
      this.userId = userId;
    }

    public Builder eventListener(RtmEventListener val) {
      eventListener = val;
      return this;
    }

    public Builder areaCode(EnumSet val) {
      areaCode = val;
      return this;
    }

    public Builder presenceTimeout(int val) {
      presenceTimeout = val;
      return this;
    }

    public Builder useStringUserId(boolean val) {
      useStringUserId = val;
      return this;
    }

    public Builder logConfig(RtmLogConfig val) {
      logConfig = val;
      return this;
    }

    public Builder proxyConfig(RtmProxyConfig val) {
      proxyConfig = val;
      return this;
    }

    public Builder encryptionConfig(RtmEncryptionConfig val) {
      encryptionConfig = val;
      return this;
    }

    public RtmConfig build() {
      return new RtmConfig(this);
    }
  }

  private RtmConfig(Builder builder) {
    this.appId = builder.appId;
    this.userId = builder.userId;
    this.eventListener = builder.eventListener;
    this.areaCode = builder.areaCode;
    this.presenceTimeout = builder.presenceTimeout;
    this.useStringUserId = builder.useStringUserId;
    this.logConfig = builder.logConfig;
    this.proxyConfig = builder.proxyConfig;
    this.encryptionConfig = builder.encryptionConfig;
  }

  public RtmEventListener getEventListener() {
    return this.eventListener;
  }

  @CalledByNative
  public String getAppId() {
    return this.appId;
  }

  @CalledByNative
  public String getUserId() {
    return this.userId;
  }

  @CalledByNative
  public int getAreaCode() {
    int val = 0;
    for (RtmAreaCode code : this.areaCode) {
      val |= (RtmAreaCode.getValue(code));
    }
    return val;
  }

  @CalledByNative
  public int getPresenceTimeout() {
    return this.presenceTimeout;
  }

  @CalledByNative
  public boolean isUseStringUserId() {
    return this.useStringUserId;
  }

  @CalledByNative
  public RtmLogConfig getLogConfig() {
    return this.logConfig;
  }

  @CalledByNative
  public RtmProxyConfig getProxyConfig() {
    return this.proxyConfig;
  }

  @CalledByNative
  public RtmEncryptionConfig getEncryptionConfig() {
    return this.encryptionConfig;
  }

  @Override
  public String toString() {
    return "RtmConfig {appId: " + appId + ", userId: " + userId + ", areaCode: " + areaCode
        + ", presenceTimeout: " + presenceTimeout + ", useStringUserId: " + useStringUserId
        + ", logConfig: " + logConfig + ", proxyConfig: " + proxyConfig
        + ", encryptionConfig: " + encryptionConfig + "}";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy