更新时间:2023-03-23 GMT+08:00

场景10:发起呼叫

描述

在使用华为云会议帐号登录后,可以调用发起呼叫接口发起一路呼叫。

业务流程

使用SDK发起时,先调用startCall接口,然后处理接口回调函数onStartCallResult和订阅的消息通知onCallStateChanged。

  1. 接口调用

    1. 组装数据结构StartCallInfo和回调函数onStartCallResult。
    2. 调用startCall接口发起呼叫,第1步中的数据作为参数。

  2. 处理回调函数

    处理回调函数onStartCallResult。

  3. 处理消息通知

    处理消息通知onCallStateChanged。

  4. 处理消息通知

    处理消息通知onCallEndedNotify。

示例代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* 发起呼叫
*/
async goToStartCall() {
  let { callerNickName, calleeNickName, calleeNumber, calleeThirdUserId, mediaType } = this.state;
  let param = {
    callerInfo: {
      nickName: "" // 主叫人姓名
    },
    calleeInfo: {
      nickName: "Mike", // 被叫人姓名
      number: "+991116003543", // 被叫人号码
      thirdUserId: ""// 被叫人三方账号
    },
    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
/**
* apiService中startCall定义
*/
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);
  });
}

Electron SDK接口中的字符串参数,比如被叫方姓名、呼叫方姓名等,需要编码成UTF8,否则接口会报错。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
/**
* 订阅通话状态消息onCallStateChanged通知
*/
uisdkService.getCallApi().setOnCallStateChangedCB(NotifyService.handleOnCallStateChanged);

/**
* NotifyService中handleOnCallStateChanged定义
*/
static handleOnCallStateChanged(callStateInfo) {
    console.log('OnCallStateChanged', ', callStateInfo = ', callStateInfo);
}

Electron SDK回调函数或者消息通知中的字符串都是UTF8编码的。