-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
82 lines (68 loc) · 2.02 KB
/
index.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
<!doctype html>
<html>
<head>
<title>Mirror</title>
<link rel="icon" href="logo.png" type="image/png" />
<link rel="manifest" href="manifest.json">
<meta charset="utf-8" />
<style>
body {
margin: 0;
overflow: hidden;
padding: 0;
text-align: center;
}
.videoElement {
height: 100vh;
margin: 0;
position: relative;
z-index: 2;
}
.videoElement--background {
left: 0;
filter: blur(5px);
height: 100vh;
object-fit: cover;
position: fixed;
top: 0;
width: 100vw;
z-index: 1;
}
.flipHorizontal {
transform: rotateY(180deg);
}
</style>
</head>
<body>
<video autoplay="true" class="videoElement flipHorizontal"></video>
<video autoplay="true" class="videoElement--background flipHorizontal"></video>
<script>
navigator.getUserMedia = [
navigator.getUserMedia,
navigator.webkitGetUserMedia,
navigator.mozGetUserMedia,
navigator.msGetUserMedia,
navigator.oGetUserMedia,
navigator.mediaDevices && navigator.mediaDevices.getUserMedia,
].find(api => api);
const $videos = document.querySelectorAll("video");
function handleVideo(stream) {
[...$videos]
.forEach(video => video.srcObject = stream);
}
function videoError(e) {
document.body.innerText = `You have not granted permission to use webcam or you don't have one.`;
}
navigator.getUserMedia
? navigator.getUserMedia({ video: true }, handleVideo, videoError)
: videoError()
;
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('sw.js', { scope: './' })
.then(reg => console.log('Registration succeeded. Scope is ' + reg.scope))
.catch(error => console.error('Registration failed with ' + error));
}
</script>
</body>
</html>