2021-01-21 20:46:47 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-06-30 16:12:12 +00:00
|
|
|
import React, { Component } from 'react';
|
2021-09-14 07:43:52 +00:00
|
|
|
import { batch } from 'react-redux';
|
2021-01-21 20:46:47 +00:00
|
|
|
|
2021-06-30 16:12:12 +00:00
|
|
|
import { isMobileBrowser } from '../../../base/environment/utils';
|
2021-06-10 12:48:44 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2021-01-21 20:46:47 +00:00
|
|
|
import { Icon, IconMenuThumb } from '../../../base/icons';
|
2021-06-30 16:12:12 +00:00
|
|
|
import {
|
|
|
|
getLocalParticipant
|
|
|
|
} from '../../../base/participants';
|
2021-01-21 20:46:47 +00:00
|
|
|
import { Popover } from '../../../base/popover';
|
|
|
|
import { connect } from '../../../base/redux';
|
2021-09-14 07:43:52 +00:00
|
|
|
import { setParticipantContextMenuOpen } from '../../../base/responsive-ui/actions';
|
2021-01-21 20:46:47 +00:00
|
|
|
import { getLocalVideoTrack } from '../../../base/tracks';
|
2021-06-30 16:12:12 +00:00
|
|
|
import ConnectionIndicatorContent from '../../../connection-indicator/components/web/ConnectionIndicatorContent';
|
2021-09-14 07:43:52 +00:00
|
|
|
import { hideToolboxOnTileView } from '../../../toolbox/actions';
|
2021-01-21 20:46:47 +00:00
|
|
|
import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
|
2021-06-30 16:12:12 +00:00
|
|
|
import { renderConnectionStatus } from '../../actions.web';
|
2021-01-21 20:46:47 +00:00
|
|
|
|
2021-06-30 16:12:12 +00:00
|
|
|
import ConnectionStatusButton from './ConnectionStatusButton';
|
2021-01-21 20:46:47 +00:00
|
|
|
import FlipLocalVideoButton from './FlipLocalVideoButton';
|
|
|
|
import VideoMenu from './VideoMenu';
|
|
|
|
|
2021-06-30 16:12:12 +00:00
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link LocalVideoMenuTriggerButton}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
2021-06-30 16:12:12 +00:00
|
|
|
/**
|
|
|
|
* The redux dispatch function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a ref to the current component instance.
|
|
|
|
*/
|
|
|
|
getRef: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the local participant.
|
|
|
|
*/
|
|
|
|
_localParticipantId: string,
|
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
/**
|
|
|
|
* The position relative to the trigger the local video menu should display
|
|
|
|
* from. Valid values are those supported by AtlasKit
|
|
|
|
* {@code InlineDialog}.
|
|
|
|
*/
|
|
|
|
_menuPosition: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether to display the Popover as a drawer.
|
|
|
|
*/
|
|
|
|
_overflowDrawer: boolean,
|
|
|
|
|
2021-06-30 16:12:12 +00:00
|
|
|
/**
|
|
|
|
* Whether to render the connection info pane.
|
|
|
|
*/
|
|
|
|
_showConnectionInfo: boolean,
|
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
/**
|
|
|
|
* Shows/hides the local video flip button.
|
|
|
|
*/
|
2021-06-10 12:48:44 +00:00
|
|
|
_showLocalVideoFlipButton: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
2021-01-21 20:46:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React Component for displaying an icon associated with opening the
|
|
|
|
* the video menu for the local participant.
|
|
|
|
*
|
2021-06-30 16:12:12 +00:00
|
|
|
* @extends {Component}
|
2021-01-21 20:46:47 +00:00
|
|
|
*/
|
2021-06-30 16:12:12 +00:00
|
|
|
class LocalVideoMenuTriggerButton extends Component<Props> {
|
|
|
|
/**
|
|
|
|
* Reference to the Popover instance.
|
|
|
|
*/
|
|
|
|
popoverRef: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new LocalVideoMenuTriggerButton instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only React Component props with which
|
|
|
|
* the new instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.popoverRef = React.createRef();
|
|
|
|
this._onPopoverClose = this._onPopoverClose.bind(this);
|
2021-09-10 12:17:57 +00:00
|
|
|
this._onPopoverOpen = this._onPopoverOpen.bind(this);
|
2021-06-30 16:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggers showing the popover's context menu.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
showContextMenu() {
|
|
|
|
if (this.popoverRef && this.popoverRef.current) {
|
|
|
|
this.popoverRef.current.showDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls the ref(instance) getter.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
if (this.props.getRef) {
|
|
|
|
this.props.getRef(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls the ref(instance) getter.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.props.getRef) {
|
|
|
|
this.props.getRef(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
_localParticipantId,
|
|
|
|
_menuPosition,
|
|
|
|
_showConnectionInfo,
|
|
|
|
_overflowDrawer,
|
|
|
|
_showLocalVideoFlipButton,
|
|
|
|
t
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const content = _showConnectionInfo
|
|
|
|
? <ConnectionIndicatorContent participantId = { _localParticipantId } />
|
|
|
|
: (
|
|
|
|
<VideoMenu id = 'localVideoMenu'>
|
|
|
|
<FlipLocalVideoButton />
|
|
|
|
{ isMobileBrowser()
|
|
|
|
&& <ConnectionStatusButton participantId = { _localParticipantId } />
|
|
|
|
}
|
|
|
|
</VideoMenu>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
isMobileBrowser() || _showLocalVideoFlipButton
|
|
|
|
? <Popover
|
|
|
|
content = { content }
|
|
|
|
onPopoverClose = { this._onPopoverClose }
|
2021-09-10 12:17:57 +00:00
|
|
|
onPopoverOpen = { this._onPopoverOpen }
|
2021-06-30 16:12:12 +00:00
|
|
|
overflowDrawer = { _overflowDrawer }
|
|
|
|
position = { _menuPosition }
|
|
|
|
ref = { this.popoverRef }>
|
2021-09-14 07:43:52 +00:00
|
|
|
{!_overflowDrawer && (
|
2021-06-30 16:12:12 +00:00
|
|
|
<span
|
|
|
|
className = 'popover-trigger local-video-menu-trigger'>
|
2021-09-14 07:43:52 +00:00
|
|
|
{!isMobileBrowser() && <Icon
|
2021-06-30 16:12:12 +00:00
|
|
|
ariaLabel = { t('dialog.localUserControls') }
|
|
|
|
role = 'button'
|
|
|
|
size = '1em'
|
|
|
|
src = { IconMenuThumb }
|
|
|
|
tabIndex = { 0 }
|
|
|
|
title = { t('dialog.localUserControls') } />
|
2021-09-14 07:43:52 +00:00
|
|
|
}
|
2021-06-30 16:12:12 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:17:57 +00:00
|
|
|
_onPopoverOpen: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable and hide toolbox while context menu is open.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onPopoverOpen() {
|
2021-09-14 07:43:52 +00:00
|
|
|
this.props.dispatch(setParticipantContextMenuOpen(true));
|
|
|
|
this.props.dispatch(hideToolboxOnTileView());
|
2021-09-10 12:17:57 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 16:12:12 +00:00
|
|
|
_onPopoverClose: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render normal context menu next time popover dialog opens.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onPopoverClose() {
|
2021-09-14 07:43:52 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
batch(() => {
|
|
|
|
dispatch(setParticipantContextMenuOpen(false));
|
|
|
|
dispatch(renderConnectionStatus(false));
|
|
|
|
});
|
2021-06-30 16:12:12 +00:00
|
|
|
}
|
2021-01-21 20:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated {@code LocalVideoMenuTriggerButton}'s props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
const currentLayout = getCurrentLayout(state);
|
2021-06-30 16:12:12 +00:00
|
|
|
const localParticipant = getLocalParticipant(state);
|
2021-01-21 20:46:47 +00:00
|
|
|
const { disableLocalVideoFlip } = state['features/base/config'];
|
|
|
|
const videoTrack = getLocalVideoTrack(state['features/base/tracks']);
|
|
|
|
const { overflowDrawer } = state['features/toolbox'];
|
2021-06-30 16:12:12 +00:00
|
|
|
const { showConnectionInfo } = state['features/base/connection'];
|
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
let _menuPosition;
|
|
|
|
|
|
|
|
switch (currentLayout) {
|
|
|
|
case LAYOUTS.TILE_VIEW:
|
|
|
|
_menuPosition = 'left-start';
|
|
|
|
break;
|
|
|
|
case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
|
|
|
|
_menuPosition = 'left-end';
|
|
|
|
break;
|
2021-08-16 09:58:48 +00:00
|
|
|
case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
|
|
|
|
_menuPosition = 'top';
|
|
|
|
break;
|
2021-01-21 20:46:47 +00:00
|
|
|
default:
|
|
|
|
_menuPosition = 'auto';
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
_menuPosition,
|
|
|
|
_showLocalVideoFlipButton: !disableLocalVideoFlip && videoTrack?.videoType !== 'desktop',
|
2021-06-30 16:12:12 +00:00
|
|
|
_overflowDrawer: overflowDrawer,
|
|
|
|
_localParticipantId: localParticipant.id,
|
2021-09-14 07:43:52 +00:00
|
|
|
_showConnectionInfo: showConnectionInfo
|
2021-01-21 20:46:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
export default translate(connect(_mapStateToProps)(LocalVideoMenuTriggerButton));
|