Skip to main content

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:

Network Geofencing

Prerequisites

In order to follow this procedure you must have:

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:


_4
// Set region for geofencing
_4
RtmServiceContext ctx = new RtmServiceContext();
_4
ctx.areaCode = RtmServiceContext.RtmAreaCode.AREA_CODE_CN | RtmServiceContext.RtmAreaCode.AREA_CODE_AS;
_4
RtmClient.setRtmServiceContext(ctx);

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:

Test geofencing

To test this functionality:

  1. Set the APP ID

    In agora-manager/res/raw/config.json, set appId to the AppID of your project.

  2. Set the authentication method

    Choose one of the following authentication methods:

    • Temporary token:
      1. Set rtcToken with the value of your temporary token.
      2. Set channelName - with the name of a channel you used to create the token.
    • Authentication server:
      1. Setup an Authentication server
      2. 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.
  3. Start the Android reference app

    1. In Android Studio, connect a physical Android device to your development machine.

    2. 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.

  1. Test data encryption

    Login to Signaling as multiple users, then send and receive messages using geofencing.

  1. In Android Studio, open app/java/com.example.<projectname>/MainActivity, and update appId, channelName and token with the values for your temporary token.

  2. Connect a physical Android device to your development device.

  3. 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.

  1. 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

API reference

Signaling