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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 { IconHorizontalPoints } 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. },
  102. contextMenu: {
  103. position: 'relative' as const,
  104. marginTop: 0,
  105. right: 'auto',
  106. marginRight: '4px',
  107. marginBottom: '4px'
  108. }
  109. };
  110. };
  111. /**
  112. * React {@code Component} for displaying an icon associated with opening the
  113. * the {@code VideoMenu}.
  114. *
  115. * @augments {Component}
  116. */
  117. class RemoteVideoMenuTriggerButton extends Component<IProps> {
  118. /**
  119. * Initializes a new RemoteVideoMenuTriggerButton instance.
  120. *
  121. * @param {Object} props - The read-only React Component props with which
  122. * the new instance is to be initialized.
  123. */
  124. constructor(props: IProps) {
  125. super(props);
  126. this._onPopoverClose = this._onPopoverClose.bind(this);
  127. this._onPopoverOpen = this._onPopoverOpen.bind(this);
  128. }
  129. /**
  130. * Implements React's {@link Component#render()}.
  131. *
  132. * @inheritdoc
  133. * @returns {ReactElement}
  134. */
  135. render() {
  136. const {
  137. _disabled,
  138. _overflowDrawer,
  139. _showConnectionInfo,
  140. _participantDisplayName,
  141. buttonVisible,
  142. classes,
  143. participantID,
  144. popoverVisible
  145. } = this.props;
  146. let content;
  147. if (_showConnectionInfo) {
  148. content = <ConnectionIndicatorContent participantId = { participantID } />;
  149. } else if (!_disabled) {
  150. content = this._renderRemoteVideoMenu();
  151. }
  152. if (!content) {
  153. return null;
  154. }
  155. const username = _participantDisplayName;
  156. return (
  157. <Popover
  158. content = { content }
  159. id = 'remote-video-menu-trigger'
  160. onPopoverClose = { this._onPopoverClose }
  161. onPopoverOpen = { this._onPopoverOpen }
  162. position = { this.props._menuPosition }
  163. visible = { popoverVisible }>
  164. {!_overflowDrawer && buttonVisible && !_disabled && (
  165. !isMobileBrowser() && <Button
  166. accessibilityLabel = { this.props.t('dialog.remoteUserControls', { username }) }
  167. className = { classes.triggerButton }
  168. icon = { IconHorizontalPoints }
  169. size = 'small' />
  170. )}
  171. </Popover>
  172. );
  173. }
  174. /**
  175. * Disable and hide toolbox while context menu is open.
  176. *
  177. * @returns {void}
  178. */
  179. _onPopoverOpen() {
  180. const { dispatch, showPopover } = this.props;
  181. showPopover();
  182. dispatch(setParticipantContextMenuOpen(true));
  183. }
  184. /**
  185. * Render normal context menu next time popover dialog opens.
  186. *
  187. * @returns {void}
  188. */
  189. _onPopoverClose() {
  190. const { dispatch, hidePopover } = this.props;
  191. hidePopover();
  192. batch(() => {
  193. dispatch(setParticipantContextMenuOpen(false));
  194. dispatch(renderConnectionStatus(false));
  195. });
  196. }
  197. /**
  198. * Creates a new {@code VideoMenu} with buttons for interacting with
  199. * the remote participant.
  200. *
  201. * @private
  202. * @returns {ReactElement}
  203. */
  204. _renderRemoteVideoMenu() {
  205. const { _localVideoOwner, _participant, _remoteControlState, classes } = this.props;
  206. const props = {
  207. className: classes.contextMenu,
  208. onSelect: this._onPopoverClose,
  209. participant: _participant,
  210. thumbnailMenu: true
  211. };
  212. if (_participant?.fakeParticipant) {
  213. return (
  214. <FakeParticipantContextMenu
  215. { ...props }
  216. localVideoOwner = { _localVideoOwner } />
  217. );
  218. }
  219. return (
  220. <ParticipantContextMenu
  221. { ...props }
  222. remoteControlState = { _remoteControlState } />
  223. );
  224. }
  225. }
  226. /**
  227. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  228. *
  229. * @param {Object} state - The Redux state.
  230. * @param {Object} ownProps - The own props of the component.
  231. * @private
  232. * @returns {IProps}
  233. */
  234. function _mapStateToProps(state: IReduxState, ownProps: Partial<IProps>) {
  235. const { participantID, thumbnailType } = ownProps;
  236. let _remoteControlState = null;
  237. const localParticipantId = getLocalParticipant(state)?.id;
  238. const participant = getParticipantById(state, participantID ?? '');
  239. const _participantDisplayName = participant?.name;
  240. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  241. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  242. const { active, controller } = state['features/remote-control'];
  243. const { requestedParticipant, controlled } = controller;
  244. const activeParticipant = requestedParticipant || controlled;
  245. const { overflowDrawer } = state['features/toolbox'];
  246. const { showConnectionInfo } = state['features/base/connection'];
  247. const { remoteVideoMenu } = state['features/base/config'];
  248. const { ownerId } = state['features/shared-video'];
  249. if (_supportsRemoteControl
  250. && ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
  251. if (requestedParticipant === participantID) {
  252. _remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  253. } else if (controlled) {
  254. _remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  255. } else {
  256. _remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  257. }
  258. }
  259. let _menuPosition;
  260. switch (thumbnailType) {
  261. case THUMBNAIL_TYPE.TILE:
  262. _menuPosition = 'left-start';
  263. break;
  264. case THUMBNAIL_TYPE.VERTICAL:
  265. _menuPosition = 'left-end';
  266. break;
  267. case THUMBNAIL_TYPE.HORIZONTAL:
  268. _menuPosition = 'top';
  269. break;
  270. default:
  271. _menuPosition = 'auto';
  272. }
  273. return {
  274. _disabled: Boolean(remoteVideoMenu?.disabled),
  275. _localVideoOwner: Boolean(ownerId === localParticipantId),
  276. _menuPosition,
  277. _overflowDrawer: overflowDrawer,
  278. _participant: participant ?? { id: '' },
  279. _participantDisplayName: _participantDisplayName ?? '',
  280. _remoteControlState,
  281. _showConnectionInfo: Boolean(showConnectionInfo)
  282. };
  283. }
  284. export default translate(connect(_mapStateToProps)(
  285. withStyles(styles)(RemoteVideoMenuTriggerButton)));