Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RemoteVideoMenu.tsx 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* eslint-disable lines-around-comment*/
  2. import React, { PureComponent } from 'react';
  3. import { Text, TextStyle, View, ViewStyle } from 'react-native';
  4. import { Divider } from 'react-native-paper';
  5. import { connect } from 'react-redux';
  6. import { IReduxState, IStore } from '../../../app/types';
  7. import Avatar from '../../../base/avatar/components/Avatar';
  8. import { hideSheet } from '../../../base/dialog/actions';
  9. import BottomSheet from '../../../base/dialog/components/native/BottomSheet';
  10. import { bottomSheetStyles } from '../../../base/dialog/components/native/styles';
  11. import { KICK_OUT_ENABLED } from '../../../base/flags/constants';
  12. import { getFeatureFlag } from '../../../base/flags/functions';
  13. import { translate } from '../../../base/i18n/functions';
  14. import {
  15. getParticipantById,
  16. getParticipantDisplayName,
  17. hasRaisedHand,
  18. isLocalParticipantModerator
  19. } from '../../../base/participants/functions';
  20. import { getBreakoutRooms, getCurrentRoomId, isInBreakoutRoom } from '../../../breakout-rooms/functions';
  21. import { IRoom } from '../../../breakout-rooms/types';
  22. import PrivateMessageButton from '../../../chat/components/native/PrivateMessageButton';
  23. import AskUnmuteButton from './AskUnmuteButton';
  24. import ConnectionStatusButton from './ConnectionStatusButton';
  25. import DemoteToVisitorButton from './DemoteToVisitorButton';
  26. import GrantModeratorButton from './GrantModeratorButton';
  27. import KickButton from './KickButton';
  28. import LowerHandButton from './LowerHandButton';
  29. import MuteButton from './MuteButton';
  30. import MuteEveryoneElseButton from './MuteEveryoneElseButton';
  31. import MuteVideoButton from './MuteVideoButton';
  32. import PinButton from './PinButton';
  33. import SendToBreakoutRoom from './SendToBreakoutRoom';
  34. import VolumeSlider from './VolumeSlider';
  35. import styles from './styles';
  36. /**
  37. * Size of the rendered avatar in the menu.
  38. */
  39. const AVATAR_SIZE = 24;
  40. interface IProps {
  41. /**
  42. * The id of the current room.
  43. */
  44. _currentRoomId: string;
  45. /**
  46. * Whether or not to display the grant moderator button.
  47. */
  48. _disableGrantModerator: boolean;
  49. /**
  50. * Whether or not to display the kick button.
  51. */
  52. _disableKick: boolean;
  53. /**
  54. * Whether or not to display the send private message button.
  55. */
  56. _disablePrivateChat: boolean;
  57. /**
  58. * Whether or not to display the remote mute buttons.
  59. */
  60. _disableRemoteMute: boolean;
  61. /**
  62. * Whether or not the current room is a breakout room.
  63. */
  64. _isBreakoutRoom: boolean;
  65. /**
  66. * Whether the participant is present in the room or not.
  67. */
  68. _isParticipantAvailable?: boolean;
  69. /**
  70. * Whether or not the targeted participant joined without audio.
  71. */
  72. _isParticipantSilent: boolean;
  73. /**
  74. * Whether the local participant is moderator or not.
  75. */
  76. _moderator: boolean;
  77. /**
  78. * Display name of the participant retrieved from Redux.
  79. */
  80. _participantDisplayName: string;
  81. /**
  82. * Whether the targeted participant raised hand or not.
  83. */
  84. _raisedHand: boolean;
  85. /**
  86. * Array containing the breakout rooms.
  87. */
  88. _rooms: Array<IRoom>;
  89. /**
  90. * Whether to display the demote button.
  91. */
  92. _showDemote: boolean;
  93. /**
  94. * The Redux dispatch function.
  95. */
  96. dispatch: IStore['dispatch'];
  97. /**
  98. * The ID of the participant for which this menu opened for.
  99. */
  100. participantId: string;
  101. /**
  102. * Translation function.
  103. */
  104. t: Function;
  105. }
  106. /**
  107. * Class to implement a popup menu that opens upon long pressing a thumbnail.
  108. */
  109. class RemoteVideoMenu extends PureComponent<IProps> {
  110. /**
  111. * Constructor of the component.
  112. *
  113. * @inheritdoc
  114. */
  115. constructor(props: IProps) {
  116. super(props);
  117. this._onCancel = this._onCancel.bind(this);
  118. this._renderMenuHeader = this._renderMenuHeader.bind(this);
  119. }
  120. /**
  121. * Implements {@code Component#render}.
  122. *
  123. * @inheritdoc
  124. */
  125. render() {
  126. const {
  127. _disableKick,
  128. _disablePrivateChat,
  129. _disableRemoteMute,
  130. _disableGrantModerator,
  131. _isBreakoutRoom,
  132. _isParticipantAvailable,
  133. _isParticipantSilent,
  134. _moderator,
  135. _raisedHand,
  136. _rooms,
  137. _showDemote,
  138. _currentRoomId,
  139. participantId,
  140. t
  141. } = this.props;
  142. const buttonProps = {
  143. afterClick: this._onCancel,
  144. showLabel: true,
  145. participantID: participantId,
  146. styles: bottomSheetStyles.buttons
  147. };
  148. const connectionStatusButtonProps = {
  149. ...buttonProps,
  150. afterClick: undefined
  151. };
  152. return (
  153. <BottomSheet
  154. renderHeader = { this._renderMenuHeader }
  155. showSlidingView = { _isParticipantAvailable }>
  156. {!_isParticipantSilent && <AskUnmuteButton { ...buttonProps } />}
  157. { !_disableRemoteMute && <MuteButton { ...buttonProps } /> }
  158. <MuteEveryoneElseButton { ...buttonProps } />
  159. { _moderator && _raisedHand && <LowerHandButton { ...buttonProps } /> }
  160. { !_disableRemoteMute && !_isParticipantSilent && <MuteVideoButton { ...buttonProps } /> }
  161. {/* @ts-ignore */}
  162. <Divider style = { styles.divider as ViewStyle } />
  163. { !_disableKick && <KickButton { ...buttonProps } /> }
  164. { !_disableGrantModerator && !_isBreakoutRoom && <GrantModeratorButton { ...buttonProps } /> }
  165. <PinButton { ...buttonProps } />
  166. { _showDemote && <DemoteToVisitorButton { ...buttonProps } /> }
  167. { !_disablePrivateChat && <PrivateMessageButton { ...buttonProps } /> }
  168. <ConnectionStatusButton { ...connectionStatusButtonProps } />
  169. {_moderator && _rooms.length > 1 && <>
  170. {/* @ts-ignore */}
  171. <Divider style = { styles.divider as ViewStyle } />
  172. <View style = { styles.contextMenuItem as ViewStyle }>
  173. <Text style = { styles.contextMenuItemText as TextStyle }>
  174. {t('breakoutRooms.actions.sendToBreakoutRoom')}
  175. </Text>
  176. </View>
  177. {_rooms.map(room => _currentRoomId !== room.id && (<SendToBreakoutRoom
  178. key = { room.id }
  179. room = { room }
  180. { ...buttonProps } />))}
  181. </>}
  182. <VolumeSlider participantID = { participantId } />
  183. </BottomSheet>
  184. );
  185. }
  186. /**
  187. * Callback to hide the {@code RemoteVideoMenu}.
  188. *
  189. * @private
  190. * @returns {boolean}
  191. */
  192. _onCancel() {
  193. this.props.dispatch(hideSheet());
  194. }
  195. /**
  196. * Function to render the menu's header.
  197. *
  198. * @returns {React$Element}
  199. */
  200. _renderMenuHeader() {
  201. const { participantId } = this.props;
  202. return (
  203. <View
  204. style = { [
  205. bottomSheetStyles.sheet,
  206. styles.participantNameContainer ] as ViewStyle[] }>
  207. <Avatar
  208. participantId = { participantId }
  209. size = { AVATAR_SIZE } />
  210. <Text style = { styles.participantNameLabel as TextStyle }>
  211. { this.props._participantDisplayName }
  212. </Text>
  213. </View>
  214. );
  215. }
  216. }
  217. /**
  218. * Function that maps parts of Redux state tree into component props.
  219. *
  220. * @param {Object} state - Redux state.
  221. * @param {Object} ownProps - Properties of component.
  222. * @private
  223. * @returns {IProps}
  224. */
  225. function _mapStateToProps(state: IReduxState, ownProps: any) {
  226. const kickOutEnabled = getFeatureFlag(state, KICK_OUT_ENABLED, true);
  227. const { participantId } = ownProps;
  228. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  229. const participant = getParticipantById(state, participantId);
  230. const { disableKick, disablePrivateChat } = remoteVideoMenu;
  231. const _rooms = Object.values(getBreakoutRooms(state));
  232. const _currentRoomId = getCurrentRoomId(state);
  233. const shouldDisableKick = disableKick || !kickOutEnabled;
  234. const moderator = isLocalParticipantModerator(state);
  235. const _iAmVisitor = state['features/visitors'].iAmVisitor;
  236. const _isBreakoutRoom = isInBreakoutRoom(state);
  237. const raisedHand = hasRaisedHand(participant);
  238. return {
  239. _currentRoomId,
  240. _disableKick: Boolean(shouldDisableKick),
  241. _disableRemoteMute: Boolean(disableRemoteMute),
  242. _disablePrivateChat: Boolean(disablePrivateChat) || _iAmVisitor,
  243. _isBreakoutRoom,
  244. _isParticipantAvailable: Boolean(participant),
  245. _isParticipantSilent: Boolean(participant?.isSilent),
  246. _moderator: moderator,
  247. _participantDisplayName: getParticipantDisplayName(state, participantId),
  248. _raisedHand: raisedHand,
  249. _rooms,
  250. _showDemote: moderator
  251. };
  252. }
  253. export default translate(connect(_mapStateToProps)(RemoteVideoMenu));