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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 ID of the participant for which this menu opened for.
  37. */
  38. participantId: String,
  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. // eslint-disable-next-line prefer-const
  69. let RemoteVideoMenu_;
  70. /**
  71. * Class to implement a popup menu that opens upon long pressing a thumbnail.
  72. */
  73. class RemoteVideoMenu extends PureComponent<Props> {
  74. /**
  75. * Constructor of the component.
  76. *
  77. * @inheritdoc
  78. */
  79. constructor(props: Props) {
  80. super(props);
  81. this._onCancel = this._onCancel.bind(this);
  82. this._renderMenuHeader = this._renderMenuHeader.bind(this);
  83. }
  84. /**
  85. * Implements {@code Component#render}.
  86. *
  87. * @inheritdoc
  88. */
  89. render() {
  90. const {
  91. _disableKick,
  92. _disableRemoteMute,
  93. _disableGrantModerator,
  94. _isParticipantAvailable,
  95. participantId
  96. } = this.props;
  97. const buttonProps = {
  98. afterClick: this._onCancel,
  99. showLabel: true,
  100. participantID: participantId,
  101. styles: this.props._bottomSheetStyles.buttons
  102. };
  103. return (
  104. <BottomSheet
  105. onCancel = { this._onCancel }
  106. renderHeader = { this._renderMenuHeader }
  107. showSlidingView = { _isParticipantAvailable }>
  108. { !_disableRemoteMute && <MuteButton { ...buttonProps } /> }
  109. <MuteEveryoneElseButton { ...buttonProps } />
  110. { !_disableRemoteMute && <MuteVideoButton { ...buttonProps } /> }
  111. <Divider style = { styles.divider } />
  112. { !_disableKick && <KickButton { ...buttonProps } /> }
  113. { !_disableGrantModerator && <GrantModeratorButton { ...buttonProps } /> }
  114. <PinButton { ...buttonProps } />
  115. <PrivateMessageButton { ...buttonProps } />
  116. <ConnectionStatusButton { ...buttonProps } />
  117. {/* <Divider style = { styles.divider } />*/}
  118. {/* <VolumeSlider participantID = { participantId } />*/}
  119. </BottomSheet>
  120. );
  121. }
  122. _onCancel: () => boolean;
  123. /**
  124. * Callback to hide the {@code RemoteVideoMenu}.
  125. *
  126. * @private
  127. * @returns {boolean}
  128. */
  129. _onCancel() {
  130. if (this.props._isOpen) {
  131. this.props.dispatch(hideRemoteVideoMenu());
  132. return true;
  133. }
  134. return false;
  135. }
  136. _renderMenuHeader: () => React$Element<any>;
  137. /**
  138. * Function to render the menu's header.
  139. *
  140. * @returns {React$Element}
  141. */
  142. _renderMenuHeader() {
  143. const { _bottomSheetStyles, participantId } = this.props;
  144. return (
  145. <View
  146. style = { [
  147. _bottomSheetStyles.sheet,
  148. styles.participantNameContainer ] }>
  149. <Avatar
  150. participantId = { participantId }
  151. size = { AVATAR_SIZE } />
  152. <Text style = { styles.participantNameLabel }>
  153. { this.props._participantDisplayName }
  154. </Text>
  155. </View>
  156. );
  157. }
  158. }
  159. /**
  160. * Function that maps parts of Redux state tree into component props.
  161. *
  162. * @param {Object} state - Redux state.
  163. * @param {Object} ownProps - Properties of component.
  164. * @private
  165. * @returns {Props}
  166. */
  167. function _mapStateToProps(state, ownProps) {
  168. const kickOutEnabled = getFeatureFlag(state, KICK_OUT_ENABLED, true);
  169. const { participantId } = ownProps;
  170. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  171. const isParticipantAvailable = getParticipantById(state, participantId);
  172. let { disableKick } = remoteVideoMenu;
  173. disableKick = disableKick || !kickOutEnabled;
  174. return {
  175. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  176. _disableKick: Boolean(disableKick),
  177. _disableRemoteMute: Boolean(disableRemoteMute),
  178. _isOpen: isDialogOpen(state, RemoteVideoMenu_),
  179. _isParticipantAvailable: Boolean(isParticipantAvailable),
  180. _participantDisplayName: getParticipantDisplayName(state, participantId)
  181. };
  182. }
  183. RemoteVideoMenu_ = connect(_mapStateToProps)(RemoteVideoMenu);
  184. export default RemoteVideoMenu_;