Skip to main content

You are viewing Agora Docs forBetaproducts and features. Switch to Docs

Android
iOS
macOS
Web
Windows
Electron
Flutter
React Native
React JS
Unity
Unreal Engine
Unreal (Blueprint)

Restrict area access

When a user joins a channel, Video SDK automatically connects them to the region of Agora SD-RTN™ that is geographically closest to the user. However, to meet the laws and regulations of the user's country, you may need to specify, or filter out connections to a specific geographical region. Agora enables you to control and customize data routing in your app by specifying the Agora SD-RTN™ region users connect to.

information

This is an advanced feature suitable only for scenarios with access security restrictions.

Understand the tech

After you turn on the restricted access area feature, the SDK only accesses the Agora server in the specified area, irrespective of the geographical location of the user. As an example, the following table shows the outcome if you specify North America as the access region, and users connect to Agora SD-RTN™ from North America and China respectively:

Designated access area User's region Area actually accessed by the SDK User experience
North America North America North America Normal
China Quality may be affected
information
  • If a server in the specified area is not available, the SDK reports an error.
  • Due to cross-regional public Internet between the designated area and the area where the app user is located, the audio and video experience may be affected.

The following figure shows the workflow you implement to restrict area access:

Network Geofencing

Prerequisites

Ensure that you have implemented the SDK quickstart in your project.

Implement restricted area access

This section shows you how to restrict area access in your app.

You specify the access area by setting the RtcEngineConfig.mAreaCode parameter when calling the create method to create an RtcEngine instance. The available areas are:

  • AREA_CODE_GLOB: Global (Default)
  • AREA_CODE_CN : Mainland China
  • AREA_CODE_NA : North America
  • AREA_CODE_EU : Europe
  • AREA_CODE_AS : Asia excluding Mainland China
  • AREA_CODE_JP : Japan
  • AREA_CODE_IN : India
information

Area codes support bitwise operations.

Include an area

To restrict access to servers in only one region, such as North America, set config.mAreaCode = AREA_CODE_NA; before creating the RtcEngine instance:


_13
// Initialize the App and join the channel
_13
private void initializeAndJoinChannel() {
_13
try {
_13
RtcEngineConfig config = new RtcEngineConfig();
_13
config.mAppId = appId;
_13
config.mContext = mContext;
_13
config.mEventHandler = mEngineEventHandler.mRtcEventHandler;
_13
// Restrict access to servers in North America only
_13
config.mAreaCode = AREA_CODE_NA;
_13
mRtcEngine = RtcEngine.create(config);
_13
} catch (Exception e) {
_13
throw new RuntimeException("Check the error.");
_13
}

Exclude an area

To exclude servers in a region, such as Mainland China, set config.mAreaCode = AREA_CODE_GLOB ^ AREA_CODE_CN; before creating the RtcEngine instance:


_13
// Initialize the App and join the channel
_13
private void initializeAndJoinChannel() {
_13
try {
_13
RtcEngineConfig config = new RtcEngineConfig();
_13
config.mAppId = appId;
_13
config.mContext = mContext;
_13
config.mEventHandler = mEngineEventHandler.mRtcEventHandler;
_13
// Exclude Mainland China from access area
_13
config.mAreaCode = AREA_CODE_GLOB ^ AREA_CODE_CN;
_13
mRtcEngine = RtcEngine.create(config);
_13
} catch (Exception e) {
_13
throw new RuntimeException("Check the error.");
_13
}

Reference

This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

API reference

This section provides links to relevant pages in this article.

Video Calling