-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullscreen.html
106 lines (92 loc) · 2.57 KB
/
fullscreen.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<html>
<head>
</head>
<body>
<style>
body, html {
background: black;
padding: 0;
margin: 0;
}
#webcam-container a.button {
font-family: sans-serif;
text-decoration: none;
background: white;
color: black;
border: 1px solid;
border-radius: 4px;
padding: 8px;
margin-bottom: 4px;
display: block;
}
#webcam-container a:visited {
color: black;
}
.float-button {
position: absolute;
color: rgba(255,255,255,0.25);
text-decoration: none;
font-family: sans-serif;
font-size: larger;
border: 1px solid;
padding: 4px;
border-radius: 4px;
right: 0;
}
.float-button:hover {
background: red;
color: white;
}
</style>
<div id='webcam-container'>
<video id="webcam" autoplay playsinline width="100%"></video>
<a href='?' class='float-button'>reset</a>
</div>
<script>
function init() {
// Just ask so we can do the popup
navigator.getUserMedia({ video: true }, ()=> {}, () =>{});
//
const video = document.getElementById('webcam');
const deviceId = new URL(location.href).searchParams.get('deviceId');
if(!deviceId) {
const container = document.querySelector('#webcam-container');
container.innerHTML = "";;
navigator.mediaDevices.enumerateDevices()
.then((devices) => {
devices.forEach(({ deviceId, label }) => {
const node = document.createElement(`p`);
node.innerHTML = `
<a class='button' href="?deviceId=${deviceId}">${label}</a>
`;
container.appendChild(node);
});
});
} else {
navigator.mediaDevices.enumerateDevices()
.then((d) => {
console.log(d);
});
const constraints = {
video: {
width: {
min: 1280
},
height: {
min: 720
},
deviceId: {
exact: deviceId
}
}
}
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
video.srcObject = stream;
video.play();
});
}
}
init();
</script>
</body>
</html>