简体   繁体   中英

how to detect chrome camera access dialog is open

我如何才能检测到Google Chrome浏览器访问对话框是否打开,我可以检测到用户选择了允许还是拒绝,但是无法检测到对话框是否打开,我需要在其下方显示一个小提示,以了解是否需要打开对话框。我默认打开它,但是如果用户第二次拒绝,则它不会打开

I don't believe that there's actually a way to detect if the dialog is open, but you might be able to infer that it's open. Show your tip each time you call getUserMedia() , and hide it on the callback or any other user interaction with your page (assumption being they denied video access if they're doing other stuff on the page)...

$("#tooltip").show();

navigator.webkitGetUserMedia({"video":true}, function(stream) {
    $("#tooltip").hide();
    // Do your thing.
});

You could also put a delay on showing the tip so it's only shown if the video stream callback doesn't happen for a specified period of time:

var tipTimeout = setTimeout(function() {
    $("#tooltip").show();
}, 1000);

navigator.webkitGetUserMedia({"video":true}, function(stream) {
    clearTimeout(tipTimeout);
    $("#tooltip").hide();
    // Do your thing.
});

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM