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.

HideSelfViewVideoButton.tsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React, { PureComponent } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { IReduxState, IStore } from '../../../app/types';
  5. import { translate } from '../../../base/i18n/functions';
  6. import { updateSettings } from '../../../base/settings/actions';
  7. import { getHideSelfView } from '../../../base/settings/functions';
  8. import ContextMenuItem from '../../../base/ui/components/web/ContextMenuItem';
  9. import { NOTIFY_CLICK_MODE } from '../../../toolbox/constants';
  10. /**
  11. * The type of the React {@code Component} props of {@link HideSelfViewVideoButton}.
  12. */
  13. interface IProps extends WithTranslation {
  14. /**
  15. * Button text class name.
  16. */
  17. className: string;
  18. /**
  19. * Whether or not to hide the self view.
  20. */
  21. disableSelfView: boolean;
  22. /**
  23. * The redux dispatch function.
  24. */
  25. dispatch: IStore['dispatch'];
  26. /**
  27. * Callback to execute when the button is clicked.
  28. */
  29. notifyClick?: Function;
  30. /**
  31. * Notify mode for `participantMenuButtonClicked` event -
  32. * whether to only notify or to also prevent button click routine.
  33. */
  34. notifyMode?: string;
  35. /**
  36. * Click handler executed aside from the main action.
  37. */
  38. onClick?: Function;
  39. }
  40. /**
  41. * Implements a React {@link Component} which displays a button for hiding the local video.
  42. *
  43. * @augments Component
  44. */
  45. class HideSelfViewVideoButton extends PureComponent<IProps> {
  46. /**
  47. * Initializes a new {@code HideSelfViewVideoButton} instance.
  48. *
  49. * @param {Object} props - The read-only React Component props with which
  50. * the new instance is to be initialized.
  51. */
  52. constructor(props: IProps) {
  53. super(props);
  54. // Bind event handlers so they are only bound once for every instance.
  55. this._onClick = this._onClick.bind(this);
  56. }
  57. /**
  58. * Implements React's {@link Component#render()}.
  59. *
  60. * @inheritdoc
  61. * @returns {null|ReactElement}
  62. */
  63. render() {
  64. const {
  65. className,
  66. t
  67. } = this.props;
  68. return (
  69. <ContextMenuItem
  70. accessibilityLabel = { t('videothumbnail.hideSelfView') }
  71. className = 'hideselflink'
  72. id = 'hideselfviewButton'
  73. onClick = { this._onClick }
  74. text = { t('videothumbnail.hideSelfView') }
  75. textClassName = { className } />
  76. );
  77. }
  78. /**
  79. * Hides the local video.
  80. *
  81. * @private
  82. * @returns {void}
  83. */
  84. _onClick() {
  85. const { disableSelfView, dispatch, notifyClick, notifyMode, onClick } = this.props;
  86. notifyClick?.();
  87. if (notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY) {
  88. return;
  89. }
  90. onClick?.();
  91. dispatch(updateSettings({
  92. disableSelfView: !disableSelfView
  93. }));
  94. }
  95. }
  96. /**
  97. * Maps (parts of) the Redux state to the associated {@code FlipLocalVideoButton}'s props.
  98. *
  99. * @param {Object} state - The Redux state.
  100. * @private
  101. * @returns {IProps}
  102. */
  103. function _mapStateToProps(state: IReduxState) {
  104. return {
  105. disableSelfView: Boolean(getHideSelfView(state))
  106. };
  107. }
  108. export default translate(connect(_mapStateToProps)(HideSelfViewVideoButton));