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.

FlipLocalVideoButton.tsx 3.2KB

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