4

我在使用OpenTok 2 API时遇到了一些问题。当我开始发布流并提示我允许或拒绝网站使用我的网络摄像头和麦克风时,如果我允许 allowed() 应该运行,但如果我拒绝 denied() 应该运行。

publisher.addEventListener('accessAllowed', allowed);
publisher.addEventListener('accessDenied', denied);

function allowed() {
    console.log('Allowed');
}

function denied() {
    console.log('Denied');
}

它在 Firefox 中按预期工作。然而,在 Chrome 中 accessAllowed 有效,accessDenied 无效。相反,我收到以下错误:

OT.Publisher.onStreamAvailableError PermissionDeniedError:
TB.exception :: title: Internal Error (2000) msg: Publisher failed to access camera/mic:

有任何想法吗?

4

1 回答 1

5

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.

于 2014-02-04T22:56:26.480 回答