您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RemoteVideoMenuTriggerButton.tsx 9.5KB

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