Restrict media zones
Updated
Restrict access to Agora servers in the specified region
To meet the laws and regulations of different countries or regions, the Agora Video 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 |
|---|---|---|---|
| North America | North America | North America | Normal |
| North America | China | North America | There may be a significant impact on user experience. Due to the cross-region public Internet between the designated area and the area where the app user is located, poor quality of the public Internet network affects the audio and video experience. If the servers in the specified area are not available, the SDK reports an error directly. |
Restricted media zones is an advanced feature of the SDK. Use it only when required for use-cases with access security restrictions.
Implementation
When you specify an access area, audio, video and message data is not accessed from servers outside the specified area.
To specify the area for connection, when initializing an IAgoraService instance by calling initialize, call AgoraServiceConfig.setAreaCode(). The following area codes are available:
0xFFFFFFFF: Global (Default)0x00000001: Mainland China0x00000002: North America0x00000004: Europe0x00000008: Asia, excluding Mainland China0x00000010: Japan0x00000020: India
Area codes support bitwise operations.
Refer to the following sample code to specify an access area:
SDK.load(); // ensure JNI library is loaded
// Create an AgoraService object
AgoraService service = new AgoraService();
if (null == service) {
System.out.printf("createAndInitAgoraService fail\n");
return;
}
AgoraServiceConfig config = new AgoraServiceConfig();
// Disable the audio device module
config.setEnableAudioDevice(0);
// Enable 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);