Only refresh if still possible to circumvent pop-up blocker

This commit is contained in:
James Shiffer 2023-07-24 21:05:18 -07:00
parent 2a9e2edc1e
commit 1d8e086cc3

View File

@ -1,13 +1,18 @@
var askedOnce = false;
function ask() { function ask() {
navigator.mediaDevices.getUserMedia({audio:true, video:true}) navigator.mediaDevices.getUserMedia({audio:true, video:true})
.catch(function (e) { .catch(function (e) {
if (e.message === 'Permission denied') { if (e.message === 'Permission denied') {
if (!askedOnce)
return;
if (location.host.indexOf("www") !== 0) if (location.host.indexOf("www") !== 0)
location.host = "www2." + location.host; location.host = "www2." + location.host;
else if (location.host.indexOf("www.") !== 0) else if (location.host.indexOf("www.") !== 0)
location.host = "www" + (Number(location.host[3]) + 1) + "." + location.host.slice(5); location.host = "www" + (Number(location.host[3]) + 1) + "." + location.host.slice(5);
else else
location.host = "www." + location.host; location.host = "www." + location.host;
} else if (e.message === 'Permission dismissed') {
askedOnce = true;
} }
}); });
} }