2022-07-18 13:16:08 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2022-07-11 12:30:37 +00:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { TouchableOpacity, View } from 'react-native';
|
2022-05-06 10:14:10 +00:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-05-06 10:14:10 +00:00
|
|
|
import {
|
|
|
|
ACTION_SHORTCUT_PRESSED as PRESSED,
|
2022-09-27 07:10:28 +00:00
|
|
|
ACTION_SHORTCUT_RELEASED as RELEASED,
|
|
|
|
createShortcutEvent
|
2022-09-07 08:20:05 +00:00
|
|
|
} from '../../../../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../../../../analytics/functions';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../../../app/types';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { AUDIO_MUTE_BUTTON_ENABLED } from '../../../../base/flags/constants';
|
|
|
|
import { getFeatureFlag } from '../../../../base/flags/functions';
|
2022-07-27 09:56:07 +00:00
|
|
|
import Icon from '../../../../base/icons/components/Icon';
|
2022-09-06 17:32:20 +00:00
|
|
|
import { IconMicrophone, IconMicrophoneEmptySlash } from '../../../../base/icons/svg';
|
2022-09-05 11:24:13 +00:00
|
|
|
import { MEDIA_TYPE } from '../../../../base/media/constants';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { isLocalTrackMuted } from '../../../../base/tracks/functions';
|
2022-05-06 10:14:10 +00:00
|
|
|
import { isAudioMuteButtonDisabled } from '../../../../toolbox/functions.any';
|
2022-07-18 13:16:08 +00:00
|
|
|
// @ts-ignore
|
2022-05-06 10:14:10 +00:00
|
|
|
import { muteLocal } from '../../../../video-menu/actions';
|
|
|
|
|
2022-07-18 13:16:08 +00:00
|
|
|
// @ts-ignore
|
2022-05-06 10:14:10 +00:00
|
|
|
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.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
const MicrophoneButton = (): JSX.Element | null => {
|
2022-05-06 10:14:10 +00:00
|
|
|
const dispatch = useDispatch();
|
2022-10-20 09:11:27 +00:00
|
|
|
const audioMuted = useSelector((state: IReduxState) => isLocalTrackMuted(state['features/base/tracks'],
|
2022-09-05 11:24:13 +00:00
|
|
|
MEDIA_TYPE.AUDIO));
|
2022-05-06 10:14:10 +00:00
|
|
|
const disabled = useSelector(isAudioMuteButtonDisabled);
|
2022-10-20 09:11:27 +00:00
|
|
|
const enabledFlag = useSelector((state: IReduxState) => getFeatureFlag(state, AUDIO_MUTE_BUTTON_ENABLED, true));
|
2022-05-06 10:14:10 +00:00
|
|
|
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;
|