uniapp腾讯云语音方案含全局悬浮球

版本说明(2021-02-02):
    hbuilderx  3.0.7.20210123

    腾讯云语音插件:https://ext.dcloud.net.cn/plugin?id=824          1.7.4

    windows 10

主要流程:

     websocket通信,确认接听后开始进入同一个腾讯云语音房间号,然后开始通话;

主要难点及配置说明(基础用法直接参考文档即可):

       

trtcCloud.checkPermission(0);   // 切记 请求录音权限

       1. 切换页面如何保证通话能在后台继续

         我这边是用单独文件,保证实例不被销毁,因为实例全局需要用,可以使用vuex管理状态,在app.vue里面监听来电事件

        

       使用:

       

     

trtcCloud.startLocalAudio();
 trtcCloud.startAudioRecording({},result=>{
  console.log('打开音频');
  console.log(result);
})
trtcCloud.enterRoom({
   appId:appId,
   appKey:appKey,
	roomId:this.$store.getters.phoneRoomId,
	userId:plus.device.uuid,
	callback:r=>{
	 console.log('加入房间')
	}
});

 

2. iphone在app后台时无法发送说话的问题

     https://ask.dcloud.net.cn/article/42

     

3. APP内全局悬浮球问题(代码是写在vuex里面的  根据情况修改即可,主要用的是plus.nativeObj.View)

let url = web.webUrl+'/call.png';
      let width = '40px';
      let leftPos = payload - 40 -20;
      let bottom = uni.upx2px(180); // 单位要做转换
      state.floatCall = new plus.nativeObj.View('floatBall',
          {bottom:bottom+'px',left:leftPos+"px",width:width,radius:width,height:width,dock:"right"},
          [
            {
              tag:'img',id:'img',src:url,
              position:{width:width,height:width,dock:width}
            }
          ]);
      state.floatCall.interceptTouchEvent(true);  // 允许事件
      state.floatCall.addEventListener('click', (r)=>{
        state.floatCall.hide();
        uni.navigateTo({
          url: "/pages/client/kefu/liveaudioroom/liveaudioroom"
        })
      });

      state.floatCall.show();

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值