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.

AbstractVideoMuteButton.tsx 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { IReduxState } from '../../app/types';
  2. import { VIDEO_MUTE_BUTTON_ENABLED } from '../../base/flags/constants';
  3. import { getFeatureFlag } from '../../base/flags/functions';
  4. import { MEDIA_TYPE } from '../../base/media/constants';
  5. import { IProps as AbstractButtonProps } from '../../base/toolbox/components/AbstractButton';
  6. import BaseVideoMuteButton from '../../base/toolbox/components/BaseVideoMuteButton';
  7. import { isLocalTrackMuted } from '../../base/tracks/functions';
  8. import { handleToggleVideoMuted } from '../actions.any';
  9. import { isVideoMuteButtonDisabled } from '../functions';
  10. /**
  11. * The type of the React {@code Component} props of {@link AbstractVideoMuteButton}.
  12. */
  13. export interface IProps extends AbstractButtonProps {
  14. /**
  15. * Whether video button is disabled or not.
  16. */
  17. _videoDisabled: boolean;
  18. /**
  19. * Whether video is currently muted or not.
  20. */
  21. _videoMuted: boolean;
  22. }
  23. /**
  24. * Component that renders a toolbar button for toggling video mute.
  25. *
  26. * @augments BaseVideoMuteButton
  27. */
  28. export default class AbstractVideoMuteButton<P extends IProps> extends BaseVideoMuteButton<P> {
  29. accessibilityLabel = 'toolbar.accessibilityLabel.videomute';
  30. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.videounmute';
  31. label = 'toolbar.videomute';
  32. tooltip = 'toolbar.videomute';
  33. toggledTooltip = 'toolbar.videounmute';
  34. /**
  35. * Indicates if video is currently disabled or not.
  36. *
  37. * @override
  38. * @protected
  39. * @returns {boolean}
  40. */
  41. _isDisabled() {
  42. return this.props._videoDisabled;
  43. }
  44. /**
  45. * Indicates if video is currently muted or not.
  46. *
  47. * @override
  48. * @protected
  49. * @returns {boolean}
  50. */
  51. _isVideoMuted() {
  52. return this.props._videoMuted;
  53. }
  54. /**
  55. * Changes the muted state.
  56. *
  57. * @override
  58. * @param {boolean} videoMuted - Whether video should be muted or not.
  59. * @protected
  60. * @returns {void}
  61. */
  62. _setVideoMuted(videoMuted: boolean) {
  63. this.props.dispatch(handleToggleVideoMuted(videoMuted, true, true));
  64. }
  65. }
  66. /**
  67. * Maps (parts of) the redux state to the associated props for the
  68. * {@code VideoMuteButton} component.
  69. *
  70. * @param {Object} state - The Redux state.
  71. * @private
  72. * @returns {{
  73. * _videoMuted: boolean
  74. * }}
  75. */
  76. export function mapStateToProps(state: IReduxState) {
  77. const tracks = state['features/base/tracks'];
  78. const enabledFlag = getFeatureFlag(state, VIDEO_MUTE_BUTTON_ENABLED, true);
  79. return {
  80. _videoDisabled: isVideoMuteButtonDisabled(state),
  81. _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO),
  82. visible: enabledFlag
  83. };
  84. }