-
Notifications
You must be signed in to change notification settings - Fork 0
/
gum_video_button_beforeunload.html
41 lines (36 loc) · 1.09 KB
/
gum_video_button_beforeunload.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
38
39
40
41
<html>
<meta charset=utf-8>
<div id="div"></div>
<button id="button">Camera</button>
<button id="trackstop">Stop</button>
<button id="reload">Refresh page</button>
<a href="https://mozilla.github.io/webrtc-landing/enumerate.html">Navigate</a><br>
<video id="video" width="320" height="200" autoplay></video><br>
<script>
const console = { log: msg => div.innerHTML += msg + "<br>" };
button.onclick = async () => {
try {
video.srcObject = await navigator.mediaDevices.getUserMedia({video: true});
} catch(e) {
console.log(e);
}
};
trackstop.onclick = () => {
for (const track of video.srcObject.getTracks()) track.stop();
video.srcObject = null;
}
reload.onclick = () => location.reload();
const beforeUnloadListener = (event) => {
event.preventDefault();
return event.returnValue = "Are you sure you want to exit?";
};
window.onbeforeunload = event => {
event.preventDefault();
return event.returnValue = "Are you sure you want to exit?";
};
window.onunload = () => {
navigator.mediaDevices.getUserMedia({video: true}).catch(() => {});
trackstop.onclick();
}
</script>
</html>