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

AudioOnlyButton.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // @flow
  2. import { connect } from 'react-redux';
  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. type Props = 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. * The redux {@code dispatch} function.
  27. */
  28. dispatch: Function
  29. };
  30. /**
  31. * An implementation of a button for toggling the audio-only mode.
  32. */
  33. class AudioOnlyButton extends AbstractButton<Props, *> {
  34. accessibilityLabel = 'toolbar.accessibilityLabel.audioOnly';
  35. icon = IconAudioOnly;
  36. label = 'toolbar.audioOnlyOn';
  37. toggledIcon = IconAudioOnlyOff;
  38. toggledLabel = 'toolbar.audioOnlyOff';
  39. /**
  40. * Handles clicking / pressing the button.
  41. *
  42. * @override
  43. * @protected
  44. * @returns {void}
  45. */
  46. _handleClick() {
  47. const { _audioOnly, _startCarMode, dispatch } = this.props;
  48. if (!_audioOnly && _startCarMode) {
  49. dispatch(setAudioOnly(true));
  50. navigate(screen.conference.carmode);
  51. } else {
  52. dispatch(toggleAudioOnly());
  53. }
  54. }
  55. /**
  56. * Indicates whether this button is in toggled state or not.
  57. *
  58. * @override
  59. * @protected
  60. * @returns {boolean}
  61. */
  62. _isToggled() {
  63. return this.props._audioOnly;
  64. }
  65. }
  66. /**
  67. * Maps (parts of) the redux state to the associated props for the
  68. * {@code AudioOnlyButton} component.
  69. *
  70. * @param {Object} state - The Redux state.
  71. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  72. * @private
  73. * @returns {{
  74. * _audioOnly: boolean
  75. * }}
  76. */
  77. function _mapStateToProps(state, ownProps): Object {
  78. const { enabled: audioOnly } = state['features/base/audio-only'];
  79. const enabledInFeatureFlags = getFeatureFlag(state, AUDIO_ONLY_BUTTON_ENABLED, true);
  80. const { startCarMode } = state['features/base/settings'];
  81. const { visible = enabledInFeatureFlags } = ownProps;
  82. return {
  83. _audioOnly: Boolean(audioOnly),
  84. _startCarMode: startCarMode,
  85. visible
  86. };
  87. }
  88. export default translate(connect(_mapStateToProps)(AudioOnlyButton));