To meet the laws and regulations of different countries or regions, the Agora RTC SDK supports geofencing. After enabling geofencing, the Agora SDK only connects to Agora servers within the specified region.
If you specify the region for connection, the SDK only connects to Agora servers in this region. When there is no available server in this region, the SDK throws an error instead of connecting to servers in another region.
Before adjusting the audio volume, ensure that you have implemented the basic real-time communication functions in your project. For details, see Start a Call or Start Interactive Live Streaming.
When creating an RtcEngine instance by calling initialize
, set the AreaCode
parameter in RtcEngineContext
to specify the region for connection.
AREA_CODE_GLOB
: (Default) GlobalAREA_CODE_CN
: Mainland ChinaAREA_CODE_NA
: North AmericaAREA_CODE_EU
: EuropeAREA_CODE_AS
: Asia, excluding Mainland ChinaAREA_CODE_JP
: JapanAREA_CODE_IN
: IndiaTo specify a region for connection (such as North America) , add context.areaCode = AREA_CODE_NA;
before calling initialize
.
// Initialize the Agora SDK
bool CAgoraRegionConnDlg::InitAgora()
{
// Create an AgoraRtcEngine
m_rtcEngine = createAgoraRtcEngine();
if (!m_rtcEngine) {
m_lstInfo.InsertString(m_lstInfo.GetCount() - 1, _T("createAgoraRtcEngine failed"));
return false;
}
// Set the message receiver
m_eventHandler.SetMsgReceiver(m_hWnd);
RtcEngineContext context;
std::string strAppID = GET_APP_ID;
context.appId = strAppID.c_str();
CString area_code;
m_cmbAreaCode.GetWindowText(area_code);
// Specify the region for connection as North America
context.areaCode = AREA_CODE_NA;
// Initialize the RtcEngineContext
int ret = m_rtcEngine->initialize(context);
if (ret != 0) {
m_initialize = false;
CString strInfo;
strInfo.Format(_T("initialize failed: %d"), ret);
m_lstInfo.InsertString(m_lstInfo.GetCount(), strInfo);
return false;
}
else
m_initialize = true;
m_lstInfo.InsertString(m_lstInfo.GetCount(), _T("initialize success"));
}
To exclude a region for connection (such as Mainland China), add context.areaCode = AREA_CODE_GLOB ^ AREA_CODE_CN;
before calling initialize
.
// Initialize the Agora SDK
bool CAgoraRegionConnDlg::InitAgora()
{
// Create an AgoraRtcEngine
m_rtcEngine = createAgoraRtcEngine();
if (!m_rtcEngine) {
m_lstInfo.InsertString(m_lstInfo.GetCount() - 1, _T("createAgoraRtcEngine failed"));
return false;
}
// Set the message receiver
m_eventHandler.SetMsgReceiver(m_hWnd);
RtcEngineContext context;
std::string strAppID = GET_APP_ID;
context.appId = strAppID.c_str();
CString area_code;
m_cmbAreaCode.GetWindowText(area_code);
// Exclude Mainland China from the regions for connection.
context.areaCode = AREA_CODE_GLOB ^ AREA_CODE_CN;
// Initialize the RtcEngineContext
int ret = m_rtcEngine->initialize(context);
if (ret != 0) {
m_initialize = false;
CString strInfo;
strInfo.Format(_T("initialize failed: %d"), ret);
m_lstInfo.InsertString(m_lstInfo.GetCount(), strInfo);
return false;
}
else
m_initialize = true;
m_lstInfo.InsertString(m_lstInfo.GetCount(), _T("initialize success"));
}
This section includes links to related pages.
Agora provides an open-source sample project RegionConn on GitHub.