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

RemoteVideoMenu.js 6.3KB

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