Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VideoSettingsButton.tsx 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import React, { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { IReduxState } from '../../../app/types';
  5. import { isMobileBrowser } from '../../../base/environment/utils';
  6. import { translate } from '../../../base/i18n/functions';
  7. import { IconArrowUp } from '../../../base/icons/svg';
  8. import ToolboxButtonWithIcon from '../../../base/toolbox/components/web/ToolboxButtonWithIcon';
  9. import { getLocalJitsiVideoTrack } from '../../../base/tracks/functions.web';
  10. import { toggleVideoSettings } from '../../../settings/actions';
  11. import VideoSettingsPopup from '../../../settings/components/web/video/VideoSettingsPopup';
  12. import { getVideoSettingsVisibility } from '../../../settings/functions.web';
  13. import { isVideoSettingsButtonDisabled } from '../../functions.web';
  14. import VideoMuteButton from '../VideoMuteButton';
  15. interface IProps extends WithTranslation {
  16. /**
  17. * The button's key.
  18. */
  19. buttonKey?: string;
  20. /**
  21. * External handler for click action.
  22. */
  23. handleClick: Function;
  24. /**
  25. * Indicates whether video permissions have been granted or denied.
  26. */
  27. hasPermissions: boolean;
  28. /**
  29. * Whether there is a video track or not.
  30. */
  31. hasVideoTrack: boolean;
  32. /**
  33. * If the button should be disabled.
  34. */
  35. isDisabled: boolean;
  36. /**
  37. * Defines is popup is open.
  38. */
  39. isOpen: boolean;
  40. /**
  41. * Notify mode for `toolbarButtonClicked` event -
  42. * whether to only notify or to also prevent button click routine.
  43. */
  44. notifyMode?: string;
  45. /**
  46. * Click handler for the small icon. Opens video options.
  47. */
  48. onVideoOptionsClick: Function;
  49. /**
  50. * Flag controlling the visibility of the button.
  51. * VideoSettings popup is currently disabled on mobile browsers
  52. * as mobile devices do not support capture of more than one
  53. * camera at a time.
  54. */
  55. visible: boolean;
  56. }
  57. /**
  58. * Button used for video & video settings.
  59. *
  60. * @returns {ReactElement}
  61. */
  62. class VideoSettingsButton extends Component<IProps> {
  63. /**
  64. * Initializes a new {@code VideoSettingsButton} instance.
  65. *
  66. * @inheritdoc
  67. */
  68. constructor(props: IProps) {
  69. super(props);
  70. this._onEscClick = this._onEscClick.bind(this);
  71. this._onClick = this._onClick.bind(this);
  72. }
  73. /**
  74. * Returns true if the settings icon is disabled.
  75. *
  76. * @returns {boolean}
  77. */
  78. _isIconDisabled() {
  79. const { hasPermissions, hasVideoTrack, isDisabled } = this.props;
  80. return (!hasPermissions || isDisabled) && !hasVideoTrack;
  81. }
  82. /**
  83. * Click handler for the more actions entries.
  84. *
  85. * @param {KeyboardEvent} event - Esc key click to close the popup.
  86. * @returns {void}
  87. */
  88. _onEscClick(event: React.KeyboardEvent) {
  89. if (event.key === 'Escape' && this.props.isOpen) {
  90. event.preventDefault();
  91. event.stopPropagation();
  92. this._onClick();
  93. }
  94. }
  95. /**
  96. * Click handler for the more actions entries.
  97. *
  98. * @param {MouseEvent} e - Mousw event.
  99. * @returns {void}
  100. */
  101. _onClick(e?: React.MouseEvent) {
  102. const { onVideoOptionsClick, isOpen } = this.props;
  103. if (isOpen) {
  104. e?.stopPropagation();
  105. }
  106. onVideoOptionsClick();
  107. }
  108. /**
  109. * Implements React's {@link Component#render}.
  110. *
  111. * @inheritdoc
  112. */
  113. render() {
  114. const { t, visible, isOpen, buttonKey, notifyMode } = this.props;
  115. return visible ? (
  116. <VideoSettingsPopup>
  117. <ToolboxButtonWithIcon
  118. ariaControls = 'video-settings-dialog'
  119. ariaExpanded = { isOpen }
  120. ariaHasPopup = { true }
  121. ariaLabel = { this.props.t('toolbar.videoSettings') }
  122. buttonKey = { buttonKey }
  123. icon = { IconArrowUp }
  124. iconDisabled = { this._isIconDisabled() }
  125. iconId = 'video-settings-button'
  126. iconTooltip = { t('toolbar.videoSettings') }
  127. notifyMode = { notifyMode }
  128. onIconClick = { this._onClick }
  129. onIconKeyDown = { this._onEscClick }>
  130. <VideoMuteButton
  131. buttonKey = { buttonKey }
  132. notifyMode = { notifyMode } />
  133. </ToolboxButtonWithIcon>
  134. </VideoSettingsPopup>
  135. ) : <VideoMuteButton
  136. buttonKey = { buttonKey }
  137. notifyMode = { notifyMode } />;
  138. }
  139. }
  140. /**
  141. * Function that maps parts of Redux state tree into component props.
  142. *
  143. * @param {Object} state - Redux state.
  144. * @returns {Object}
  145. */
  146. function mapStateToProps(state: IReduxState) {
  147. const { permissions = { video: false } } = state['features/base/devices'];
  148. const { isNarrowLayout } = state['features/base/responsive-ui'];
  149. return {
  150. hasPermissions: permissions.video,
  151. hasVideoTrack: Boolean(getLocalJitsiVideoTrack(state)),
  152. isDisabled: isVideoSettingsButtonDisabled(state),
  153. isOpen: Boolean(getVideoSettingsVisibility(state)),
  154. visible: !isMobileBrowser() && !isNarrowLayout
  155. };
  156. }
  157. const mapDispatchToProps = {
  158. onVideoOptionsClick: toggleVideoSettings
  159. };
  160. export default translate(connect(
  161. mapStateToProps,
  162. mapDispatchToProps
  163. )(VideoSettingsButton));