您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AudioOnlyButton.ts 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { connect } from 'react-redux';
  2. import { IReduxState } from '../../../app/types';
  3. import { setAudioOnly, toggleAudioOnly } from '../../../base/audio-only/actions';
  4. import { AUDIO_ONLY_BUTTON_ENABLED } from '../../../base/flags/constants';
  5. import { getFeatureFlag } from '../../../base/flags/functions';
  6. import { translate } from '../../../base/i18n/functions';
  7. import { IconAudioOnly, IconAudioOnlyOff } from '../../../base/icons/svg';
  8. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  9. import {
  10. navigate
  11. } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  12. import { screen } from '../../../mobile/navigation/routes';
  13. /**
  14. * The type of the React {@code Component} props of {@link AudioOnlyButton}.
  15. */
  16. interface IProps extends AbstractButtonProps {
  17. /**
  18. * Whether the current conference is in audio only mode or not.
  19. */
  20. _audioOnly: boolean;
  21. /**
  22. * Indicates whether the car mode is enabled.
  23. */
  24. _startCarMode?: boolean;
  25. }
  26. /**
  27. * An implementation of a button for toggling the audio-only mode.
  28. */
  29. class AudioOnlyButton extends AbstractButton<IProps> {
  30. accessibilityLabel = 'toolbar.accessibilityLabel.audioOnly';
  31. icon = IconAudioOnly;
  32. label = 'toolbar.audioOnlyOn';
  33. toggledIcon = IconAudioOnlyOff;
  34. toggledLabel = 'toolbar.audioOnlyOff';
  35. /**
  36. * Handles clicking / pressing the button.
  37. *
  38. * @override
  39. * @protected
  40. * @returns {void}
  41. */
  42. _handleClick() {
  43. const { _audioOnly, _startCarMode, dispatch } = this.props;
  44. if (!_audioOnly && _startCarMode) {
  45. dispatch(setAudioOnly(true));
  46. navigate(screen.conference.carmode);
  47. } else {
  48. dispatch(toggleAudioOnly());
  49. }
  50. }
  51. /**
  52. * Indicates whether this button is in toggled state or not.
  53. *
  54. * @override
  55. * @protected
  56. * @returns {boolean}
  57. */
  58. _isToggled() {
  59. return this.props._audioOnly;
  60. }
  61. }
  62. /**
  63. * Maps (parts of) the redux state to the associated props for the
  64. * {@code AudioOnlyButton} component.
  65. *
  66. * @param {Object} state - The Redux state.
  67. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  68. * @private
  69. * @returns {{
  70. * _audioOnly: boolean
  71. * }}
  72. */
  73. function _mapStateToProps(state: IReduxState, ownProps: any) {
  74. const { enabled: audioOnly } = state['features/base/audio-only'];
  75. const enabledInFeatureFlags = getFeatureFlag(state, AUDIO_ONLY_BUTTON_ENABLED, true);
  76. const { startCarMode } = state['features/base/settings'];
  77. const { visible = enabledInFeatureFlags } = ownProps;
  78. return {
  79. _audioOnly: Boolean(audioOnly),
  80. _startCarMode: startCarMode,
  81. visible
  82. };
  83. }
  84. export default translate(connect(_mapStateToProps)(AudioOnlyButton));