Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

VideoSettingsButton.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { isMobileBrowser } from '../../../base/environment/utils';
  4. import { translate } from '../../../base/i18n';
  5. import { IconArrowUp } from '../../../base/icons';
  6. import { connect } from '../../../base/redux';
  7. import { ToolboxButtonWithIcon } from '../../../base/toolbox/components';
  8. import { getLocalJitsiVideoTrack } from '../../../base/tracks';
  9. import { VideoSettingsPopup, toggleVideoSettings } from '../../../settings';
  10. import { getVideoSettingsVisibility } from '../../../settings/functions';
  11. import { isVideoSettingsButtonDisabled } from '../../functions';
  12. import VideoMuteButton from '../VideoMuteButton';
  13. type Props = {
  14. /**
  15. * The button's key.
  16. */
  17. buttonKey?: string,
  18. /**
  19. * External handler for click action.
  20. */
  21. handleClick: Function,
  22. /**
  23. * Click handler for the small icon. Opens video options.
  24. */
  25. onVideoOptionsClick: Function,
  26. /**
  27. * Indicates whether video permissions have been granted or denied.
  28. */
  29. hasPermissions: boolean,
  30. /**
  31. * Whether there is a video track or not.
  32. */
  33. hasVideoTrack: boolean,
  34. /**
  35. * If the button should be disabled.
  36. */
  37. isDisabled: boolean,
  38. /**
  39. * Notify mode for `toolbarButtonClicked` event -
  40. * whether to only notify or to also prevent button click routine.
  41. */
  42. notifyMode?: string,
  43. /**
  44. * Flag controlling the visibility of the button.
  45. * VideoSettings popup is currently disabled on mobile browsers
  46. * as mobile devices do not support capture of more than one
  47. * camera at a time.
  48. */
  49. visible: boolean,
  50. /**
  51. * Used for translation.
  52. */
  53. t: Function,
  54. /**
  55. * Defines is popup is open.
  56. */
  57. isOpen: boolean
  58. };
  59. /**
  60. * Button used for video & video settings.
  61. *
  62. * @returns {ReactElement}
  63. */
  64. class VideoSettingsButton extends Component<Props> {
  65. /**
  66. * Initializes a new {@code VideoSettingsButton} instance.
  67. *
  68. * @inheritdoc
  69. */
  70. constructor(props: Props) {
  71. super(props);
  72. this._onEscClick = this._onEscClick.bind(this);
  73. this._onClick = this._onClick.bind(this);
  74. }
  75. /**
  76. * Returns true if the settings icon is disabled.
  77. *
  78. * @returns {boolean}
  79. */
  80. _isIconDisabled() {
  81. const { hasPermissions, hasVideoTrack, isDisabled } = this.props;
  82. return (!hasPermissions || isDisabled) && !hasVideoTrack;
  83. }
  84. _onEscClick: (KeyboardEvent) => void;
  85. /**
  86. * Click handler for the more actions entries.
  87. *
  88. * @param {KeyboardEvent} event - Esc key click to close the popup.
  89. * @returns {void}
  90. */
  91. _onEscClick(event) {
  92. if (event.key === 'Escape' && this.props.isOpen) {
  93. event.preventDefault();
  94. event.stopPropagation();
  95. this._onClick();
  96. }
  97. }
  98. _onClick: () => void;
  99. /**
  100. * Click handler for the more actions entries.
  101. *
  102. * @returns {void}
  103. */
  104. _onClick() {
  105. const { onVideoOptionsClick } = this.props;
  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) {
  147. const { permissions = {} } = 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: 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));