Geofencing
When a user joins a channel, Video SDK automatically connects them to the closest geographical region of Agora SD-RTN™. However, to meet the laws and regulations of your region, you may want to filter in or filter out connections to a specific geographical region. Agora geofencing enables you to control and customize data routing in your app by specifying the Agora SD-RTN™ region users connect to.
Understand the tech
This section shows you how to enable geofencing in your app. The following figure shows the workflow you implement for geofencing:
Prerequisites
In order to follow this procedure you must have implemented the SDK quickstart project.
Project setup
In order to create the environment necessary to implement geofencing in your app, open the SDK quickstart Video Calling project you created previously.
Implement geofencing in your app
This section shows how to use the Video SDK to implement geofencing in your app.
To enable geofencing in your app, set the mAreaCode
property of config
to a region for geofencing. In /app/java/com.example.<projectname>/MainActivity
, locate the setupVideoSDKEngine
method and add the following code before config.mAppId = appId;
:
If your app fails to connect to the specified region of Agora SD-RTN™, instead of connection to another Agora SD-RTN™ region, Video SDK throws an error. If a firewall is deployed in your network environment, ensure that you:
- Whitelist certain domains
- Allow all IP addresses
- Open the firewall ports defined in Use Cloud Proxy
Test your implementation
To ensure that you have implemented geofencing in your app:
-
Generate a temporary token in Agora Console .
-
In your browser, navigate to the Agora web demo and update App ID, Channel, and Token with the values for your temporary token, then click Join.
-
In Android Studio, in
app/java/com.example.<projectname>/MainActivity
, updateappId
,channelName
andtoken
with the values for your temporary token. -
Connect a physical Android device to your development device.
-
In Android Studio, click Run app. A moment later you see the project installed on your device. If this is the first time you run the project, you need to grant microphone and camera access to your app.
-
Select an option and click Join to start a session.
- When you join as a Host, the local video is published and played in the app.
- When you join as Audience, the remote stream is subscribed and played. You see your app to the specified region Agora SD-RTN™ and opens a channel.
-
Try excluding a region of Agora SD-RTN™.
In
/app/java/com.example.<projectname>/MainActivity
, locate thesetupVideoSDKEngine
method and replaceconfig.mAreaCode = RtcEngineConfig.AreaCode.AREA_CODE_NA
with the following code:
Reference
This section contains information that completes the information in this page, or points you to documentation that explains other aspects to this product.
- When the user's location is different from the specified region, the public network spanning between the user's location and the specified region might have a poor quality, which can make the audio and video experience less than optimal.
- To specify multiple regions for the connection, you can perform bitwise operations on the area codes. To include a region, use the
|
operator, to exclude a region use^
.
Geofencing area codes
The supported area codes are:
AREA_CODE_GLOB
: Global (Default)AREA_CODE_CN
: Mainland ChinaAREA_CODE_NA
: North AmericaAREA_CODE_EU
: EuropeAREA_CODE_AS
: Asia, excluding Mainland ChinaAREA_CODE_JP
: JapanAREA_CODE_IN
: India
The area codes support bitwise operation.