我偶然到了这一点,工作还算不错的方法,而且不需要Cookie(人可以更改这些设置了带外,这样的cookie可以成为不正确),或为Chrome提供一盎司的帮助(不)。
if (chrome) {
var madeMicDecision = false;
navigator.getUserMedia({whatever},
function(stream) {
madeMicDecision = true;
//close the stream, move to the next page
//they have either just granted permission, or have in the past and it's remembered
},
function(error) {
madeMicDecision = true;
//go to error handling page
//the error handling page should describe going to chrome://settings/contentExceptions#media-stream
//or how to allow the user media via clicking on the crossed out camera icon in the 'wonderbar'
}
}
但是我们也希望显示的指南屏幕 - 上面的代码将弹出信息框镀铬如果权限设置不会被记住。但是,如果没有来自chrome的权限事件或查询权限的API,我们如何知道何时显示chrome + infobox教程内容?
我的窍门是自动显示内容,但只能延迟一段时间。之前接受或拒绝权限的人永远不会看到这些内容,因为我们的成功/失败处理程序会在延迟之前将它们移开。因此,请给getUserMedia调用一下时间来检测/反应 - 如果浏览器尚未开启,那么应该显示帮助内容。
setTimeout(function() {
if (!madeMicDescision) {
//display chrome/infobox/getUserMedia permissions help content
}
}, 2000);
不完美(真是奇怪而难过),但似乎适用于最常见的情况。
你最终如何解决这个问题?谢谢。 –
@AdamRabung在这里看到相关的问题:http://stackoverflow.com/questions/23432654/requesting-getusermedia-only-when-permission-is-not-granted我最终设置了一个标志,存储在用户的本地存储与到期。该标志在navigator.getUserMedia API的成功回调中设置。 – SirTophamHatt