Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RemoteVideoMenu.js 5.0KB

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