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.

RemoteVideoMenu.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Text, View } from 'react-native';
  4. import { Avatar } from '../../../base/avatar';
  5. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  6. import { BottomSheet, isDialogOpen } from '../../../base/dialog';
  7. import { getParticipantDisplayName } from '../../../base/participants';
  8. import { connect } from '../../../base/redux';
  9. import { StyleType } from '../../../base/styles';
  10. import { PrivateMessageButton } from '../../../chat';
  11. import { hideRemoteVideoMenu } from '../../actions';
  12. import GrantModeratorButton from './GrantModeratorButton';
  13. import KickButton from './KickButton';
  14. import MuteButton from './MuteButton';
  15. import PinButton from './PinButton';
  16. import styles from './styles';
  17. /**
  18. * Size of the rendered avatar in the menu.
  19. */
  20. const AVATAR_SIZE = 25;
  21. type Props = {
  22. /**
  23. * The Redux dispatch function.
  24. */
  25. dispatch: Function,
  26. /**
  27. * The participant for which this menu opened for.
  28. */
  29. participant: Object,
  30. /**
  31. * The color-schemed stylesheet of the BottomSheet.
  32. */
  33. _bottomSheetStyles: StyleType,
  34. /**
  35. * Whether or not to display the kick button.
  36. */
  37. _disableKick: boolean,
  38. /**
  39. * Whether or not to display the remote mute buttons.
  40. */
  41. _disableRemoteMute: boolean,
  42. /**
  43. * True if the menu is currently open, false otherwise.
  44. */
  45. _isOpen: boolean,
  46. /**
  47. * Display name of the participant retreived from Redux.
  48. */
  49. _participantDisplayName: string
  50. }
  51. // eslint-disable-next-line prefer-const
  52. let RemoteVideoMenu_;
  53. /**
  54. * Class to implement a popup menu that opens upon long pressing a thumbnail.
  55. */
  56. class RemoteVideoMenu extends Component<Props> {
  57. /**
  58. * Constructor of the component.
  59. *
  60. * @inheritdoc
  61. */
  62. constructor(props: Props) {
  63. super(props);
  64. this._onCancel = this._onCancel.bind(this);
  65. }
  66. /**
  67. * Implements {@code Component#render}.
  68. *
  69. * @inheritdoc
  70. */
  71. render() {
  72. const { _disableKick, _disableRemoteMute, participant } = this.props;
  73. const buttonProps = {
  74. afterClick: this._onCancel,
  75. showLabel: true,
  76. participantID: participant.id,
  77. styles: this.props._bottomSheetStyles.buttons
  78. };
  79. const buttons = [];
  80. if (!_disableRemoteMute) {
  81. buttons.push(<MuteButton { ...buttonProps } />);
  82. }
  83. buttons.push(<GrantModeratorButton { ...buttonProps } />);
  84. if (!_disableKick) {
  85. buttons.push(<KickButton { ...buttonProps } />);
  86. }
  87. buttons.push(<PinButton { ...buttonProps } />);
  88. buttons.push(<PrivateMessageButton { ...buttonProps } />);
  89. return (
  90. <BottomSheet onCancel = { this._onCancel }>
  91. <View style = { styles.participantNameContainer }>
  92. <Avatar
  93. participantId = { participant.id }
  94. size = { AVATAR_SIZE } />
  95. <Text style = { styles.participantNameLabel }>
  96. { this.props._participantDisplayName }
  97. </Text>
  98. </View>
  99. { buttons }
  100. </BottomSheet>
  101. );
  102. }
  103. _onCancel: () => boolean;
  104. /**
  105. * Callback to hide the {@code RemoteVideoMenu}.
  106. *
  107. * @private
  108. * @returns {boolean}
  109. */
  110. _onCancel() {
  111. if (this.props._isOpen) {
  112. this.props.dispatch(hideRemoteVideoMenu());
  113. return true;
  114. }
  115. return false;
  116. }
  117. }
  118. /**
  119. * Function that maps parts of Redux state tree into component props.
  120. *
  121. * @param {Object} state - Redux state.
  122. * @param {Object} ownProps - Properties of component.
  123. * @private
  124. * @returns {Props}
  125. */
  126. function _mapStateToProps(state, ownProps) {
  127. const { participant } = ownProps;
  128. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  129. const { disableKick } = remoteVideoMenu;
  130. return {
  131. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  132. _disableKick: Boolean(disableKick),
  133. _disableRemoteMute: Boolean(disableRemoteMute),
  134. _isOpen: isDialogOpen(state, RemoteVideoMenu_),
  135. _participantDisplayName: getParticipantDisplayName(state, participant.id)
  136. };
  137. }
  138. RemoteVideoMenu_ = connect(_mapStateToProps)(RemoteVideoMenu);
  139. export default RemoteVideoMenu_;