Remove unecassary state for lobby device initialization (#1238)

* remove unecassary state

Signed-off-by: Timo K <toger5@hotmail.de>

* hotfix

Signed-off-by: Timo K <toger5@hotmail.de>

* remove video/audioAvailableAndEnabled
this is not required anymore since we disable the button.

Signed-off-by: Timo K <toger5@hotmail.de>

---------

Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo 2023-07-13 11:20:24 +02:00 committed by GitHub
parent a3ce8384db
commit cac06f9852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,11 +66,6 @@ export function VideoPreview({ matrixInfo, onUserChoicesChanged }: Props) {
const [videoEnabled, setVideoEnabled] = useState<boolean>(true); const [videoEnabled, setVideoEnabled] = useState<boolean>(true);
const [audioEnabled, setAudioEnabled] = useState<boolean>(true); const [audioEnabled, setAudioEnabled] = useState<boolean>(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<boolean>(true);
const [initializingAudio, setInitializingAudio] = useState<boolean>(true);
// The settings are updated as soon as the device changes. We wrap the settings value in a ref to store their initial value. // 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. // Not changing the device options prohibits the usePreviewTracks hook to recreate the tracks.
const initialDefaultDevices = useRef(useDefaultDevices()[0]); const initialDefaultDevices = useRef(useDefaultDevices()[0]);
@ -99,32 +94,23 @@ export function VideoPreview({ matrixInfo, onUserChoicesChanged }: Props) {
const requestPermissions = !!audioTrack && !!videoTrack; const requestPermissions = !!audioTrack && !!videoTrack;
const mediaSwitcher = useMediaDevicesSwitcher( const mediaSwitcher = useMediaDevicesSwitcher(
undefined, undefined,
{ { videoTrack, audioTrack },
videoTrack,
audioTrack,
},
requestPermissions requestPermissions
); );
const { videoIn, audioIn } = mediaSwitcher; const { videoIn, audioIn } = mediaSwitcher;
const videoEl = React.useRef(null); 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(() => { useEffect(() => {
// Effect to update the settings // Effect to update the settings
onUserChoicesChanged({ onUserChoicesChanged({
video: { video: {
selectedId: videoIn.selectedId, selectedId: videoIn.selectedId,
enabled: videoAvailableAndEnabled, enabled: videoEnabled && !!videoTrack,
}, },
audio: { audio: {
selectedId: audioIn.selectedId, selectedId: audioIn.selectedId,
enabled: audioAvailableAndEnabled, enabled: audioEnabled && !!audioTrack,
}, },
}); });
}, [ }, [
@ -133,24 +119,18 @@ export function VideoPreview({ matrixInfo, onUserChoicesChanged }: Props) {
videoEnabled, videoEnabled,
audioIn.selectedId, audioIn.selectedId,
audioEnabled, audioEnabled,
videoAvailableAndEnabled, videoTrack,
audioAvailableAndEnabled, audioTrack,
]); ]);
useEffect(() => { useEffect(() => {
// Effect to update the initial device selection for the ui elements based on the current preview track. // Effect to update the initial device selection for the ui elements based on the current preview track.
if (!videoIn.selectedId || videoIn.selectedId == "") { if (!videoIn.selectedId || videoIn.selectedId == "") {
if (videoTrack) {
setInitializingVideo(false);
}
videoTrack?.getDeviceId().then((videoId) => { videoTrack?.getDeviceId().then((videoId) => {
videoIn.setSelected(videoId ?? "default"); videoIn.setSelected(videoId ?? "default");
}); });
} }
if (!audioIn.selectedId || audioIn.selectedId == "") { if (!audioIn.selectedId || audioIn.selectedId == "") {
if (audioTrack) {
setInitializingAudio(false);
}
audioTrack?.getDeviceId().then((audioId) => { audioTrack?.getDeviceId().then((audioId) => {
// getDeviceId() can return undefined for audio devices. This happens if // getDeviceId() can return undefined for audio devices. This happens if
// the devices list uses "default" as the device id for the current // the devices list uses "default" as the device id for the current
@ -197,13 +177,13 @@ export function VideoPreview({ matrixInfo, onUserChoicesChanged }: Props) {
)} )}
<div className={styles.previewButtons}> <div className={styles.previewButtons}>
<MicButton <MicButton
muted={!audioAvailableAndEnabled} muted={!audioEnabled}
onPress={() => setAudioEnabled(!audioAvailableAndEnabled)} onPress={() => setAudioEnabled(!audioEnabled)}
disabled={!audioTrack} disabled={!audioTrack}
/> />
<VideoButton <VideoButton
muted={!videoAvailableAndEnabled} muted={!videoEnabled}
onPress={() => setVideoEnabled(!videoAvailableAndEnabled)} onPress={() => setVideoEnabled(!videoEnabled)}
disabled={!videoTrack} disabled={!videoTrack}
/> />
<SettingsButton onPress={openSettings} /> <SettingsButton onPress={openSettings} />