Flip user-facing camera stream

This commit is contained in:
Joscha 2024-03-29 20:39:03 +01:00
parent 0bd6c08528
commit ed9fb6d23a

View file

@ -19,6 +19,10 @@
height: 100%; height: 100%;
} }
video.mirrored {
scale: -1 1;
}
#button { #button {
position: absolute; position: absolute;
bottom: 20px; bottom: 20px;
@ -106,8 +110,13 @@
}); });
video.srcObject = stream; video.srcObject = stream;
// Enable or disable flip button // Flip video horizontally if it's facing the user
const facing = getStreamFacingMode(stream); const facing = getStreamFacingMode(stream);
if (facing !== "environment") {
video.classList.add("mirrored");
}
// Enable or disable flip button
const canFlip = facing !== undefined; const canFlip = facing !== undefined;
const facingOpposite = facing === "user" ? "environment" : "user"; const facingOpposite = facing === "user" ? "environment" : "user";
flip.hidden = !canFlip; flip.hidden = !canFlip;