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.

VideoSettingsButton.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { isMobileBrowser } from '../../../base/environment/utils';
  4. import { IconArrowDown } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import { ToolboxButtonWithIcon } from '../../../base/toolbox/components';
  7. import { getLocalJitsiVideoTrack } from '../../../base/tracks';
  8. import { toggleVideoSettings, VideoSettingsPopup } from '../../../settings';
  9. import { isVideoSettingsButtonDisabled } from '../../functions';
  10. import VideoMuteButton from '../VideoMuteButton';
  11. type Props = {
  12. /**
  13. * Click handler for the small icon. Opens video options.
  14. */
  15. onVideoOptionsClick: Function,
  16. /**
  17. * Indicates whether video permissions have been granted or denied.
  18. */
  19. hasPermissions: boolean,
  20. /**
  21. * Whether there is a video track or not.
  22. */
  23. hasVideoTrack: boolean,
  24. /**
  25. * If the button should be disabled
  26. */
  27. isDisabled: boolean,
  28. /**
  29. * Flag controlling the visibility of the button.
  30. * VideoSettings popup is currently disabled on mobile browsers
  31. * as mobile devices do not support capture of more than one
  32. * camera at a time.
  33. */
  34. visible: boolean
  35. };
  36. /**
  37. * Button used for video & video settings.
  38. *
  39. * @returns {ReactElement}
  40. */
  41. class VideoSettingsButton extends Component<Props> {
  42. /**
  43. * Returns true if the settings icon is disabled.
  44. *
  45. * @returns {boolean}
  46. */
  47. _isIconDisabled() {
  48. const { hasPermissions, hasVideoTrack, isDisabled } = this.props;
  49. return (!hasPermissions || isDisabled) && !hasVideoTrack;
  50. }
  51. /**
  52. * Implements React's {@link Component#render}.
  53. *
  54. * @inheritdoc
  55. */
  56. render() {
  57. const { onVideoOptionsClick, visible } = this.props;
  58. return visible ? (
  59. <VideoSettingsPopup>
  60. <ToolboxButtonWithIcon
  61. icon = { IconArrowDown }
  62. iconDisabled = { this._isIconDisabled() }
  63. onIconClick = { onVideoOptionsClick }>
  64. <VideoMuteButton />
  65. </ToolboxButtonWithIcon>
  66. </VideoSettingsPopup>
  67. ) : <VideoMuteButton />;
  68. }
  69. }
  70. /**
  71. * Function that maps parts of Redux state tree into component props.
  72. *
  73. * @param {Object} state - Redux state.
  74. * @returns {Object}
  75. */
  76. function mapStateToProps(state) {
  77. const { permissions = {} } = state['features/base/devices'];
  78. return {
  79. hasPermissions: permissions.video,
  80. hasVideoTrack: Boolean(getLocalJitsiVideoTrack(state)),
  81. isDisabled: isVideoSettingsButtonDisabled(state),
  82. visible: !isMobileBrowser()
  83. };
  84. }
  85. const mapDispatchToProps = {
  86. onVideoOptionsClick: toggleVideoSettings
  87. };
  88. export default connect(
  89. mapStateToProps,
  90. mapDispatchToProps,
  91. )(VideoSettingsButton);