您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RemoteVideoMenu.js 4.9KB

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