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

VideoMuteButton.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // @flow
  2. import {
  3. ACTION_SHORTCUT_TRIGGERED,
  4. VIDEO_MUTE,
  5. createShortcutEvent,
  6. sendAnalytics
  7. } from '../../analytics';
  8. import { VIDEO_MUTE_BUTTON_ENABLED, getFeatureFlag } from '../../base/flags';
  9. import { translate } from '../../base/i18n';
  10. import { MEDIA_TYPE } from '../../base/media';
  11. import { connect } from '../../base/redux';
  12. import { AbstractButton, AbstractVideoMuteButton } from '../../base/toolbox/components';
  13. import type { AbstractButtonProps } from '../../base/toolbox/components';
  14. import { isLocalTrackMuted } from '../../base/tracks';
  15. import { handleToggleVideoMuted } from '../actions.any';
  16. import { isVideoMuteButtonDisabled } from '../functions';
  17. declare var APP: Object;
  18. /**
  19. * The type of the React {@code Component} props of {@link VideoMuteButton}.
  20. */
  21. type Props = AbstractButtonProps & {
  22. /**
  23. * Whether video is currently muted or not.
  24. */
  25. _videoMuted: boolean,
  26. /**
  27. * Whether video button is disabled or not.
  28. */
  29. _videoDisabled: boolean,
  30. /**
  31. * The redux {@code dispatch} function.
  32. */
  33. dispatch: Function
  34. }
  35. /**
  36. * Component that renders a toolbar button for toggling video mute.
  37. *
  38. * @augments AbstractVideoMuteButton
  39. */
  40. class VideoMuteButton extends AbstractVideoMuteButton<Props, *> {
  41. accessibilityLabel = 'toolbar.accessibilityLabel.videomute';
  42. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.videounmute';
  43. label = 'toolbar.videomute';
  44. tooltip = 'toolbar.videomute';
  45. toggledTooltip = 'toolbar.videounmute';
  46. /**
  47. * Initializes a new {@code VideoMuteButton} instance.
  48. *
  49. * @param {Props} props - The read-only React {@code Component} props with
  50. * which the new instance is to be initialized.
  51. */
  52. constructor(props: Props) {
  53. super(props);
  54. // Bind event handlers so they are only bound once per instance.
  55. this._onKeyboardShortcut = this._onKeyboardShortcut.bind(this);
  56. }
  57. /**
  58. * Registers the keyboard shortcut that toggles the video muting.
  59. *
  60. * @inheritdoc
  61. * @returns {void}
  62. */
  63. componentDidMount() {
  64. typeof APP === 'undefined'
  65. || APP.keyboardshortcut.registerShortcut(
  66. 'V',
  67. null,
  68. this._onKeyboardShortcut,
  69. 'keyboardShortcuts.videoMute');
  70. }
  71. /**
  72. * Unregisters the keyboard shortcut that toggles the video muting.
  73. *
  74. * @inheritdoc
  75. * @returns {void}
  76. */
  77. componentWillUnmount() {
  78. typeof APP === 'undefined'
  79. || APP.keyboardshortcut.unregisterShortcut('V');
  80. }
  81. /**
  82. * Indicates if video is currently disabled or not.
  83. *
  84. * @override
  85. * @protected
  86. * @returns {boolean}
  87. */
  88. _isDisabled() {
  89. return this.props._videoDisabled;
  90. }
  91. /**
  92. * Indicates if video is currently muted or not.
  93. *
  94. * @override
  95. * @protected
  96. * @returns {boolean}
  97. */
  98. _isVideoMuted() {
  99. return this.props._videoMuted;
  100. }
  101. _onKeyboardShortcut: () => void;
  102. /**
  103. * Creates an analytics keyboard shortcut event and dispatches an action to
  104. * toggle the video muting.
  105. *
  106. * @private
  107. * @returns {void}
  108. */
  109. _onKeyboardShortcut() {
  110. // Ignore keyboard shortcuts if the video button is disabled.
  111. if (this._isDisabled()) {
  112. return;
  113. }
  114. sendAnalytics(
  115. createShortcutEvent(
  116. VIDEO_MUTE,
  117. ACTION_SHORTCUT_TRIGGERED,
  118. { enable: !this._isVideoMuted() }));
  119. AbstractButton.prototype._onClick.call(this);
  120. }
  121. /**
  122. * Changes the muted state.
  123. *
  124. * @override
  125. * @param {boolean} videoMuted - Whether video should be muted or not.
  126. * @protected
  127. * @returns {void}
  128. */
  129. _setVideoMuted(videoMuted: boolean) {
  130. this.props.dispatch(handleToggleVideoMuted(videoMuted, true, true));
  131. }
  132. }
  133. /**
  134. * Maps (parts of) the redux state to the associated props for the
  135. * {@code VideoMuteButton} component.
  136. *
  137. * @param {Object} state - The Redux state.
  138. * @private
  139. * @returns {{
  140. * _videoMuted: boolean
  141. * }}
  142. */
  143. function _mapStateToProps(state): Object {
  144. const tracks = state['features/base/tracks'];
  145. const enabledFlag = getFeatureFlag(state, VIDEO_MUTE_BUTTON_ENABLED, true);
  146. return {
  147. _videoDisabled: isVideoMuteButtonDisabled(state),
  148. _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO),
  149. visible: enabledFlag
  150. };
  151. }
  152. export default translate(connect(_mapStateToProps)(VideoMuteButton));