diff --git a/src/room/VideoPreview.tsx b/src/room/VideoPreview.tsx index f76c8e5b..ae5e311c 100644 --- a/src/room/VideoPreview.tsx +++ b/src/room/VideoPreview.tsx @@ -66,11 +66,6 @@ export function VideoPreview({ matrixInfo, onUserChoicesChanged }: Props) { const [videoEnabled, setVideoEnabled] = useState(true); const [audioEnabled, setAudioEnabled] = useState(true); - // we store if the tracks are currently initializing to not show them as muted. - // showing them as muted while they are not yet available makes the buttons flicker undesirable during startup. - const [initializingVideo, setInitializingVideo] = useState(true); - const [initializingAudio, setInitializingAudio] = useState(true); - // The settings are updated as soon as the device changes. We wrap the settings value in a ref to store their initial value. // Not changing the device options prohibits the usePreviewTracks hook to recreate the tracks. const initialDefaultDevices = useRef(useDefaultDevices()[0]); @@ -99,32 +94,23 @@ export function VideoPreview({ matrixInfo, onUserChoicesChanged }: Props) { const requestPermissions = !!audioTrack && !!videoTrack; const mediaSwitcher = useMediaDevicesSwitcher( undefined, - { - videoTrack, - audioTrack, - }, + { videoTrack, audioTrack }, requestPermissions ); const { videoIn, audioIn } = mediaSwitcher; const videoEl = React.useRef(null); - // pretend the video is available until the initialization is over - const videoAvailableAndEnabled = - videoEnabled && (!!videoTrack || initializingVideo); - const audioAvailableAndEnabled = - audioEnabled && (!!videoTrack || initializingAudio); - useEffect(() => { // Effect to update the settings onUserChoicesChanged({ video: { selectedId: videoIn.selectedId, - enabled: videoAvailableAndEnabled, + enabled: videoEnabled && !!videoTrack, }, audio: { selectedId: audioIn.selectedId, - enabled: audioAvailableAndEnabled, + enabled: audioEnabled && !!audioTrack, }, }); }, [ @@ -133,24 +119,18 @@ export function VideoPreview({ matrixInfo, onUserChoicesChanged }: Props) { videoEnabled, audioIn.selectedId, audioEnabled, - videoAvailableAndEnabled, - audioAvailableAndEnabled, + videoTrack, + audioTrack, ]); useEffect(() => { // Effect to update the initial device selection for the ui elements based on the current preview track. if (!videoIn.selectedId || videoIn.selectedId == "") { - if (videoTrack) { - setInitializingVideo(false); - } videoTrack?.getDeviceId().then((videoId) => { videoIn.setSelected(videoId ?? "default"); }); } if (!audioIn.selectedId || audioIn.selectedId == "") { - if (audioTrack) { - setInitializingAudio(false); - } audioTrack?.getDeviceId().then((audioId) => { // getDeviceId() can return undefined for audio devices. This happens if // the devices list uses "default" as the device id for the current @@ -197,13 +177,13 @@ export function VideoPreview({ matrixInfo, onUserChoicesChanged }: Props) { )}
setAudioEnabled(!audioAvailableAndEnabled)} + muted={!audioEnabled} + onPress={() => setAudioEnabled(!audioEnabled)} disabled={!audioTrack} /> setVideoEnabled(!videoAvailableAndEnabled)} + muted={!videoEnabled} + onPress={() => setVideoEnabled(!videoEnabled)} disabled={!videoTrack} />