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 5.1KB

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