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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { toggleAudioOnly } from '../../base/conference';
  4. import ToolbarButton from './ToolbarButton';
  5. /**
  6. * React {@code Component} for toggling audio only mode.
  7. *
  8. * @extends Component
  9. */
  10. class AudioOnlyButton extends Component {
  11. /**
  12. * {@code AudioOnlyButton}'s property types.
  13. *
  14. * @static
  15. */
  16. static propTypes = {
  17. /**
  18. * Whether or not audio only mode is enabled.
  19. */
  20. _audioOnly: React.PropTypes.bool,
  21. /**
  22. * Invoked to toggle audio only mode.
  23. */
  24. dispatch: React.PropTypes.func,
  25. /**
  26. * From which side the button tooltip should appear.
  27. */
  28. tooltipPosition: React.PropTypes.string
  29. }
  30. /**
  31. * Initializes a new {@code AudioOnlyButton} instance.
  32. *
  33. * @param {Object} props - The read-only properties with which the new
  34. * instance is to be initialized.
  35. */
  36. constructor(props) {
  37. super(props);
  38. // Bind event handlers so they are only bound once for every instance.
  39. this._onClick = this._onClick.bind(this);
  40. }
  41. /**
  42. * Implements React's {@link Component#render()}.
  43. *
  44. * @inheritdoc
  45. * @returns {ReactElement}
  46. */
  47. render() {
  48. const buttonConfiguration = {
  49. buttonName: 'audioonly',
  50. classNames: [ 'button', 'icon-visibility' ],
  51. enabled: true,
  52. id: 'toolbar_button_audioonly',
  53. tooltipKey: 'toolbar.audioonly'
  54. };
  55. if (this.props._audioOnly) {
  56. buttonConfiguration.classNames.push('toggled button-active');
  57. }
  58. return (
  59. <ToolbarButton
  60. button = { buttonConfiguration }
  61. onClick = { this._onClick }
  62. tooltipPosition = { this.props.tooltipPosition } />
  63. );
  64. }
  65. /**
  66. * Dispatches an action to toggle audio only mode.
  67. *
  68. * @private
  69. * @returns {void}
  70. */
  71. _onClick() {
  72. this.props.dispatch(toggleAudioOnly());
  73. }
  74. }
  75. /**
  76. * Maps (parts of) the Redux state to the associated {@code AudioOnlyButton}'s
  77. * props.
  78. *
  79. * @param {Object} state - The Redux state.
  80. * @private
  81. * @returns {{
  82. * _audioOnly: boolean
  83. * }}
  84. */
  85. function _mapStateToProps(state) {
  86. return {
  87. _audioOnly: state['features/base/conference'].audioOnly
  88. };
  89. }
  90. export default connect(_mapStateToProps)(AudioOnlyButton);