Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

VideoMuteButton.ts 4.7KB

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