2022-07-11 12:30:37 +00:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2022-05-06 10:14:10 +00:00
|
|
|
import { View, TouchableOpacity } from 'react-native';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-05-06 10:14:10 +00:00
|
|
|
import {
|
|
|
|
createShortcutEvent,
|
|
|
|
sendAnalytics,
|
|
|
|
ACTION_SHORTCUT_PRESSED as PRESSED,
|
|
|
|
ACTION_SHORTCUT_RELEASED as RELEASED
|
|
|
|
} from '../../../../analytics';
|
|
|
|
import { getFeatureFlag, AUDIO_MUTE_BUTTON_ENABLED } from '../../../../base/flags';
|
|
|
|
import { Icon, IconMicrophone, IconMicrophoneEmptySlash } from '../../../../base/icons';
|
|
|
|
import { MEDIA_TYPE } from '../../../../base/media';
|
|
|
|
import { isLocalTrackMuted } from '../../../../base/tracks';
|
|
|
|
import { isAudioMuteButtonDisabled } from '../../../../toolbox/functions.any';
|
|
|
|
import { muteLocal } from '../../../../video-menu/actions';
|
|
|
|
|
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
const LONG_PRESS = 'long.press';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a round audio mute/unmute button of a custom size.
|
|
|
|
*
|
|
|
|
* @returns {JSX.Element} - The audio mute round button.
|
|
|
|
*/
|
|
|
|
const MicrophoneButton = () : JSX.Element => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const audioMuted = useSelector(state => isLocalTrackMuted(state['features/base/tracks'], MEDIA_TYPE.AUDIO));
|
|
|
|
const disabled = useSelector(isAudioMuteButtonDisabled);
|
|
|
|
const enabledFlag = useSelector(state => getFeatureFlag(state, AUDIO_MUTE_BUTTON_ENABLED, true));
|
|
|
|
const [ longPress, setLongPress ] = useState(false);
|
|
|
|
|
|
|
|
if (!enabledFlag) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const onPressIn = useCallback(() => {
|
|
|
|
!disabled && dispatch(muteLocal(!audioMuted, MEDIA_TYPE.AUDIO));
|
|
|
|
}, [ audioMuted, disabled ]);
|
|
|
|
|
|
|
|
const onLongPress = useCallback(() => {
|
2022-07-11 12:30:37 +00:00
|
|
|
if (!disabled && !audioMuted) {
|
2022-05-06 10:14:10 +00:00
|
|
|
sendAnalytics(createShortcutEvent(
|
|
|
|
'push.to.talk',
|
|
|
|
PRESSED,
|
|
|
|
{},
|
|
|
|
LONG_PRESS));
|
|
|
|
setLongPress(true);
|
|
|
|
}
|
2022-07-11 12:30:37 +00:00
|
|
|
}, [ audioMuted, disabled, setLongPress ]);
|
2022-05-06 10:14:10 +00:00
|
|
|
|
|
|
|
const onPressOut = useCallback(() => {
|
|
|
|
if (longPress) {
|
|
|
|
setLongPress(false);
|
|
|
|
sendAnalytics(createShortcutEvent(
|
|
|
|
'push.to.talk',
|
|
|
|
RELEASED,
|
|
|
|
{},
|
|
|
|
LONG_PRESS
|
|
|
|
));
|
|
|
|
dispatch(muteLocal(true, MEDIA_TYPE.AUDIO));
|
|
|
|
}
|
2022-07-11 12:30:37 +00:00
|
|
|
}, [ longPress, setLongPress ]);
|
2022-05-06 10:14:10 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
2022-07-11 12:30:37 +00:00
|
|
|
onLongPress = { onLongPress }
|
2022-05-06 10:14:10 +00:00
|
|
|
onPressIn = { onPressIn }
|
2022-07-11 12:30:37 +00:00
|
|
|
onPressOut = { onPressOut } >
|
2022-05-06 10:14:10 +00:00
|
|
|
<View
|
|
|
|
style = { [
|
|
|
|
styles.microphoneStyles.container,
|
|
|
|
!audioMuted && styles.microphoneStyles.unmuted
|
|
|
|
] }>
|
|
|
|
<View
|
|
|
|
style = { styles.microphoneStyles.iconContainer }>
|
|
|
|
<Icon
|
|
|
|
src = { audioMuted ? IconMicrophoneEmptySlash : IconMicrophone }
|
|
|
|
style = { styles.microphoneStyles.icon } />
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MicrophoneButton;
|