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.

RemoteVideoMenuTriggerButton.tsx 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* eslint-disable lines-around-comment */
  2. import { withStyles } from '@mui/styles';
  3. import React, { Component } from 'react';
  4. import { WithTranslation } from 'react-i18next';
  5. import { batch, connect } from 'react-redux';
  6. import { IReduxState } from '../../../app/types';
  7. import { isMobileBrowser } from '../../../base/environment/utils';
  8. import { translate } from '../../../base/i18n/functions';
  9. import { IconDotsHorizontal } from '../../../base/icons/svg';
  10. import { getLocalParticipant, getParticipantById } from '../../../base/participants/functions';
  11. import { IParticipant } from '../../../base/participants/types';
  12. import Popover from '../../../base/popover/components/Popover.web';
  13. import { setParticipantContextMenuOpen } from '../../../base/responsive-ui/actions';
  14. import Button from '../../../base/ui/components/web/Button';
  15. import ConnectionIndicatorContent from
  16. // @ts-ignore
  17. '../../../connection-indicator/components/web/ConnectionIndicatorContent';
  18. import { THUMBNAIL_TYPE } from '../../../filmstrip/constants';
  19. import { renderConnectionStatus } from '../../actions.web';
  20. import FakeParticipantContextMenu from './FakeParticipantContextMenu';
  21. import ParticipantContextMenu from './ParticipantContextMenu';
  22. // @ts-ignore
  23. import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  24. /* eslint-enable lines-around-comment */
  25. /**
  26. * The type of the React {@code Component} props of
  27. * {@link RemoteVideoMenuTriggerButton}.
  28. */
  29. interface IProps extends WithTranslation {
  30. /**
  31. * Whether the remote video context menu is disabled.
  32. */
  33. _disabled: Boolean;
  34. /**
  35. * Shared video local participant owner.
  36. */
  37. _localVideoOwner?: boolean;
  38. /**
  39. * The position relative to the trigger the remote menu should display
  40. * from.
  41. */
  42. _menuPosition: string;
  43. /**
  44. * Whether to display the Popover as a drawer.
  45. */
  46. _overflowDrawer: boolean;
  47. /**
  48. * Participant reference.
  49. */
  50. _participant: IParticipant;
  51. /**
  52. * The ID for the participant on which the remote video menu will act.
  53. */
  54. _participantDisplayName: string;
  55. /**
  56. * The current state of the participant's remote control session.
  57. */
  58. _remoteControlState: number;
  59. /**
  60. * Whether the popover should render the Connection Info stats.
  61. */
  62. _showConnectionInfo: Boolean;
  63. /**
  64. * Whether or not the button should be visible.
  65. */
  66. buttonVisible: boolean;
  67. /**
  68. * An object containing the CSS classes.
  69. */
  70. classes: any;
  71. /**
  72. * The redux dispatch function.
  73. */
  74. dispatch: Function;
  75. /**
  76. * Hides popover.
  77. */
  78. hidePopover: Function;
  79. /**
  80. * The ID for the participant on which the remote video menu will act.
  81. */
  82. participantID: string;
  83. /**
  84. * Whether the popover is visible or not.
  85. */
  86. popoverVisible: boolean;
  87. /**
  88. * Shows popover.
  89. */
  90. showPopover: Function;
  91. /**
  92. * The type of the thumbnail.
  93. */
  94. thumbnailType: string;
  95. }
  96. const styles = () => {
  97. return {
  98. triggerButton: {
  99. padding: '3px !important',
  100. borderRadius: '4px',
  101. '& svg': {
  102. width: '18px',
  103. height: '18px'
  104. }
  105. },
  106. contextMenu: {
  107. position: 'relative' as const,
  108. marginTop: 0,
  109. right: 'auto',
  110. marginRight: '4px',
  111. marginBottom: '4px'
  112. }
  113. };
  114. };
  115. /**
  116. * React {@code Component} for displaying an icon associated with opening the
  117. * the {@code VideoMenu}.
  118. *
  119. * @augments {Component}
  120. */
  121. class RemoteVideoMenuTriggerButton extends Component<IProps> {
  122. /**
  123. * Initializes a new RemoteVideoMenuTriggerButton instance.
  124. *
  125. * @param {Object} props - The read-only React Component props with which
  126. * the new instance is to be initialized.
  127. */
  128. constructor(props: IProps) {
  129. super(props);
  130. this._onPopoverClose = this._onPopoverClose.bind(this);
  131. this._onPopoverOpen = this._onPopoverOpen.bind(this);
  132. }
  133. /**
  134. * Implements React's {@link Component#render()}.
  135. *
  136. * @inheritdoc
  137. * @returns {ReactElement}
  138. */
  139. render() {
  140. const {
  141. _disabled,
  142. _overflowDrawer,
  143. _showConnectionInfo,
  144. _participantDisplayName,
  145. buttonVisible,
  146. classes,
  147. participantID,
  148. popoverVisible
  149. } = this.props;
  150. let content;
  151. if (_showConnectionInfo) {
  152. content = <ConnectionIndicatorContent participantId = { participantID } />;
  153. } else if (!_disabled) {
  154. content = this._renderRemoteVideoMenu();
  155. }
  156. if (!content) {
  157. return null;
  158. }
  159. const username = _participantDisplayName;
  160. return (
  161. <Popover
  162. content = { content }
  163. headingLabel = { this.props.t('dialog.remoteUserControls', { username }) }
  164. id = 'remote-video-menu-trigger'
  165. onPopoverClose = { this._onPopoverClose }
  166. onPopoverOpen = { this._onPopoverOpen }
  167. overflowDrawer = { _overflowDrawer }
  168. position = { this.props._menuPosition }
  169. visible = { popoverVisible }>
  170. { buttonVisible && !_disabled && (
  171. !isMobileBrowser() && <Button
  172. accessibilityLabel = { this.props.t('dialog.remoteUserControls', { username }) }
  173. className = { classes.triggerButton }
  174. icon = { IconDotsHorizontal }
  175. size = 'small' />
  176. )}
  177. </Popover>
  178. );
  179. }
  180. /**
  181. * Disable and hide toolbox while context menu is open.
  182. *
  183. * @returns {void}
  184. */
  185. _onPopoverOpen() {
  186. const { dispatch, showPopover } = this.props;
  187. showPopover();
  188. dispatch(setParticipantContextMenuOpen(true));
  189. }
  190. /**
  191. * Render normal context menu next time popover dialog opens.
  192. *
  193. * @returns {void}
  194. */
  195. _onPopoverClose() {
  196. const { dispatch, hidePopover } = this.props;
  197. hidePopover();
  198. batch(() => {
  199. dispatch(setParticipantContextMenuOpen(false));
  200. dispatch(renderConnectionStatus(false));
  201. });
  202. }
  203. /**
  204. * Creates a new {@code VideoMenu} with buttons for interacting with
  205. * the remote participant.
  206. *
  207. * @private
  208. * @returns {ReactElement}
  209. */
  210. _renderRemoteVideoMenu() {
  211. const { _localVideoOwner, _participant, _remoteControlState, classes } = this.props;
  212. const props = {
  213. className: classes.contextMenu,
  214. onSelect: this._onPopoverClose,
  215. participant: _participant,
  216. thumbnailMenu: true
  217. };
  218. if (_participant?.fakeParticipant) {
  219. return (
  220. <FakeParticipantContextMenu
  221. { ...props }
  222. localVideoOwner = { _localVideoOwner } />
  223. );
  224. }
  225. return (
  226. <ParticipantContextMenu
  227. { ...props }
  228. remoteControlState = { _remoteControlState } />
  229. );
  230. }
  231. }
  232. /**
  233. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  234. *
  235. * @param {Object} state - The Redux state.
  236. * @param {Object} ownProps - The own props of the component.
  237. * @private
  238. * @returns {IProps}
  239. */
  240. function _mapStateToProps(state: IReduxState, ownProps: Partial<IProps>) {
  241. const { participantID, thumbnailType } = ownProps;
  242. let _remoteControlState = null;
  243. const localParticipantId = getLocalParticipant(state)?.id;
  244. const participant = getParticipantById(state, participantID ?? '');
  245. const _participantDisplayName = participant?.name;
  246. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  247. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  248. const { active, controller } = state['features/remote-control'];
  249. const { requestedParticipant, controlled } = controller;
  250. const activeParticipant = requestedParticipant || controlled;
  251. const { overflowDrawer } = state['features/toolbox'];
  252. const { showConnectionInfo } = state['features/base/connection'];
  253. const { remoteVideoMenu } = state['features/base/config'];
  254. const { ownerId } = state['features/shared-video'];
  255. if (_supportsRemoteControl
  256. && ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
  257. if (requestedParticipant === participantID) {
  258. _remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  259. } else if (controlled) {
  260. _remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  261. } else {
  262. _remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  263. }
  264. }
  265. let _menuPosition;
  266. switch (thumbnailType) {
  267. case THUMBNAIL_TYPE.TILE:
  268. _menuPosition = 'left-start';
  269. break;
  270. case THUMBNAIL_TYPE.VERTICAL:
  271. _menuPosition = 'left-end';
  272. break;
  273. case THUMBNAIL_TYPE.HORIZONTAL:
  274. _menuPosition = 'top';
  275. break;
  276. default:
  277. _menuPosition = 'auto';
  278. }
  279. return {
  280. _disabled: Boolean(remoteVideoMenu?.disabled),
  281. _localVideoOwner: Boolean(ownerId === localParticipantId),
  282. _menuPosition,
  283. _overflowDrawer: overflowDrawer,
  284. _participant: participant ?? { id: '' },
  285. _participantDisplayName: _participantDisplayName ?? '',
  286. _remoteControlState,
  287. _showConnectionInfo: Boolean(showConnectionInfo)
  288. };
  289. }
  290. export default translate(connect(_mapStateToProps)(
  291. withStyles(styles)(RemoteVideoMenuTriggerButton)));