区域访问限制

  • Java

更新时间

了解如何在 RTC 服务端 SDK 中区域访问限制,包括适用场景、配置步骤、实现要点和注意事项。

为适应不同国家或地区的法律法规,声网支持限定访问区域功能。

开启限定访问区域功能后,不论用户在哪个区域使用你的 app,SDK 都只会访问指定区域的声网服务器。

例如你指定了北美为访问区域,假设有两位用户分别从北美和中国连接声网服务器:

指定访问区域App 用户所在区域SDK 实际访问区域连接后的用户体验
北美北美北美正常
中国可能受到较大影响。由于指定区域与 app 用户所在区域之间存在跨区域公共互联网,公共互联网网络质量较差会导致音视频体验受到影响。如果指定区域的服务器都不可用,SDK 会直接报错。
表格内容超出当前宽度,可横向滚动查看更多列。

信息

  • 如果指定区域的服务器都不可用,SDK 会直接报错。
  • 区域访问限制是 SDK 的高级设置功能,声网建议你仅在有访问安全限制的场景使用。

实现方法

服务端 SDK 支持限定区域访问。一旦指定了访问区域,音视频和消息数据将不会访问指定区域以外的服务器。

你需要在调用 initialize 方法初始化 IAgoraService 实例时,通过设置 AgoraServiceConfiguration 中的 areaCode 参数来指定访问区域。

  • 0xFFFFFFFF: (默认)全球。
  • 0x00000001: 中国大陆。
  • 0x00000002: 北美。
  • 0x00000004: 欧洲。
  • 0x00000008: 除中国大陆以外的亚洲区域。
  • 0x00000010: 日本。
  • 0x00000020: 印度。

区域码支持位操作。

示例代码

Java
// Creates an AgoraService object
AgoraService service = new AgoraService();
if (null == service) {
    System.out.printf("createAndInitAgoraService fail\n");
    return;
}
AgoraServiceConfig config = new AgoraServiceConfig();
// Disables the audio device module (Normally we do not directly connect audio capture or playback devices to a server)
config.setEnableAudioDevice(0);
// Enables the audio processing module
config.setEnableAudioProcessor(1);
// Whether to enable video
config.setEnableVideo(0);
// Specify North America as the region for connection
config.setAreaCode(0x00000002);
int ret = service.initialize(config);