-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
189 lines (179 loc) · 6.07 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Light node with a view</title>
<script defer data-domain="lens.jcstein.dev" src="https://plausible.io/js/script.js"></script>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
font-family: Arial, sans-serif;
}
.container {
display: flex;
height: 100%;
}
#camera, #lumina {
flex: 1;
overflow: hidden;
position: relative;
}
#camera video {
width: 100%;
height: 100%;
object-fit: cover;
}
#camera video.mirrored {
transform: scaleX(-1);
}
iframe {
width: 100%;
height: 100%;
border: none;
}
#switchCamera {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
z-index: 10;
padding: 10px 20px;
background-color: rgba(0,0,0,0.7);
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
display: none;
}
#privacyPopup {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.8);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
#privacyContent {
background-color: white;
padding: 20px;
border-radius: 10px;
max-width: 80%;
text-align: center;
}
#acceptPrivacy {
margin-top: 20px;
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
#sourceLink {
margin-top: 10px;
font-size: 14px;
}
@media (max-width: 768px) {
.container {
flex-direction: column;
}
}
</style>
</head>
<body>
<div id="privacyPopup">
<div id="privacyContent">
<h2>Privacy Notice</h2>
<p>This site is static and runs entirely in your browser. No video feed or camera data is sent or stored anywhere. Your privacy is fully protected.</p>
<button id="acceptPrivacy">I Understand</button>
<div id="sourceLink">
<a href="https://github.com/jcstein/lens/blob/main/index.html" target="_blank" rel="noopener noreferrer">View Source Code</a>
</div>
</div>
</div>
<div class="container">
<div id="camera">
<video autoplay playsinline></video>
<button id="switchCamera">Switch Camera</button>
</div>
<div id="lumina">
<iframe src="https://lumina.rs" allow="camera; microphone; fullscreen; display-capture; autoplay" sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"></iframe>
</div>
</div>
<script>
const video = document.querySelector('video');
const switchButton = document.getElementById('switchCamera');
const privacyPopup = document.getElementById('privacyPopup');
const acceptPrivacyButton = document.getElementById('acceptPrivacy');
let currentStream = null;
let isUsingFrontCamera = true;
let hasMutipleCameras = false;
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
function updateMirrorEffect() {
if (isUsingFrontCamera || !isMobile) {
video.classList.add('mirrored');
} else {
video.classList.remove('mirrored');
}
}
async function startVideo(useFrontCamera = true) {
const facingMode = useFrontCamera ? 'user' : 'environment';
const constraints = {
video: { facingMode: facingMode }
};
try {
if (currentStream) {
currentStream.getTracks().forEach(track => track.stop());
}
const stream = await navigator.mediaDevices.getUserMedia(constraints);
video.srcObject = stream;
currentStream = stream;
isUsingFrontCamera = useFrontCamera;
updateMirrorEffect();
await video.play();
} catch (error) {
console.error('Error accessing camera:', error);
}
}
async function switchCamera() {
if (hasMutipleCameras) {
await startVideo(!isUsingFrontCamera);
}
}
switchButton.addEventListener('click', switchCamera);
async function initialize() {
try {
await startVideo();
const devices = await navigator.mediaDevices.enumerateDevices();
const videoDevices = devices.filter(device => device.kind === 'videoinput');
if (videoDevices.length > 1) {
hasMutipleCameras = true;
switchButton.style.display = 'block';
}
} catch (error) {
console.error('Error initializing:', error);
}
}
acceptPrivacyButton.addEventListener('click', () => {
privacyPopup.style.display = 'none';
initialize();
});
document.addEventListener('visibilitychange', () => {
if (!document.hidden && currentStream && currentStream.active) {
video.srcObject = currentStream;
video.play().catch(console.error);
}
});
</script>
</body>
</html>