微信小程序调用语音通话功能出错:
join1v1Chat:fail jsapi has no permission, event=join1v1VoIPChat, runningState=foreground, permissionMsg=permission got, detail=jsapi has no permission
该问题在ios系统中会出现,安卓系统正常。
部分代码如下:
async function requestAuthorize(useCamera = false) {
try {
console.debug('申请麦克风权限...')
await wx.authorize({ scope: 'scope.record' })
console.debug('申请麦克风权限成功!')
if (useCamera) {
console.debug('申请相机权限...')
await wx.authorize({ scope: 'scope.camera' })
console.debug('申请相机权限成功!')
}
} catch (err) {
throw new Error('需要授权才能使用通话功能')
}
}
async function start1v1Call(room: IRoomInfo) {
const { type: roomType, listener, caller } = room
if (!listener || !caller) return
console.log('room: ', room)
state.value.room = room
// 调用如下
try {
await requestAuthorize(room.type === 'video')
console.debug('启用1v1通话...')
await wx.setEnable1v1Chat({ enable: true })
console.debug('加入1v1通话...')
await wx
.join1v1Chat({
caller,
listener,
roomType,
minWindowType: 0,
disableSwitchVoice: false,
})
.then(() => {
console.warn('join1v1Chat: success!')
})
} catch (error) {
console.warn('操作失败:: ', error)
throw error
}
}
