问题描述
我在使用 OpenTok 2 API 。当我开始发布流并提示允许或拒绝网站使用我的摄像头和麦克风时,如果允许允许()应该运行,但是如果拒绝拒绝()应该运行。
I'm having some trouble with the OpenTok 2 API. When I start to publish a stream and I'm prompted to allow or deny the website to use my webcam and microphone, if I allow allowed() should run, but if I deny denied() should run.
publisher.addEventListener('accessAllowed', allowed);
publisher.addEventListener('accessDenied', denied);
function allowed() {
console.log('Allowed');
}
function denied() {
console.log('Denied');
}
它在Firefox中按预期工作。然而,在Chrome accessAllowed的作品中,accessDenied并没有。相反,我得到以下错误:
It works as expected in Firefox. In Chrome accessAllowed works, however, accessDenied doesn't. Instead I get the following error:
OT.Publisher.onStreamAvailableError PermissionDeniedError:
TB.exception :: title: Internal Error (2000) msg: Publisher failed to access camera/mic:
有什么想法?
推荐答案
这是OpenTok当前JS库中的一个错误。我有一个解决方法,应该让你去,当bug修复时,我会回来更新。
This is a bug in the current JS library at OpenTok. I do have a workaround that should get you going and I'll come back with an update when the bug is fixed.
var waiting = false;
publisher.addEventListener('accessAllowed', function() {
waiting = false;
allowed();
});
publisher.addEventListener('accessDenied', function() {
waiting = false;
denied();
});
publisher.addEventListener('accessDialogOpened', function() {
waiting = true;
});
publisher.addEventListener('accessDialogClosed', function() {
setTimeout(function() {
if (waiting) {
waiting = false;
denied();
}
}, 0);
});
这个解决方法略有限制,因为Chrome在拒绝访问一次,然后访问页面。如果用户没有更改他/她有关媒体权限的偏好,则视频将继续被拒绝,并且'accessDialogOpened'甚至不会触发。我会通知团队并继续研究。
This workaround is slightly limited because Chrome has some weirdness when it comes to denying access once and then visiting the page again. If the user hasn't changed his/her preferences regarding the media permissions, the video will continue to be denied and the 'accessDialogOpened' won't even fire. I'll inform the team and continue to look into this.
这篇关于Chrome中出现OpenTok accessDenied问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!