-
Notifications
You must be signed in to change notification settings - Fork 0
/
gum_query.html
37 lines (33 loc) · 908 Bytes
/
gum_query.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<html>
<meta charset=utf-8>
<video id="video" width="320" height="240" autoplay muted></video><br>
<button id="button">Go!</button>
<div id="div"></div>
<script>
const console = {log: msg => div.innerHTML += `${msg}<br>`};
const wait = ms => new Promise(r => setTimeout(r, ms));
(async () => {
try {
await dumpState("Before: ");
} catch(e) {
console.log(e);
}
})();
button.onclick = async () => {
try {
const stream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});
video.srcObject = stream;
await dumpState("After: ");
} catch(e) {
console.log(e);
}
};
async function dumpState(header = "") {
const [cam, mic] = await Promise.all([
navigator.permissions.query({name: "camera"}),
navigator.permissions.query({name: "microphone"})
]);
console.log(`${header}camera = "${cam.state}", microphone = "${mic.state}"`)
}
</script>
</html>