mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-21 23:57:00 +00:00
d2e13cc826
Move the video resolution subscription down into a lower component so it no longer re-renders the whole Videoconference component on every resolution change. The overall approach still needs validation, but this already avoids the top-level re-render and is a clear improvement over the current behavior.i
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { useEffect } from 'react'
|
|
import { useRoomContext } from '@livekit/components-react'
|
|
import {
|
|
type RemoteParticipant,
|
|
type RemoteTrackPublication,
|
|
RoomEvent,
|
|
Track,
|
|
VideoQuality,
|
|
} from 'livekit-client'
|
|
import { useSnapshot } from 'valtio'
|
|
import { userChoicesStore } from '@/stores/userChoices'
|
|
|
|
/**
|
|
* Sets initial video quality for new participants as they join.
|
|
* LiveKit doesn't allow handling video quality preferences at the room level.
|
|
*/
|
|
export const VideoResolutionSubscription = () => {
|
|
const { videoSubscribeQuality } = useSnapshot(userChoicesStore)
|
|
const room = useRoomContext()
|
|
|
|
useEffect(() => {
|
|
if (!room) return
|
|
|
|
const handleTrackPublished = (
|
|
publication: RemoteTrackPublication,
|
|
_participant: RemoteParticipant
|
|
) => {
|
|
// By default, the maximum quality is set to high
|
|
if (
|
|
videoSubscribeQuality === undefined ||
|
|
videoSubscribeQuality === VideoQuality.HIGH
|
|
)
|
|
return
|
|
|
|
if (
|
|
publication.kind === Track.Kind.Video &&
|
|
publication.source !== Track.Source.ScreenShare
|
|
) {
|
|
publication.setVideoQuality(videoSubscribeQuality)
|
|
}
|
|
}
|
|
|
|
room.on(RoomEvent.TrackPublished, handleTrackPublished)
|
|
return () => {
|
|
room.off(RoomEvent.TrackPublished, handleTrackPublished)
|
|
}
|
|
}, [room, videoSubscribeQuality])
|
|
|
|
return null
|
|
}
|