OpenTok accessDenied issue in Chrome

点点圈 提交于 2019-12-09 13:34:52

问题


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');
}

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:

Any ideas?


回答1:


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);
});

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.



来源:https://stackoverflow.com/questions/21559016/opentok-accessdenied-issue-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!