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

430 lines
14 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import PropTypes from 'prop-types';
2019-01-12 08:20:04 +08:00
import EndMeetingConfirmationContainer from '/imports/ui/components/end-meeting-confirmation/container';
import { makeCall } from '/imports/ui/services/api';
2016-12-08 23:40:11 +08:00
import AboutContainer from '/imports/ui/components/about/container';
import MobileAppModal from '/imports/ui/components/mobile-app-modal/container';
import SettingsMenuContainer from '/imports/ui/components/settings/container';
2022-02-15 23:38:55 +08:00
import BBBMenu from '/imports/ui/components/common/menu/component';
2018-04-27 01:24:25 +08:00
import ShortcutHelpComponent from '/imports/ui/components/shortcut-help/component';
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
import FullscreenService from '/imports/ui/components/common/fullscreen-button/service';
import { colorDanger, colorWhite } from '/imports/ui/stylesheets/styled-components/palette';
2021-12-10 22:55:37 +08:00
import Styled from './styles';
import browserInfo from '/imports/utils/browserInfo';
import deviceInfo from '/imports/utils/deviceInfo';
2017-10-06 20:50:01 +08:00
2016-09-22 03:49:31 +08:00
const intlMessages = defineMessages({
optionsLabel: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.optionsLabel',
2017-04-10 23:50:03 +08:00
description: 'Options button label',
2016-09-22 03:49:31 +08:00
},
fullscreenLabel: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.fullscreenLabel',
2017-04-10 23:50:03 +08:00
description: 'Make fullscreen option label',
2016-09-22 03:49:31 +08:00
},
settingsLabel: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.settingsLabel',
2017-04-10 23:50:03 +08:00
description: 'Open settings option label',
2016-09-22 03:49:31 +08:00
},
2016-12-08 05:14:14 +08:00
aboutLabel: {
id: 'app.navBar.settingsDropdown.aboutLabel',
2017-04-10 23:50:03 +08:00
description: 'About option label',
2016-12-08 05:14:14 +08:00
},
aboutDesc: {
id: 'app.navBar.settingsDropdown.aboutDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes about option',
2016-12-08 05:14:14 +08:00
},
2016-09-22 03:49:31 +08:00
leaveSessionLabel: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.leaveSessionLabel',
2017-04-10 23:50:03 +08:00
description: 'Leave session button label',
2016-09-22 03:49:31 +08:00
},
fullscreenDesc: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.fullscreenDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes fullscreen option',
},
settingsDesc: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.settingsDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes settings option',
},
leaveSessionDesc: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.leaveSessionDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes leave session option',
},
2017-08-11 00:05:51 +08:00
exitFullscreenDesc: {
id: 'app.navBar.settingsDropdown.exitFullscreenDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes exit fullscreen option',
2017-02-14 00:21:53 +08:00
},
2017-08-11 00:05:51 +08:00
exitFullscreenLabel: {
id: 'app.navBar.settingsDropdown.exitFullscreenLabel',
2017-04-10 23:50:03 +08:00
description: 'Exit fullscreen option label',
2017-02-14 00:21:53 +08:00
},
hotkeysLabel: {
id: 'app.navBar.settingsDropdown.hotkeysLabel',
2018-05-03 11:33:28 +08:00
description: 'Hotkeys options label',
},
hotkeysDesc: {
id: 'app.navBar.settingsDropdown.hotkeysDesc',
2018-05-03 11:33:28 +08:00
description: 'Describes hotkeys option',
},
helpLabel: {
id: 'app.navBar.settingsDropdown.helpLabel',
description: 'Help options label',
},
openAppLabel: {
id: 'app.navBar.settingsDropdown.openAppLabel',
description: 'Open mobile app label',
},
helpDesc: {
id: 'app.navBar.settingsDropdown.helpDesc',
description: 'Describes help option',
},
2019-01-12 08:20:04 +08:00
endMeetingLabel: {
id: 'app.navBar.settingsDropdown.endMeetingLabel',
description: 'End meeting options label',
},
endMeetingDesc: {
id: 'app.navBar.settingsDropdown.endMeetingDesc',
description: 'Describes settings option closing the current meeting',
},
startCaption: {
id: 'app.audio.captions.button.start',
description: 'Start audio captions',
},
stopCaption: {
id: 'app.audio.captions.button.stop',
description: 'Stop audio captions',
},
2016-09-22 03:49:31 +08:00
});
const propTypes = {
2021-08-14 01:04:42 +08:00
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
handleToggleFullscreen: PropTypes.func.isRequired,
noIOSFullscreen: PropTypes.bool,
amIModerator: PropTypes.bool,
shortcuts: PropTypes.string,
2019-05-14 22:28:18 +08:00
isBreakoutRoom: PropTypes.bool,
2019-06-27 00:29:34 +08:00
isMeteorConnected: PropTypes.bool.isRequired,
2021-08-14 01:04:42 +08:00
isDropdownOpen: PropTypes.bool,
audioCaptionsEnabled: PropTypes.bool.isRequired,
audioCaptionsActive: PropTypes.bool.isRequired,
audioCaptionsSet: PropTypes.func.isRequired,
isMobile: PropTypes.bool.isRequired,
};
const defaultProps = {
noIOSFullscreen: true,
amIModerator: false,
shortcuts: '',
2019-05-14 22:28:18 +08:00
isBreakoutRoom: false,
2021-08-14 01:04:42 +08:00
isDropdownOpen: false,
};
const ALLOW_FULLSCREEN = Meteor.settings.public.app.allowFullscreen;
const BBB_TABLET_APP_CONFIG = Meteor.settings.public.app.bbbTabletApp;
const { isSafari, isTabletApp } = browserInfo;
const FULLSCREEN_CHANGE_EVENT = isSafari ? 'webkitfullscreenchange' : 'fullscreenchange';
class SettingsDropdown extends PureComponent {
constructor(props) {
super(props);
this.state = {
isAboutModalOpen: false,
isShortcutHelpModalOpen: false,
isSettingsMenuModalOpen: false,
isEndMeetingConfirmationModalOpen: false,
isMobileAppModalOpen:false,
2019-07-27 00:48:51 +08:00
isFullscreen: false,
};
// Set the logout code to 680 because it's not a real code and can be matched on the other side
this.LOGOUT_CODE = '680';
this.leaveSession = this.leaveSession.bind(this);
2019-07-27 00:48:51 +08:00
this.onFullscreenChange = this.onFullscreenChange.bind(this);
this.setSettingsMenuModalIsOpen = this.setSettingsMenuModalIsOpen.bind(this);
this.setEndMeetingConfirmationModalIsOpen = this.setEndMeetingConfirmationModalIsOpen.bind(this);
this.setMobileAppModalIsOpen = this.setMobileAppModalIsOpen.bind(this);
this.setAboutModalIsOpen = this.setAboutModalIsOpen.bind(this);
this.setShortcutHelpModalIsOpen = this.setShortcutHelpModalIsOpen.bind(this);
2019-07-27 00:48:51 +08:00
}
componentDidMount() {
document.documentElement.addEventListener(FULLSCREEN_CHANGE_EVENT, this.onFullscreenChange);
2019-07-30 23:03:29 +08:00
}
componentWillUnmount() {
document.documentElement.removeEventListener(FULLSCREEN_CHANGE_EVENT, this.onFullscreenChange);
2017-12-16 14:41:54 +08:00
}
2019-07-27 00:48:51 +08:00
onFullscreenChange() {
const { isFullscreen } = this.state;
const newIsFullscreen = FullscreenService.isFullScreen(document.documentElement);
if (isFullscreen !== newIsFullscreen) {
this.setState({ isFullscreen: newIsFullscreen });
}
}
getFullscreenItem(menuItems) {
const {
intl,
noIOSFullscreen,
handleToggleFullscreen,
} = this.props;
2019-07-27 00:48:51 +08:00
const { isFullscreen } = this.state;
if (noIOSFullscreen || !ALLOW_FULLSCREEN) return null;
2018-05-09 05:37:58 +08:00
let fullscreenLabel = intl.formatMessage(intlMessages.fullscreenLabel);
let fullscreenDesc = intl.formatMessage(intlMessages.fullscreenDesc);
let fullscreenIcon = 'fullscreen';
2016-09-02 04:19:37 +08:00
if (isFullscreen) {
fullscreenLabel = intl.formatMessage(intlMessages.exitFullscreenLabel);
fullscreenDesc = intl.formatMessage(intlMessages.exitFullscreenDesc);
fullscreenIcon = 'exit_fullscreen';
}
2018-05-09 05:37:58 +08:00
return (
menuItems.push(
{
2021-08-14 01:04:42 +08:00
key: 'list-item-fullscreen',
icon: fullscreenIcon,
label: fullscreenLabel,
description: fullscreenDesc,
2021-08-14 01:04:42 +08:00
onClick: handleToggleFullscreen,
},
)
2018-12-06 01:42:31 +08:00
);
}
2019-05-25 05:26:00 +08:00
leaveSession() {
makeCall('userLeftMeeting');
// we don't check askForFeedbackOnLogout here,
// it is checked in meeting-ended component
Session.set('codeError', this.LOGOUT_CODE);
2019-05-25 05:26:00 +08:00
}
setAboutModalIsOpen(value) {
this.setState({isAboutModalOpen: value})
}
setShortcutHelpModalIsOpen(value) {
this.setState({isShortcutHelpModalOpen: value})
}
setSettingsMenuModalIsOpen(value) {
this.setState({isSettingsMenuModalOpen: value})
}
setEndMeetingConfirmationModalIsOpen(value) {
this.setState({isEndMeetingConfirmationModalOpen: value})
}
setMobileAppModalIsOpen(value) {
this.setState({isMobileAppModalOpen: value})
}
renderMenuItems() {
const {
intl, amIModerator, isBreakoutRoom, isMeteorConnected, audioCaptionsEnabled,
audioCaptionsActive, audioCaptionsSet, isMobile,
} = this.props;
const { isIos } = deviceInfo;
2019-05-14 22:28:18 +08:00
const allowedToEndMeeting = amIModerator && !isBreakoutRoom;
const {
showHelpButton: helpButton,
helpLink,
allowLogout: allowLogoutSetting,
} = Meteor.settings.public.app;
this.menuItems = [];
2021-08-14 01:04:42 +08:00
this.getFullscreenItem(this.menuItems);
this.menuItems.push(
{
2021-08-14 01:04:42 +08:00
key: 'list-item-settings',
icon: 'settings',
dataTest: 'settings',
label: intl.formatMessage(intlMessages.settingsLabel),
description: intl.formatMessage(intlMessages.settingsDesc),
onClick: () => this.setSettingsMenuModalIsOpen(true),
},
{
2021-08-14 01:04:42 +08:00
key: 'list-item-about',
icon: 'about',
dataTest: 'aboutModal',
label: intl.formatMessage(intlMessages.aboutLabel),
description: intl.formatMessage(intlMessages.aboutDesc),
onClick: () => this.setAboutModalIsOpen(true),
2021-08-14 01:04:42 +08:00
},
);
2021-08-14 00:53:04 +08:00
if (helpButton) {
this.menuItems.push(
{
2021-08-14 01:04:42 +08:00
key: 'list-item-help',
icon: 'help',
iconRight: 'popout_window',
label: intl.formatMessage(intlMessages.helpLabel),
2022-09-07 00:52:45 +08:00
dataTest: 'helpButton',
description: intl.formatMessage(intlMessages.helpDesc),
2021-08-14 01:04:42 +08:00
onClick: () => window.open(`${helpLink}`),
},
);
}
2021-08-14 01:04:42 +08:00
if (isIos &&
!isTabletApp &&
BBB_TABLET_APP_CONFIG.enabled == true &&
BBB_TABLET_APP_CONFIG.iosAppStoreUrl !== '') {
this.menuItems.push(
{
key: 'list-item-help',
icon: 'popout_window',
label: intl.formatMessage(intlMessages.openAppLabel),
onClick: () => this.setMobileAppModalIsOpen(true),
}
);
}
if (audioCaptionsEnabled && isMobile) {
this.menuItems.push(
{
key: 'audioCaptions',
dataTest: 'audioCaptions',
icon: audioCaptionsActive ? 'closed_caption_stop' : 'closed_caption',
label: intl.formatMessage(
audioCaptionsActive ? intlMessages.stopCaption : intlMessages.startCaption,
),
onClick: () => audioCaptionsSet(!audioCaptionsActive),
},
);
}
this.menuItems.push(
{
2021-08-14 01:04:42 +08:00
key: 'list-item-shortcuts',
icon: 'shortcuts',
label: intl.formatMessage(intlMessages.hotkeysLabel),
description: intl.formatMessage(intlMessages.hotkeysDesc),
onClick: () => this.setShortcutHelpModalIsOpen(true),
2021-08-14 01:04:42 +08:00
divider: true,
},
);
if (allowLogoutSetting && isMeteorConnected) {
this.menuItems.push(
{
key: 'list-item-logout',
dataTest: 'logout',
icon: 'logout',
label: intl.formatMessage(intlMessages.leaveSessionLabel),
description: intl.formatMessage(intlMessages.leaveSessionDesc),
onClick: () => this.leaveSession(),
2021-08-14 01:04:42 +08:00
},
);
2021-08-14 00:53:04 +08:00
}
if (allowedToEndMeeting && isMeteorConnected) {
const customStyles = { background: colorDanger, color: colorWhite };
this.menuItems.push(
{
key: 'list-item-end-meeting',
icon: 'application',
label: intl.formatMessage(intlMessages.endMeetingLabel),
description: intl.formatMessage(intlMessages.endMeetingDesc),
customStyles,
onClick: () => this.setEndMeetingConfirmationModalIsOpen(true),
2021-08-14 01:04:42 +08:00
},
);
2021-08-14 00:53:04 +08:00
}
return this.menuItems;
2017-12-16 14:41:54 +08:00
}
2017-02-14 00:21:53 +08:00
renderModal(isOpen, setIsOpen, priority, Component, otherOptions) {
return isOpen ? <Component
{...{
...otherOptions,
onRequestClose: () => setIsOpen(false),
priority,
setIsOpen,
isOpen
}}
/> : null
}
2017-12-16 14:41:54 +08:00
render() {
const {
intl,
shortcuts: OPEN_OPTIONS_AK,
isDropdownOpen,
isMobile,
2022-05-13 21:42:19 +08:00
isRTL,
} = this.props;
2017-02-14 00:21:53 +08:00
const { isAboutModalOpen, isShortcutHelpModalOpen, isSettingsMenuModalOpen,
isEndMeetingConfirmationModalOpen, isMobileAppModalOpen, } = this.state;
2022-05-13 21:42:19 +08:00
const customStyles = { top: '1rem' };
2021-08-14 01:04:42 +08:00
return (
<>
<BBBMenu
accessKey={OPEN_OPTIONS_AK}
customStyles={!isMobile ? customStyles : null}
trigger={(
<Styled.DropdownButton
state={isDropdownOpen ? 'open' : 'closed'}
label={intl.formatMessage(intlMessages.optionsLabel)}
icon="more"
data-test="optionsButton"
color="dark"
size="md"
circle
hideLabel
// FIXME: Without onClick react proptypes keep warning
// even after the DropdownTrigger inject an onClick handler
onClick={() => null}
/>
)}
actions={this.renderMenuItems()}
opts={{
id: 'app-settings-dropdown-menu',
keepMounted: true,
transitionDuration: 0,
elevation: 3,
2023-05-10 09:31:48 +08:00
getcontentanchorel: null,
fullwidth: 'true',
anchorOrigin: { vertical: 'bottom', horizontal: isRTL ? 'left' : 'right' },
transformorigin: { vertical: 'top', horizontal: isRTL ? 'left' : 'right' },
}}
/>
{this.renderModal(isAboutModalOpen, this.setAboutModalIsOpen, "low",
AboutContainer)}
{this.renderModal(isShortcutHelpModalOpen, this.setShortcutHelpModalIsOpen,
"low", ShortcutHelpComponent)}
{this.renderModal(isSettingsMenuModalOpen, this.setSettingsMenuModalIsOpen,
"low", SettingsMenuContainer)}
{this.renderModal(isEndMeetingConfirmationModalOpen, this.setEndMeetingConfirmationModalIsOpen,
"low", EndMeetingConfirmationContainer)}
{this.renderModal(isMobileAppModalOpen, this.setMobileAppModalIsOpen, "low",
MobileAppModal)}
</>
2016-09-02 04:19:37 +08:00
);
}
}
SettingsDropdown.propTypes = propTypes;
SettingsDropdown.defaultProps = defaultProps;
export default withShortcutHelper(injectIntl(SettingsDropdown), 'openOptions');