Geofencing
When a user joins a channel, Signaling 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 for Signaling.
Implement geofencing in your app
This section shows how to use the Signaling SDK to implement geofencing in your app.
Call AgoraRTM.setArea
to specify the region to connect to. After specifying the region, Signaling SDK connects
to the Agora servers within that region. The following regions are supported:
-
GLOBAL
: (Default) Global. -
CHINA
: Mainland China. -
ASIA
: Asia excluding mainland China. -
EUROPE
: Europe. -
INDIA
: India. -
JAPAN
: Japan. -
NORTH_AMERICA
: North America.
The following code shows you how to set the geolocation:
If your app fails to connect to the specified region of Agora SD-RTN™, instead of connection to another Agora SD-RTN™ region, Signaling 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 IP addresses for Cloud Proxy.
Test geofencing
To test this functionality:
-
Set the APP ID
In
agora-manager/res/raw/config.json
, setappId
to the AppID of your project. -
Set the authentication method
Choose one of the following authentication methods:
- Temporary token:
- Set
rtcToken
with the value of your temporary token. - Set
channelName
- with the name of a channel you used to create the token.
- Set
- Authentication server:
- Setup an Authentication server
- In
config.json
, set:channelName
with the name of a channel you want to join.rtcToken
to an empty string.serverUrl
to the base URL of your authentication server. For example,https://agora-token-service-production-1234.up.railway.app
.
- Temporary token:
-
Start the Android reference app
-
In Android Studio, connect a physical Android device to your development machine.
-
Click Run to start the 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.
-
-
Test data encryption
Login to Signaling as multiple users, then send and receive messages using geofencing.
-
In Android Studio, open
app/java/com.example.<projectname>/MainActivity
, and 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, grant microphone and camera access to your app.
- Click Join to start a call.
You see your app starts the proxy service and magically connects to the Agora SD-RTN™ which was not possible in a restricted network environment.
Reference
This section contains information that completes the information in this page, or points you to documentation that explains other aspects to this product.
Firewall requirements
If a firewall is deployed in your network environment, ensure that you add the domains in the following table according to the region you specify, allow all IP addresses, and open the following firewall ports.
-
Whitelist domains
Region Domain Mainland China
webrtc2-ap-web-2.agoraio.cn
webrtc2-ap-web-4.agoraio.cn
statscollector-3.agoraio.cn
statscollector-4.agoraio.cn
logservice-china.agora.io
North America
ap-web-1-north-america.agora.io
ap-web-2-north-america.agora.io
statscollector-1-north-america.agora.io
statscollector-2-north-america.agora.io
logservice-north-america.agora.io
Europe
ap-web-1-europe.agora.io
ap-web-2-europe.agora.io
statscollector-1-europe.agora.io
statscollector-2-europe.agora.io
logservice-europe.agora.io
Japan
ap-web-1-japan.agora.io
ap-web-2-japan.agora.io
statscollector-1-japan.agora.io
statscollector-2-japan.agora.io
logservice-japan.agora.io
India
ap-web-1-india.agora.io
ap-web-2-india.agora.io
statscollector-1-india.agora.io
statscollector-2-india.agora.io
logservice-india.agora.io
Asia excluding mainland China
ap-web-1-asia.agora.io
ap-web-2-asia.agora.io
statscollector-1-asia.agora.io
statscollector-2-asia.agora.io
logservice-asia.agora.io
-
Port - See the Firewall Requirements