Skip to content

Commit

Permalink
Orient live camera feed for best screen fit when in fullscreen mode (#…
Browse files Browse the repository at this point in the history
…16947)

* Change orientation in fullscreen to best fit video

* Refactor effect to simplify, add more comments
  • Loading branch information
jdryden572 authored Mar 4, 2025
1 parent c236533 commit 389c707
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions web/src/views/live/LiveCameraView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,28 @@ export default function LiveCameraView({
}
}, [fullscreen, isPortrait, cameraAspectRatio, containerAspectRatio]);

// On mobile devices that support it, try to orient screen
// to best fit the camera feed in fullscreen mode
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const screenOrientation = screen.orientation as any;
if (!screenOrientation.lock || !screenOrientation.unlock) {
// Browser does not support ScreenOrientation APIs that we need
return;
}

if (fullscreen) {
const orientationForBestFit =
cameraAspectRatio > 1 ? "landscape" : "portrait";

// If the current device doesn't support locking orientation,
// this promise will reject with an error that we can ignore
screenOrientation.lock(orientationForBestFit).catch(() => {});
}

return () => screenOrientation.unlock();
}, [fullscreen, cameraAspectRatio]);

const handleError = useCallback(
(e: LivePlayerError) => {
if (e) {
Expand Down

0 comments on commit 389c707

Please sign in to comment.