文档反馈
文档反馈

简化 Promise 链式调用

// 开启麦克风
function startMicro(){
  return netcall.startDevice({
    type: Netcall.DEVICE_TYPE_AUDIO_IN,
    device: deviceMicro,
  }).catch(function(err) {
    console.log('启动麦克风失败', err)
  })
}

// 开启摄像头
function startCamera(){
  return netcall.startDevice({
      type: Netcall.DEVICE_TYPE_VIDEO,
    device: deviceCamera,
      width: 640,
      height: 480
    })
  .catch(function(err) {
    console.log('启动摄像头失败', err)
  })
}

// 设置本地预览画面大小
function setLocalVideoSize(){
  return netcall.setVideoViewSize({
    with: 500,
    height: 500,
    cut:true
  })
}

const netcall = this.netcall
const arrFn = [
  startMicro,
  netcall.setCaptureVolume.bind(netcall),
  startCamera,
  netcall.changeRoleToPlayer.bind(netcall)
  netcall.startRtc.bind(netcall),
  setLocalVideoSize
]

const promise = WebRTC.pipe(arrFn)

promise
  .then(function () {
    console.log('webrtc连接成功')
  })
  .catch(function (e) {
    console.log('发生错误, 结束会话', e)
    netcall.leaveChannel()
  })

上面示例中的一些参数说明如下

obj 属性 类型 说明
deviceMicro obj 指定需要打开的麦克风设备,参考获取指定设备列表
deviceCamera obj 指定需要打开的摄像头设备,参考获取指定设备列表

请注意绑定作用域,防止出现意外错误或者陷入死循环

×

反馈成功

非常感谢您的反馈,我们会继续努力做得更好。