为适应不同国家或地区的法律法规,声网支持限定访问区域功能。开启限定访问区域功能后,不论用户在哪个区域使用你的 app,SDK 都只会访问指定区域的声网服务器。
例如你指定了北美为访问区域,假设有两位用户分别从北美和中国连接声网服务器:
指定的访问区域 | App 用户所在区域 | SDK 实际访问的区域 | 连接后的用户体验 1 |
---|---|---|---|
北美 | 北美 | 北美 | 正常 |
中国 | 可能受到较大影响 2 |
服务端网关 SDK 支持限定区域访问。一旦指定了访问区域,音视频和消息数据将不会访问指定区域以外的服务器。
你需要在调用 initialize
方法初始化 IAgoraService
实例时,通过设置 AgoraServiceConfiguration
中的 areaCode
参数来指定访问区域。
0xFFFFFFFF
: (默认)全球。0x00000001
: 中国大陆。0x00000002
: 北美。0x00000004
: 欧洲。0x00000008
: 除中国大陆以外的亚洲区域。0x00000010
: 日本。0x00000020
: 印度。区域码支持位操作。
SDK.load(); // ensure JNI library load
// 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);