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 making a call.

Service Process

When using the SDK to make a call, call the startCall API and implement the API callback function onStartCallResult and subscribed-to message notification onCallStateChanged.

  1. Call an API.

    1. Assemble the data structure StartCallInfo and callback function onStartCallResult.
    2. Call the startCall API to initiate the call. The data in the preceding step is used as input parameters.

  2. Implement the callback function.

    Implement the onStartCallResult function.

  3. Implement the notification function.

    Implement the onCallStateChanged function.

  4. Implement the notification function.

    Implement the onCallEndedNotify 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
/**
* Initiate a call.
*/
async goToStartCall() {
  let { callerNickName, calleeNickName, calleeNumber, calleeThirdUserId, mediaType } = this.state;
  let param = {
    callerInfo: {
      nickName: "" // Caller name.
    },
    calleeInfo: {
      nickName: "Mike", // Name of the called participant.
      number: "+991116003543", // Called number.
      thirdUserId: ""// Third-party account of the called participant.
    },
    mediaType: mediaType,
  }
  const apiService = new ApiService();
  let setResult = await apiService.startCall(param);
  if (setResult.ret != 0) {
    window.electron.ipcRenderer.send("show-error-alert", "startCall error = " + setResult.ret);
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
/**
* Definition of startCall in apiService
*/
async startCall(startCallInfo) {
  return new Promise((resolve) => {
    let resultCallback = (ret, reason) => {
      console.log("startCall, out data = ", { ret, reason });
      resolve({ ret, reason });
    };
    console.log("startCall, in param = ", startCallInfo);
    this.uisdkService.getCallApi().startCall(startCallInfo, resultCallback);
  });
}

Parameters, such as names of the caller and called participant, in Electron SDK APIs must be encoded in UTF-8. Otherwise, an error will be reported.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
/**
* Subscribe to the call status notification onCallStateChanged.
*/
uisdkService.getCallApi().setOnCallStateChangedCB(NotifyService.handleOnCallStateChanged);

/**
* Definition of handleOnCallStateChanged in NotifyService
*/
static handleOnCallStateChanged(callStateInfo) {
    console.log('OnCallStateChanged', ', callStateInfo = ', callStateInfo);
}

Character strings in Electron SDK callback functions or message notifications are encoded in UTF-8.