To meet the laws and regulations of different countries or regions, the Agora RTC SDK supports geofencing. After enabling geofencing, the Agora SDK only connects to Agora servers within the specified region.
For example, if you specify North America as the region for connection, the SDK only connects to Agora servers in North America. When there is no available server in North American, the SDK throws an error instead of connecting to servers in another region.
As of v3.0.0.2, the Agora RTC Native SDK supports network geofencing.
When creating an RtcEngine instance by calling create
, set the mAreaCode
parameter in RtcEngineConfig
to specify the region for connection.
AREA_CODE_GLOB
: (Default) GlobalAREA_CODE_CN
: Mainland ChinaAREA_CODE_NA
: North AmericaAREA_CODE_EU
: EuropeAREA_CODE_AS
: Asia, excluding Mainland ChinaAREA_CODE_JP
: JapanAREA_CODE_IN
: IndiaSpecify the region for connection as North America:
private void initializeEngine() {
try {
RtcEngineConfig config = new RtcEngineConfig();
config.mAppId = appId;
config.mContext = mContext;
config.mEventHandler = mEngineEventHandler.mRtcEventHandler;
config.mAreaCode = AREA_CODE_NA;
mRtcEngine = RtcEngine.create(config);
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
}
...
}
Exclude Mainland China from the regions for connection:
private void initializeEngine() {
try {
RtcEngineConfig config = new RtcEngineConfig();
config.mAppId = appId;
config.mContext = mContext;
config.mEventHandler = mEngineEventHandler.mRtcEventHandler;
config.mAreaCode = AREA_CODE_GLOB ^ AREA_CODE_CN;
mRtcEngine = RtcEngine.create(config);
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
}
...
}
Specify the regions for connection as North America, Europe, Asia, and India:
private void initializeEngine() {
try {
RtcEngineConfig config = new RtcEngineConfig();
config.mAppId = appId;
config.mContext = mContext;
config.mEventHandler = mEngineEventHandler.mRtcEventHandler;
config.mAreaCode = AreaCode.AREA_CODE_NA | AreaCode.AREA_CODE_EU | AreaCode.AREA_CODE_AS | AreaCode.AREA_CODE_IN;
mRtcEngine = RtcEngine.create(config);
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
}
...
}
If a firewall is deployed in your network environment, ensure that you whitelist all domains and ports listed in Use Cloud Proxy.