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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. // @ts-ignore
  20. import { renderConnectionStatus } from '../../actions.web';
  21. import FakeParticipantContextMenu from './FakeParticipantContextMenu';
  22. import ParticipantContextMenu from './ParticipantContextMenu';
  23. // @ts-ignore
  24. import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  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. id = 'remote-video-menu-trigger'
  164. onPopoverClose = { this._onPopoverClose }
  165. onPopoverOpen = { this._onPopoverOpen }
  166. position = { this.props._menuPosition }
  167. visible = { popoverVisible }>
  168. {!_overflowDrawer && buttonVisible && !_disabled && (
  169. !isMobileBrowser() && <Button
  170. accessibilityLabel = { this.props.t('dialog.remoteUserControls', { username }) }
  171. className = { classes.triggerButton }
  172. icon = { IconDotsHorizontal }
  173. size = 'small' />
  174. )}
  175. </Popover>
  176. );
  177. }
  178. /**
  179. * Disable and hide toolbox while context menu is open.
  180. *
  181. * @returns {void}
  182. */
  183. _onPopoverOpen() {
  184. const { dispatch, showPopover } = this.props;
  185. showPopover();
  186. dispatch(setParticipantContextMenuOpen(true));
  187. }
  188. /**
  189. * Render normal context menu next time popover dialog opens.
  190. *
  191. * @returns {void}
  192. */
  193. _onPopoverClose() {
  194. const { dispatch, hidePopover } = this.props;
  195. hidePopover();
  196. batch(() => {
  197. dispatch(setParticipantContextMenuOpen(false));
  198. dispatch(renderConnectionStatus(false));
  199. });
  200. }
  201. /**
  202. * Creates a new {@code VideoMenu} with buttons for interacting with
  203. * the remote participant.
  204. *
  205. * @private
  206. * @returns {ReactElement}
  207. */
  208. _renderRemoteVideoMenu() {
  209. const { _localVideoOwner, _participant, _remoteControlState, classes } = this.props;
  210. const props = {
  211. className: classes.contextMenu,
  212. onSelect: this._onPopoverClose,
  213. participant: _participant,
  214. thumbnailMenu: true
  215. };
  216. if (_participant?.fakeParticipant) {
  217. return (
  218. <FakeParticipantContextMenu
  219. { ...props }
  220. localVideoOwner = { _localVideoOwner } />
  221. );
  222. }
  223. return (
  224. <ParticipantContextMenu
  225. { ...props }
  226. remoteControlState = { _remoteControlState } />
  227. );
  228. }
  229. }
  230. /**
  231. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  232. *
  233. * @param {Object} state - The Redux state.
  234. * @param {Object} ownProps - The own props of the component.
  235. * @private
  236. * @returns {IProps}
  237. */
  238. function _mapStateToProps(state: IReduxState, ownProps: Partial<IProps>) {
  239. const { participantID, thumbnailType } = ownProps;
  240. let _remoteControlState = null;
  241. const localParticipantId = getLocalParticipant(state)?.id;
  242. const participant = getParticipantById(state, participantID ?? '');
  243. const _participantDisplayName = participant?.name;
  244. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  245. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  246. const { active, controller } = state['features/remote-control'];
  247. const { requestedParticipant, controlled } = controller;
  248. const activeParticipant = requestedParticipant || controlled;
  249. const { overflowDrawer } = state['features/toolbox'];
  250. const { showConnectionInfo } = state['features/base/connection'];
  251. const { remoteVideoMenu } = state['features/base/config'];
  252. const { ownerId } = state['features/shared-video'];
  253. if (_supportsRemoteControl
  254. && ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
  255. if (requestedParticipant === participantID) {
  256. _remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  257. } else if (controlled) {
  258. _remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  259. } else {
  260. _remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  261. }
  262. }
  263. let _menuPosition;
  264. switch (thumbnailType) {
  265. case THUMBNAIL_TYPE.TILE:
  266. _menuPosition = 'left-start';
  267. break;
  268. case THUMBNAIL_TYPE.VERTICAL:
  269. _menuPosition = 'left-end';
  270. break;
  271. case THUMBNAIL_TYPE.HORIZONTAL:
  272. _menuPosition = 'top';
  273. break;
  274. default:
  275. _menuPosition = 'auto';
  276. }
  277. return {
  278. _disabled: Boolean(remoteVideoMenu?.disabled),
  279. _localVideoOwner: Boolean(ownerId === localParticipantId),
  280. _menuPosition,
  281. _overflowDrawer: overflowDrawer,
  282. _participant: participant ?? { id: '' },
  283. _participantDisplayName: _participantDisplayName ?? '',
  284. _remoteControlState,
  285. _showConnectionInfo: Boolean(showConnectionInfo)
  286. };
  287. }
  288. export default translate(connect(_mapStateToProps)(
  289. withStyles(styles)(RemoteVideoMenuTriggerButton)));