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.

VideoMuteButton.web.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // @flow
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import { connect } from 'react-redux';
  5. import UIEvents from '../../../../../service/UI/UIEvents';
  6. import {
  7. ACTION_SHORTCUT_TRIGGERED,
  8. VIDEO_MUTE,
  9. createShortcutEvent,
  10. sendAnalytics
  11. } from '../../../analytics';
  12. import { translate } from '../../../base/i18n';
  13. import { MEDIA_TYPE } from '../../../base/media';
  14. import { isLocalTrackMuted } from '../../../base/tracks';
  15. import AbstractVideoMuteButton from './AbstractVideoMuteButton';
  16. import ToolbarButtonV2 from '../ToolbarButtonV2';
  17. declare var APP: Object;
  18. /**
  19. * Component that renders a toolbar button for toggling video mute.
  20. *
  21. * @extends AbstractVideoMuteButton
  22. */
  23. export class VideoMuteButton extends AbstractVideoMuteButton {
  24. /**
  25. * Default values for {@code VideoMuteButton} component's properties.
  26. *
  27. * @static
  28. */
  29. static defaultProps = {
  30. tooltipPosition: 'top'
  31. };
  32. /**
  33. * {@code VideoMuteButton} component's property types.
  34. *
  35. * @static
  36. */
  37. static propTypes = {
  38. ...AbstractVideoMuteButton.propTypes,
  39. /**
  40. * The {@code JitsiConference} for the current conference.
  41. */
  42. _conference: PropTypes.object,
  43. /**
  44. * Invoked to obtain translated strings.
  45. */
  46. t: PropTypes.func,
  47. /**
  48. * Where the tooltip should display, relative to the button.
  49. */
  50. tooltipPosition: PropTypes.string
  51. };
  52. /**
  53. * Initializes a new {@code VideoMuteButton} instance.
  54. *
  55. * @param {Props} props - The read-only React {@code Component} props with
  56. * which the new instance is to be initialized.
  57. */
  58. constructor(props: Object) {
  59. super(props);
  60. // Bind event handlers so they are only bound once per instance.
  61. this._onShortcutToggleVideo = this._onShortcutToggleVideo.bind(this);
  62. }
  63. /**
  64. * Sets a keyboard shortcuts for toggling video mute.
  65. *
  66. * @inheritdoc
  67. * @returns {void}
  68. */
  69. componentDidMount() {
  70. APP.keyboardshortcut.registerShortcut(
  71. 'V',
  72. null,
  73. this._onShortcutToggleVideo,
  74. 'keyboardShortcuts.videoMute');
  75. }
  76. /**
  77. * Removes the registered keyboard shortcut handler.
  78. *
  79. * @inheritdoc
  80. * @returns {void}
  81. */
  82. componentWillUnmount() {
  83. APP.keyboardshortcut.unregisterShortcut('V');
  84. }
  85. /**
  86. * Implements React's {@link Component#render()}.
  87. *
  88. * @inheritdoc
  89. * @returns {ReactElement}
  90. */
  91. render() {
  92. const { _conference, _videoMuted, t, tooltipPosition } = this.props;
  93. return (
  94. <ToolbarButtonV2
  95. iconName = { _videoMuted && _conference
  96. ? 'icon-camera-disabled toggled'
  97. : 'icon-camera' }
  98. onClick = { this._onToolbarToggleVideo }
  99. tooltip = { t('toolbar.videomute') }
  100. tooltipPosition = { tooltipPosition } />
  101. );
  102. }
  103. _doToggleVideo: () => void;
  104. /**
  105. * Emits an event to signal video mute should be toggled.
  106. *
  107. * @private
  108. * @returns {void}
  109. */
  110. _doToggleVideo() {
  111. APP.UI.emitEvent(UIEvents.VIDEO_MUTED, !this.props._videoMuted);
  112. }
  113. _onShortcutToggleVideo: () => void;
  114. /**
  115. * Creates an analytics keyboard shortcut event for and dispatches an action
  116. * for toggling video mute.
  117. *
  118. * @private
  119. * @returns {void}
  120. */
  121. _onShortcutToggleVideo() {
  122. sendAnalytics(createShortcutEvent(
  123. VIDEO_MUTE,
  124. ACTION_SHORTCUT_TRIGGERED,
  125. { enable: !this.props._videoMuted }));
  126. this._doToggleVideo();
  127. }
  128. _onToolbarToggleVideo: () => void;
  129. }
  130. /**
  131. * Maps (parts of) the Redux state to the associated props for the
  132. * {@code AudioMuteButton} component.
  133. *
  134. * @param {Object} state - The Redux state.
  135. * @private
  136. * @returns {{
  137. * _conference: Object,
  138. * _videoMuted: boolean,
  139. * }}
  140. */
  141. function _mapStateToProps(state) {
  142. const tracks = state['features/base/tracks'];
  143. return {
  144. _conference: state['features/base/conference'].conference,
  145. _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO)
  146. };
  147. }
  148. export default translate(connect(_mapStateToProps)(VideoMuteButton));