-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathMicrophone.tsx
71 lines (67 loc) · 2.81 KB
/
Microphone.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { _isInLobbyOrConnecting } from '@internal/calling-component-bindings';
import { ControlBarButtonStyles, MicrophoneButton } from '@internal/react-components';
import { _HighContrastAwareIcon } from '@internal/react-components';
import React, { useMemo } from 'react';
import { CallControlDisplayType } from '../../../common/types/CommonCallControlOptions';
import { usePropsFor } from '../../hooks/usePropsFor';
import { useSelector } from '../../hooks/useSelector';
import {
getCallStatus,
getCapabilites,
getIsRoomsCall,
getLocalMicrophoneEnabled,
getRole
} from '../../selectors/baseSelectors';
import { concatButtonBaseStyles } from '../../styles/Buttons.styles';
/**
* @private
*/
export const Microphone = (props: {
displayType?: CallControlDisplayType;
styles?: ControlBarButtonStyles;
splitButtonsForDeviceSelection?: boolean;
disabled?: boolean;
disableTooltip?: boolean;
isDeepNoiseSuppressionOn?: boolean;
onClickNoiseSuppression?: () => void;
showNoiseSuppressionButton?: boolean;
}): JSX.Element => {
const microphoneButtonProps = usePropsFor(MicrophoneButton);
const callStatus = useSelector(getCallStatus);
const isLocalMicrophoneEnabled = useSelector(getLocalMicrophoneEnabled);
const isRoomsCall = useSelector(getIsRoomsCall);
const role = useSelector(getRole);
const unmuteMicCapability = useSelector(getCapabilites)?.unmuteMic;
/**
* When call is in connecting state, microphone button should be disabled.
* This is due to to headless limitation where a call can not be muted/unmuted in lobby.
*/
if (callStatus === 'Connecting') {
// Lobby page should show the microphone status that was set on the local preview/configuration
// page until the user successfully joins the call.
microphoneButtonProps.checked = isLocalMicrophoneEnabled;
}
const styles = useMemo(() => concatButtonBaseStyles(props.styles ?? {}), [props.styles]);
// tab focus on MicrophoneButton on page load
return (
<MicrophoneButton
data-ui-id="call-composite-microphone-button"
{...microphoneButtonProps}
isDeepNoiseSuppressionOn={props.isDeepNoiseSuppressionOn}
onClickNoiseSuppression={props.onClickNoiseSuppression}
showNoiseSuppressionButton={props.showNoiseSuppressionButton}
showLabel={props.displayType !== 'compact'}
disableTooltip={props.disableTooltip}
styles={styles}
enableDeviceSelectionMenu={props.splitButtonsForDeviceSelection}
disabled={microphoneButtonProps.disabled || props.disabled || !!(isRoomsCall && role === 'Unknown')}
onRenderOffIcon={
unmuteMicCapability?.isPresent === false
? () => <_HighContrastAwareIcon disabled={true} iconName={'ControlButtonMicProhibited'} />
: undefined
}
/>
);
};