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.js 4.3KB

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