You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AudioOnlyButton.js 2.8KB

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