11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- import React , { useCallback , useMemo , useRef } from 'react' ;
5- import { useState } from 'react' ;
4+ import React , { useCallback , useMemo , useRef , useState } from 'react' ;
5+ /* @conditional -compile-remove(call-readiness) */
6+ import { useEffect } from 'react' ;
67import { useAdaptedSelector } from '../hooks/useAdaptedSelector' ;
78import { useHandlers } from '../hooks/useHandlers' ;
89import { LocalDeviceSettings } from '../components/LocalDeviceSettings' ;
@@ -136,13 +137,14 @@ export const ConfigurationPage = (props: ConfigurationPageProps): JSX.Element =>
136137 const options = useAdaptedSelector ( getCallingSelector ( DevicesButton ) ) ;
137138 const localDeviceSettingsHandlers = useHandlers ( LocalDeviceSettings ) ;
138139 const { video : cameraPermissionGranted , audio : microphonePermissionGranted } = useSelector ( devicePermissionSelector ) ;
140+ const environmentInfo = useSelector ( getEnvironmentInfo ) ;
139141 /* @conditional -compile-remove(call-readiness) */
140142 // use permission API to get video and audio permission state
141143 const [ videoState , setVideoState ] = useState < PermissionState | 'unsupported' | undefined > ( undefined ) ;
142144 /* @conditional -compile-remove(call-readiness) */
143145 const [ audioState , setAudioState ] = useState < PermissionState | 'unsupported' | undefined > ( undefined ) ;
144146 /* @conditional -compile-remove(call-readiness) */
145- getDevicePermissionState ( setVideoState , setAudioState ) ;
147+ getDevicePermissionState ( environmentInfo , setVideoState , setAudioState , videoState , audioState ) ;
146148
147149 const configContainerRef = useRef < HTMLDivElement > ( null ) ;
148150
@@ -155,7 +157,6 @@ export const ConfigurationPage = (props: ConfigurationPageProps): JSX.Element =>
155157 const stackConfig = ! ! configWidth && configWidth < 450 ;
156158 const errorBarProps = usePropsFor ( ErrorBar ) ;
157159 const microphones = useSelector ( getMicrophones ) ;
158- const environmentInfo = useSelector ( getEnvironmentInfo ) ;
159160
160161 let disableStartCallButton =
161162 ( ! microphonePermissionGranted || microphones ?. length === 0 ) &&
@@ -253,29 +254,33 @@ export const ConfigurationPage = (props: ConfigurationPageProps): JSX.Element =>
253254 const permissionsState : {
254255 camera : PermissionState ;
255256 microphone : PermissionState ;
256- } = {
257- // fall back to using cameraPermissionGranted and microphonePermissionGranted if permission API is not supported
258- camera :
259- videoState && videoState !== 'unsupported'
260- ? cameraPermissionGranted !== false
261- ? videoState
262- : 'denied'
263- : cameraPermissionGranted !== false
264- ? cameraPermissionGranted
265- ? 'granted'
266- : 'prompt'
267- : 'denied' ,
268- microphone :
269- audioState && audioState !== 'unsupported'
270- ? microphonePermissionGranted !== false
271- ? audioState
272- : 'denied'
273- : microphonePermissionGranted !== false
274- ? microphonePermissionGranted
275- ? 'granted'
276- : 'prompt'
277- : 'denied'
278- } ;
257+ } = useMemo (
258+ ( ) => ( {
259+ // fall back to using cameraPermissionGranted and microphonePermissionGranted if permission API is not supported
260+ camera :
261+ videoState && videoState !== 'unsupported'
262+ ? cameraPermissionGranted !== false
263+ ? videoState
264+ : 'denied'
265+ : cameraPermissionGranted !== false
266+ ? cameraPermissionGranted
267+ ? 'granted'
268+ : 'prompt'
269+ : 'denied' ,
270+ microphone :
271+ audioState && audioState !== 'unsupported'
272+ ? microphonePermissionGranted !== false
273+ ? audioState
274+ : 'denied'
275+ : microphonePermissionGranted !== false
276+ ? microphonePermissionGranted
277+ ? 'granted'
278+ : 'prompt'
279+ : 'denied'
280+ } ) ,
281+ [ videoState , audioState , cameraPermissionGranted , microphonePermissionGranted ]
282+ ) ;
283+
279284 /* @conditional -compile-remove(call-readiness) */
280285 const networkErrors = errorBarProps . activeErrorMessages . filter ( ( message ) => message . type === 'callNetworkQualityLow' ) ;
281286
@@ -287,9 +292,11 @@ export const ConfigurationPage = (props: ConfigurationPageProps): JSX.Element =>
287292 /* @conditional -compile-remove(call-readiness) */
288293 const [ minimumFallbackTimerElapsed , setMinimumFallbackTimerElapsed ] = useState ( false ) ;
289294 /* @conditional -compile-remove(call-readiness) */
290- setTimeout ( ( ) => {
291- setMinimumFallbackTimerElapsed ( true ) ;
292- } , 2000 ) ;
295+ useEffect ( ( ) => {
296+ setTimeout ( ( ) => {
297+ setMinimumFallbackTimerElapsed ( true ) ;
298+ } , 2000 ) ;
299+ } , [ ] ) ;
293300 /* @conditional -compile-remove(call-readiness) */
294301 const forceShowingCheckPermissions = ! minimumFallbackTimerElapsed ;
295302
0 commit comments