import { CallingBaseSelectorProps , getDeviceManager , getDiagnostics , getLatestErrors } from './baseSelectors' ; import { ActiveErrorMessage , ErrorType } from '@internal/react-components' ; import { createSelector } from 'reselect' ; import { CallClientState , CallErrors , CallErrorTarget } from '@internal/calling-stateful-client' ; import { DiagnosticQuality } from '@azure/communication-calling' ; /**
 * Selector type for  ErrorBar component.
 *
 *  public export type ErrorBarSelector = ( state : CallClientState , props : CallingBaseSelectorProps ) => { activeErrorMessages : ActiveErrorMessage [ ] ; } ; public export const errorBarSelector = createSelector ( [ getLatestErrors , getDiagnostics , getDeviceManager ] , ( latestErrors , diagnostics , deviceManager ) : { activeErrorMessages : ActiveErrorMessage [ ] ; } => { const activeErrorMessages = [ ] ; if ( diagnostics ?. network . latest . networkReceiveQuality ?. value === DiagnosticQuality . Bad || diagnostics ?. network . latest . networkReceiveQuality ?. value == DiagnosticQuality . Poor ) { activeErrorMessages . push ( { type : 'callNetworkQualityLow' } ) ; } if ( diagnostics ?. media . latest . noSpeakerDevicesEnumerated ) { activeErrorMessages . push ( { type : 'callNoSpeakerFound' } ) ; } if ( diagnostics ?. media . latest . noMicrophoneDevicesEnumerated ) { activeErrorMessages . push ( { type : 'callNoMicrophoneFound' } ) ; } if ( deviceManager . deviceAccess ?. audio === false || diagnostics ?. media . latest . microphoneNotFunctioning ) { activeErrorMessages . push ( { type : 'callMicrophoneAccessDenied' } ) ; } if ( diagnostics ?. media . latest . microphoneMuteUnexpectedly ) { activeErrorMessages . push ( { type : 'callMicrophoneMutedBySystem' } ) ; } if ( diagnostics ?. media . latest . microphonePermissionDenied ) { activeErrorMessages . push ( { type : 'callMacOsMicrophoneAccessDenied' } ) ; } if ( deviceManager . deviceAccess ?. video === false ) { activeErrorMessages . push ( { type : 'callCameraAccessDenied' } ) ; } else { if ( diagnostics ?. media . latest . cameraFreeze ) { activeErrorMessages . push ( { type : 'callCameraAlreadyInUse' } ) ; } } if ( diagnostics ?. media . latest . cameraPermissionDenied ) { activeErrorMessages . push ( { type : 'callMacOsCameraAccessDenied' } ) ; } if ( diagnostics ?. media . latest . screenshareRecordingDisabled ) { activeErrorMessages . push ( { type : 'callMacOsScreenShareAccessDenied' } ) ; } appendActiveErrorIfDefined ( activeErrorMessages , latestErrors , 'Call.stopVideo' , 'stopVideoGeneric' ) ; appendActiveErrorIfDefined ( activeErrorMessages , latestErrors , 'Call.mute' , 'muteGeneric' ) ; appendActiveErrorIfDefined ( activeErrorMessages , latestErrors , 'Call.stopScreenSharing' , 'stopScreenShareGeneric' ) ; appendActiveErrorIfDefined ( activeErrorMessages , latestErrors , 'Call.startVideo' , 'startVideoGeneric' ) ; appendActiveErrorIfDefined ( activeErrorMessages , latestErrors , 'Call.unmute' , 'unmuteGeneric' ) ; activeErrorMessages . splice ( maxErrorCount ) ; return { activeErrorMessages : activeErrorMessages } ; } ) ; const appendActiveErrorIfDefined = ( activeErrorMessages , latestErrors , target , activeErrorType ) : void => { if ( latestErrors [ target ] === undefined ) { return ; } activeErrorMessages . push ( { type : activeErrorType , timestamp : latestErrors [ target ] . timestamp } ) ; } ; const maxErrorCount = 3 ;