♻️(frontend) refactor full screen to allow video args

useFullScreen hook is now generic, it allows passing a specific
video element to zoom in.

Needed to zoom a specific video track.
This commit is contained in:
lebaudantoine
2025-02-01 15:03:55 +01:00
committed by aleb_the_flash
parent 861244ce01
commit b4b4ff79d9
2 changed files with 27 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ import { useFullScreen } from '../../../hooks/useFullScreen'
export const FullScreenMenuItem = () => {
const { t } = useTranslation('rooms', { keyPrefix: 'options.items' })
const { toggleFullScreen, isCurrentlyFullscreen, isFullscreenAvailable } =
useFullScreen()
useFullScreen({})
if (!isFullscreenAvailable) {
return null

View File

@@ -2,9 +2,32 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { useState } from 'react'
import { useMemo, useState } from 'react'
import { TrackReferenceOrPlaceholder } from '@livekit/components-core'
export function useFullScreen({
trackRef,
}: {
trackRef?: TrackReferenceOrPlaceholder
}) {
const videoElement = useMemo(() => {
const elements = trackRef?.publication?.track?.attachedElements
if (!elements) return
// Find the visible video element
const likeKitElement = elements.find((el) =>
el.classList.contains('lk-participant-media-video')
)
if (!likeKitElement) {
console.warn('Could not find LiveKit-managed video element')
return elements[0] || null
}
return likeKitElement
}, [trackRef])
export function useFullScreen() {
const getIsFullscreen = () => {
return !!(
document.fullscreenElement ||
@@ -24,7 +47,7 @@ export function useFullScreen() {
const enterFullscreen = async () => {
try {
const docEl = document.documentElement
const docEl = videoElement || document.documentElement
if (docEl.requestFullscreen) {
await docEl.requestFullscreen()
} else if (docEl.webkitRequestFullscreen) {