To meet the laws and regulations of different countries or regions, the Agora RTC SDK supports geofencing. After enabling geofencing, the SDK only connects to Agora servers within the specified region, regardless of where your app users are located.
For example, if you specify North America as the region for connection, when two users attempt to connect to Agora servers from different locations, the result is as follows:
Specified region for connection | App user location | Actual region for connection | User experience after connection 1 |
---|---|---|---|
North America | North America | North America | Normal |
China | Can be less than optimal 2 |
When initializing an IAgoraService
instance by calling initialize
, call AgoraServiceConfig.setAreaCode()
to specify the region for connection.
0xFFFFFFFF
: (Default) Global0x00000001
: Mainland China0x00000002
: North America0x00000004
: Europe0x00000008
: Asia, excluding Mainland China0x00000010
: Japan0x00000020
: IndiaThe following sample code shows how to specify North America as the region for connection.
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);