Skip to main content

You are viewing Agora Docs forBeta products and features. Switch to Docs

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.

Set the geofencing configuration


_2
// Define the set of area codes
_2
val areaCodes = EnumSet.of(RtmAreaCode.NA, RtmAreaCode.EU)

Apply the configuration to the Signaling Engine


_13
try {
_13
val rtmConfig = RtmConfig.Builder(appId, uid.toString())
_13
.presenceTimeout(config!!.optString("presenceTimeout").toInt())
_13
.useStringUserId(false)
_13
.eventListener(eventListener)
_13
.areaCode(areaCodes) // Specify the area codes
_13
.build()
_13
signalingEngine = RtmClient.create(rtmConfig)
_13
localUid = uid
_13
} catch (e: Exception) {
_13
notify(e.toString())
_13
return false
_13
}

Test geofencing

To test the geofencing functionality:

  1. Configure the project

    1. Open the file <samples-root>/signaling-manager/src/main/res/raw/config.json

    2. Set appId to the AppID of your project.

    3. Choose one of the following authentication methods:

      • Temporary token:
        1. Generate an RTM token using your uid.
        2. Set token to this value in config.json.
      • Authentication server:
        1. Setup an Authentication server
        2. In config.json, set:
          • token to an empty string.
          • serverUrl to the base URL for your token server. For example: https://agora-token-service-production-yay.up.railway.app.
  2. Run the reference app

    1. In Android Studio, connect a physical Android device to your development machine.
    2. Click Run to start the app.
    3. A moment later you see the project installed on your device.
  3. Test geofencing

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

    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:

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