-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(frontend) add fullscreen mode on desktop
Added an option allowing users to trigger the fullscreen mode while on desktop. Heavily inspired by the PR #279 from @sylvinus. Yet, this option allow user to enable/disable the fullscreen mode on the whole ui, in the next iteration I'll add the same feature but for a given video track. This is on purpose that the feature is available on desktop only. The hook code has been partially written by Claude and inspired by @sylvinus first suggestion.
- Loading branch information
1 parent
96c18fc
commit b3138b4
Showing
5 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/frontend/src/features/rooms/livekit/hooks/useFullScreen.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// We use vendor prefix properties | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck | ||
|
||
import { useState } from 'react' | ||
|
||
export function useFullScreen() { | ||
const getIsFullscreen = () => { | ||
return !!( | ||
document.fullscreenElement || | ||
document.webkitFullscreenElement || | ||
document.mozFullScreenElement || | ||
document.msFullscreenElement | ||
) | ||
} | ||
|
||
const [isFullscreenAvailable] = useState( | ||
() => | ||
document.fullscreenEnabled || | ||
document.webkitFullscreenEnabled || | ||
document.mozFullScreenEnabled || | ||
document.msFullscreenEnabled | ||
) | ||
|
||
const enterFullscreen = async () => { | ||
try { | ||
const docEl = document.documentElement | ||
if (docEl.requestFullscreen) { | ||
await docEl.requestFullscreen() | ||
} else if (docEl.webkitRequestFullscreen) { | ||
await docEl.webkitRequestFullscreen() | ||
} else if (docEl.msRequestFullscreen) { | ||
await docEl.msRequestFullscreen() | ||
} | ||
} catch (error) { | ||
console.error('Error entering fullscreen:', error) | ||
} | ||
} | ||
|
||
const exitFullscreen = async () => { | ||
try { | ||
if (document.exitFullscreen) { | ||
await document.exitFullscreen() | ||
} else if (document.webkitExitFullscreen) { | ||
await document.webkitExitFullscreen() | ||
} else if (document.msExitFullscreen) { | ||
await document.msExitFullscreen() | ||
} | ||
} catch (error) { | ||
console.error('Error exiting fullscreen:', error) | ||
} | ||
} | ||
|
||
const toggleFullScreen = async () => { | ||
const isCurrentlyFullscreen = getIsFullscreen() | ||
if (isCurrentlyFullscreen) { | ||
await exitFullscreen() | ||
} else { | ||
await enterFullscreen() | ||
} | ||
} | ||
|
||
return { | ||
isCurrentlyFullscreen: getIsFullscreen(), | ||
isFullscreenAvailable, | ||
toggleFullScreen, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters