bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/actions-bar/actions-dropdown/component.jsx

345 lines
11 KiB
React
Raw Normal View History

import _ from 'lodash';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { defineMessages } from 'react-intl';
2022-02-15 23:54:55 +08:00
import { withModalMounter } from '/imports/ui/components/common/modal/service';
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
import ExternalVideoModal from '/imports/ui/components/external-video-player/modal/container';
2022-02-15 23:54:55 +08:00
import RandomUserSelectContainer from '/imports/ui/components/common/modal/random-user/container';
import LayoutModalContainer from '/imports/ui/components/layout/modal/container';
2022-02-15 23:38:55 +08:00
import BBBMenu from '/imports/ui/components/common/menu/component';
import Styled from './styles';
import { colorPrimary } from '/imports/ui/stylesheets/styled-components/palette';
import { PANELS, ACTIONS, LAYOUT_TYPE } from '../../layout/enums';
import { isPresentationEnabled } from '/imports/ui/services/features';
import {isLayoutsEnabled} from '/imports/ui/services/features';
2017-06-07 20:01:18 +08:00
const propTypes = {
amIPresenter: PropTypes.bool.isRequired,
2021-08-09 22:24:02 +08:00
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
2017-06-07 20:01:18 +08:00
mountModal: PropTypes.func.isRequired,
amIModerator: PropTypes.bool.isRequired,
shortcuts: PropTypes.string,
handleTakePresenter: PropTypes.func.isRequired,
2019-05-29 22:31:27 +08:00
allowExternalVideo: PropTypes.bool.isRequired,
stopExternalVideoShare: PropTypes.func.isRequired,
isMobile: PropTypes.bool.isRequired,
setMeetingLayout: PropTypes.func.isRequired,
setPushLayout: PropTypes.func.isRequired,
showPushLayout: PropTypes.bool.isRequired,
2017-06-07 20:01:18 +08:00
};
const defaultProps = {
shortcuts: '',
settingsLayout: LAYOUT_TYPE.SMART_LAYOUT,
};
2016-10-18 05:29:00 +08:00
const intlMessages = defineMessages({
actionsLabel: {
id: 'app.actionsBar.actionsDropdown.actionsLabel',
2017-04-10 23:50:03 +08:00
description: 'Actions button label',
2016-10-18 05:29:00 +08:00
},
presentationLabel: {
id: 'app.actionsBar.actionsDropdown.presentationLabel',
2017-04-10 23:50:03 +08:00
description: 'Upload a presentation option label',
2016-10-18 05:29:00 +08:00
},
presentationDesc: {
id: 'app.actionsBar.actionsDropdown.presentationDesc',
2017-04-11 21:52:30 +08:00
description: 'adds context to upload presentation option',
2016-10-18 05:29:00 +08:00
},
desktopShareDesc: {
id: 'app.actionsBar.actionsDropdown.desktopShareDesc',
2017-04-11 21:52:30 +08:00
description: 'adds context to desktop share option',
2016-10-18 05:29:00 +08:00
},
stopDesktopShareDesc: {
id: 'app.actionsBar.actionsDropdown.stopDesktopShareDesc',
description: 'adds context to stop desktop share option',
},
2018-09-24 06:20:20 +08:00
pollBtnLabel: {
id: 'app.actionsBar.actionsDropdown.pollBtnLabel',
description: 'poll menu toggle button label',
},
pollBtnDesc: {
id: 'app.actionsBar.actionsDropdown.pollBtnDesc',
description: 'poll menu toggle button description',
},
takePresenter: {
id: 'app.actionsBar.actionsDropdown.takePresenter',
description: 'Label for take presenter role option',
},
takePresenterDesc: {
id: 'app.actionsBar.actionsDropdown.takePresenterDesc',
description: 'Description of take presenter role option',
},
startExternalVideoLabel: {
id: 'app.actionsBar.actionsDropdown.shareExternalVideo',
description: 'Start sharing external video button',
},
stopExternalVideoLabel: {
id: 'app.actionsBar.actionsDropdown.stopShareExternalVideo',
description: 'Stop sharing external video button',
},
selectRandUserLabel: {
id: 'app.actionsBar.actionsDropdown.selectRandUserLabel',
description: 'Label for selecting a random user',
},
selectRandUserDesc: {
id: 'app.actionsBar.actionsDropdown.selectRandUserDesc',
description: 'Description for select random user option',
},
propagateLayoutLabel: {
id: 'app.actionsBar.actionsDropdown.propagateLayoutLabel',
description: 'Label for propagate layout button',
},
layoutModal: {
id: 'app.actionsBar.actionsDropdown.layoutModal',
description: 'Label for layouts selection button',
},
2016-10-18 05:29:00 +08:00
});
const handlePresentationClick = () => Session.set('showUploadPresentationView', true);
2020-02-26 03:29:14 +08:00
class ActionsDropdown extends PureComponent {
2016-10-18 05:29:00 +08:00
constructor(props) {
super(props);
2017-05-04 04:51:17 +08:00
2018-01-18 05:51:33 +08:00
this.presentationItemId = _.uniqueId('action-item-');
2018-09-24 06:20:20 +08:00
this.pollId = _.uniqueId('action-item-');
this.takePresenterId = _.uniqueId('action-item-');
this.selectUserRandId = _.uniqueId('action-item-');
2018-01-18 05:51:33 +08:00
2019-04-03 02:57:29 +08:00
this.handleExternalVideoClick = this.handleExternalVideoClick.bind(this);
this.makePresentationItems = this.makePresentationItems.bind(this);
}
componentDidUpdate(prevProps) {
const { amIPresenter: wasPresenter } = prevProps;
const { amIPresenter: isPresenter, mountModal } = this.props;
if (wasPresenter && !isPresenter) {
mountModal(null);
}
}
handleExternalVideoClick() {
const { mountModal } = this.props;
mountModal(<ExternalVideoModal />);
}
2018-01-17 21:34:35 +08:00
getAvailableActions() {
const {
intl,
amIPresenter,
allowExternalVideo,
handleTakePresenter,
isSharingVideo,
2019-07-02 22:54:37 +08:00
isPollingEnabled,
2021-03-20 02:52:03 +08:00
isSelectRandomUserEnabled,
stopExternalVideoShare,
mountModal,
2021-08-05 19:03:24 +08:00
layoutContextDispatch,
setMeetingLayout,
setPushLayout,
showPushLayout,
2018-01-17 21:34:35 +08:00
} = this.props;
2018-12-18 23:15:51 +08:00
const {
pollBtnLabel,
presentationLabel,
takePresenter,
2018-12-18 23:15:51 +08:00
} = intlMessages;
const {
formatMessage,
} = intl;
const actions = [];
if (amIPresenter && isPresentationEnabled()) {
actions.push({
icon: "upload",
2022-01-20 21:03:18 +08:00
dataTest: "managePresentations",
label: formatMessage(presentationLabel),
key: this.presentationItemId,
onClick: handlePresentationClick,
dividerTop: this.props?.presentations?.length > 1 ? true : false,
})
}
if (amIPresenter && isPollingEnabled) {
actions.push({
icon: "polling",
2021-08-14 09:32:19 +08:00
dataTest: "polling",
label: formatMessage(pollBtnLabel),
key: this.pollId,
onClick: () => {
if (Session.equals('pollInitiated', true)) {
Session.set('resetPollPanel', true);
}
2021-08-13 02:42:02 +08:00
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: true,
});
2021-08-13 02:42:02 +08:00
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.POLL,
});
Session.set('forcePollOpen', true);
},
})
}
if (!amIPresenter) {
actions.push({
icon: "presentation",
label: formatMessage(takePresenter),
key: this.takePresenterId,
onClick: () => handleTakePresenter(),
});
}
if (amIPresenter && allowExternalVideo) {
actions.push({
icon: !isSharingVideo ? "external-video" : "external-video_off",
label: !isSharingVideo ? intl.formatMessage(intlMessages.startExternalVideoLabel)
: intl.formatMessage(intlMessages.stopExternalVideoLabel),
key: "external-video",
onClick: isSharingVideo ? stopExternalVideoShare : this.handleExternalVideoClick,
2022-01-20 21:03:18 +08:00
dataTest: "shareExternalVideo",
})
}
if (amIPresenter && isSelectRandomUserEnabled) {
actions.push({
icon: "user",
label: intl.formatMessage(intlMessages.selectRandUserLabel),
key: this.selectUserRandId,
onClick: () => mountModal(<RandomUserSelectContainer isSelectedUser={false} />),
dataTest: "selectRandomUser",
})
}
if (amIPresenter && showPushLayout && isLayoutsEnabled()) {
actions.push({
icon: 'send',
label: intl.formatMessage(intlMessages.propagateLayoutLabel),
key: 'propagate layout',
onClick: amIPresenter ? setMeetingLayout : setPushLayout,
2023-02-23 20:05:57 +08:00
dataTest: 'propagateLayout',
});
}
if (isLayoutsEnabled()){
2023-02-23 20:05:57 +08:00
actions.push({
icon: 'send',
label: intl.formatMessage(intlMessages.layoutModal),
key: 'layoutModal',
onClick: () => mountModal(<LayoutModalContainer {...this.props} />),
dataTest: 'layoutModal',
});
}
return actions;
2018-01-17 21:34:35 +08:00
}
makePresentationItems() {
const {
presentations,
setPresentation,
podIds,
} = this.props;
if (!podIds || podIds.length < 1) return [];
// We still have code for other pods from the Flash client. This intentionally only cares
// about the first one because it's the default.
const { podId } = podIds[0];
2021-04-07 22:37:49 +08:00
const presentationItemElements = presentations
.sort((a, b) => (a.name.localeCompare(b.name)))
.map((p) => {
const customStyles = { color: colorPrimary };
return (
{
customStyles: p.current ? customStyles : null,
icon: "file",
iconRight: p.current ? 'check' : null,
selected: p.current ? true : false,
label: p.name,
description: "uploaded presentation file",
key: `uploaded-presentation-${p.id}`,
onClick: () => {
setPresentation(p.id, podId);
},
}
2021-04-07 22:37:49 +08:00
);
});
return presentationItemElements;
}
2016-10-18 05:29:00 +08:00
render() {
2017-09-13 04:47:06 +08:00
const {
intl,
amIPresenter,
amIModerator,
shortcuts: OPEN_ACTIONS_AK,
2019-06-27 00:29:34 +08:00
isMeteorConnected,
2021-05-12 22:07:18 +08:00
isDropdownOpen,
isMobile,
2022-05-13 21:42:19 +08:00
isRTL,
2017-09-13 04:47:06 +08:00
} = this.props;
2017-03-24 23:37:33 +08:00
2018-01-17 21:34:35 +08:00
const availableActions = this.getAvailableActions();
const availablePresentations = this.makePresentationItems();
const children = availablePresentations.length > 1 && amIPresenter
? availablePresentations.concat(availableActions) : availableActions;
2018-01-17 21:34:35 +08:00
if ((!amIPresenter && !amIModerator)
|| availableActions.length === 0
|| !isMeteorConnected) {
return null;
}
2022-05-13 21:42:19 +08:00
const customStyles = { top: '-1rem' };
2016-10-18 05:29:00 +08:00
return (
2021-08-09 01:22:01 +08:00
<BBBMenu
customStyles={!isMobile ? customStyles : null}
2021-08-09 01:22:01 +08:00
accessKey={OPEN_ACTIONS_AK}
trigger={
<Styled.HideDropdownButton
open={isDropdownOpen}
hideLabel
aria-label={intl.formatMessage(intlMessages.actionsLabel)}
2022-01-13 23:11:17 +08:00
data-test="actionsButton"
2016-10-18 05:29:00 +08:00
label={intl.formatMessage(intlMessages.actionsLabel)}
2017-12-12 01:09:09 +08:00
icon="plus"
2016-10-18 05:29:00 +08:00
color="primary"
size="lg"
2017-06-03 03:25:02 +08:00
circle
2016-10-18 05:29:00 +08:00
onClick={() => null}
/>
}
actions={children}
opts={{
2022-10-06 05:54:59 +08:00
id: "actions-dropdown-menu",
keepMounted: true,
transitionDuration: 0,
elevation: 3,
getContentAnchorEl: null,
fullwidth: "true",
2022-05-13 21:42:19 +08:00
anchorOrigin: { vertical: 'top', horizontal: isRTL ? 'right' : 'left' },
transformOrigin: { vertical: 'bottom', horizontal: isRTL ? 'right' : 'left' },
}}
/>
2016-10-18 05:29:00 +08:00
);
}
}
2017-06-07 20:01:18 +08:00
ActionsDropdown.propTypes = propTypes;
ActionsDropdown.defaultProps = defaultProps;
2017-06-07 20:01:18 +08:00
2019-02-22 05:01:39 +08:00
export default withShortcutHelper(withModalMounter(ActionsDropdown), 'openActions');