Updated on 2023-03-23 GMT+08:00

Scenario 10: Initiating a Call

Description

After logging in to the system using a Huawei Cloud Meeting account, you can call the API for initiating a call.

Service Process

When the SDK is used to initiate a call, the StartCall API is called, and then the callback function OnStartCallResult and message notifications OnCallState, OnCallInfo, and OnCallRecordInfo are processed.

  1. Call the API.

    1. Create a HwmStartCallInfo object.
    2. Call the StartCall API to join a meeting. The data in preceding steps is used as input parameters.

  2. Implement the callback function.

    Implement the OnStartCallResult function.

  3. Implement the notification function.

    Implement the OnCallState function.

  4. Implement the notification function.

    Implement the OnCallInfo function.

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Initiate a call.
*/
int demoStartCallDlg::clickStartCall()
{
    hwmsdkagent::HwmStartCallInfo data;
    memset(&data, 0, sizeof(hwmsdkagent::HwmStartCallInfo));
 
//Name of the callee
    CString calleeNameCstr;
    m_calleeNameEdit.GetWindowText(calleeNameCstr);
    string calleeName = CTools::UNICODE2UTF(calleeNameCstr);
    errno_t nRet = strcpy_s(data.callee.name, sizeof(data.callee.name), calleeName.c_str());
 
    // Called number
    CString calleeNumberCstr;
    m_calleeNumberEdit.GetWindowText(calleeNumberCstr);
    string calleeNumber = CTools::UNICODE2UTF(calleeNumberCstr);
    nRet += strcpy_s(data.callee.number, sizeof(data.callee.number), calleeNumber.c_str());
 
    // Third-party account of the called participant
    CString calleeThirdUserIdCstr;
    m_calleeThirdUserIdEdit.GetWindowText(calleeThirdUserIdCstr);
    string calleeThirdUserId = CTools::UNICODE2UTF(calleeThirdUserIdCstr);
    nRet += strcpy_s(data.callee.thirdUserId, sizeof(data.callee.thirdUserId), calleeThirdUserId.c_str());
 
    // Name of the caller
    CString callerNameCstr;
    m_callerNameEdit.GetWindowText(callerNameCstr);
    string callerName = CTools::UNICODE2UTF(callerNameCstr);
    nRet += strcpy_s(data.name, sizeof(data.name), callerName.c_str());
 
    if (nRet != 0)
    {
        AfxMessageBox(_T("String Copy Error!"));
    }
 
    // Video or audio
    CString callTypeCString;
    m_callTypeCombo.GetWindowText(callTypeCString);
    hwmsdkagent::HwmCallType type = hwmsdkagent::CALL_TYPE_VIDEO;
    if (_T("Video") == callTypeCString)
    {
        data.callType = hwmsdkagent::CALL_TYPE_VIDEO;
    }
    else if (_T("Audio") == callTypeCString)
    {
        data.callType = hwmsdkagent::CALL_TYPE_AUDIO;
    }
 
    int ret = hwmsdkagent::StartCall(&data);
 
    return ret;
}

Character string parameters, such as the callee and caller names, in Windows SDK APIs. These parameters must be encoded in UTF-8. Otherwise, an error will be reported.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
/**
* Callback of the API for initiating a call
*/
void demoCallbackProc::OnStartCallResult(hwmsdk::HwmErrCode ret, const char * reason)
{
    Cdemo* app = (Cdemo*)AfxGetApp();
    if (!app || reason == NULL)
    {
        // The window is closed.
        return;
    }
    CString codeStr;
    codeStr.Format(_T("%d"), ret);
    string msgStr = CTools::UTF82MultiByte(reason);
    CString tips = _T("OnStartCallResult code:") + codeStr + _T(", msg:") + CString(msgStr.c_str());
    AfxMessageBox(tips);
}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Call status notification
*/
void demoNotifyProc::OnCallState(const HwmCallStateInfo *callStateInfo)
{
    Cdemo* app = (Cdemo*)AfxGetApp();
    if (!app || callStateInfo == NULL)
    {
        // The window is closed.
        return;
    }
 
    CString state;
    state.Format(_T("%d"), callStateInfo->state);
    CString callId;
    callId.Format(_T("%d"), callStateInfo->callId);
 
    CString tips = _T("OnCallState state:") + state + _T(", callId:" + callId);
    AfxMessageBox(tips);
 
}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Call details notification
*/
void demoNotifyProc::OnCallInfo(const HwmCallInfo *callInfo)
{
    Cdemo* app = (Cdemo*)AfxGetApp();
    if (!app || callInfo == NULL)
    {
        // The window is closed.
        return;
    }
 
    CString callType;
    callType.Format(_T("%d"), callInfo->callType);
 
    string number = CTools::UTF82MultiByte(callInfo->number);
    string name = CTools::UTF82MultiByte(callInfo->name);
    string startTime = CTools::UTF82MultiByte(callInfo->startTime);
    string endTime = CTools::UTF82MultiByte(callInfo->endTime);
 
    CString isCallOut;
    isCallOut.Format(_T("%d"), callInfo->isCallOut);
    CString callId;
    callId.Format(_T("%d"), callInfo->callId);
 
    CString tips = _T("OnCallInfo callType:") + callType + _T(", number:") + CString(number.c_str()) 
        + _T(", name:") + CString(name.c_str()) + _T(", startTime:") + CString(startTime.c_str()) 
        + _T(", endTime:") + CString(endTime.c_str()) + _T(", isCallOut:") + isCallOut + _T(", callId:") + callId;
    AfxMessageBox(tips);
}

Character strings in Windows SDK functions are encoded in UTF-8.