Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

VideoSettingsButton.tsx 5.7KB

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