Skip to content

Commit

Permalink
fix camera view for back camera
Browse files Browse the repository at this point in the history
  • Loading branch information
jcstein authored Sep 12, 2024
1 parent 4b6adc5 commit 358b155
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
width: 100%;
height: 100%;
object-fit: cover;
}
#camera video.mirrored {
transform: scaleX(-1);
}
iframe {
Expand All @@ -46,10 +48,6 @@
font-size: 16px;
display: none;
}
#switchCamera:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (max-width: 768px) {
.container {
flex-direction: column;
Expand All @@ -73,6 +71,15 @@
let currentStreamTrack = 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';
Expand All @@ -87,6 +94,7 @@
video.srcObject = stream;
currentStreamTrack = stream.getVideoTracks()[0];
isUsingFrontCamera = useFrontCamera;
updateMirrorEffect();
} catch (error) {
console.error('Error accessing camera:', error);
}
Expand Down Expand Up @@ -114,6 +122,7 @@
hasMutipleCameras = false;
switchButton.style.display = 'none';
}
updateMirrorEffect();
}

initialize();
Expand Down

0 comments on commit 358b155

Please sign in to comment.