bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/app/component.jsx

408 lines
12 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { throttle } from 'lodash';
import { defineMessages, injectIntl } from 'react-intl';
import Modal from 'react-modal';
import browserInfo from '/imports/utils/browserInfo';
2021-04-01 01:13:36 +08:00
import deviceInfo from '/imports/utils/deviceInfo';
import PanelManager from '/imports/ui/components/panel-manager/component';
2018-10-12 23:05:53 +08:00
import PollingContainer from '/imports/ui/components/polling/container';
import logger from '/imports/startup/client/logger';
2019-02-27 01:40:01 +08:00
import ActivityCheckContainer from '/imports/ui/components/activity-check/container';
import UserInfoContainer from '/imports/ui/components/user-info/container';
import BreakoutRoomInvitation from '/imports/ui/components/breakout-room/invitation/container';
2017-10-13 02:53:33 +08:00
import ToastContainer from '../toast/container';
2017-04-19 03:06:51 +08:00
import ModalContainer from '../modal/container';
import NotificationsBarContainer from '../notifications-bar/container';
2017-03-28 04:40:44 +08:00
import AudioContainer from '../audio/container';
import ChatAlertContainer from '../chat/alert/container';
2019-03-16 04:07:14 +08:00
import BannerBarContainer from '/imports/ui/components/banner-bar/container';
import WaitingNotifierContainer from '/imports/ui/components/waiting-users/alert/container';
import LockNotifier from '/imports/ui/components/lock-viewers/notify/container';
2020-06-30 10:43:20 +08:00
import StatusNotifier from '/imports/ui/components/status-notifier/container';
import MediaService from '/imports/ui/components/media/service';
2019-06-13 02:03:23 +08:00
import ManyWebcamsNotifier from '/imports/ui/components/video-provider/many-users-notify/container';
2020-02-26 03:29:14 +08:00
import UploaderContainer from '/imports/ui/components/presentation/presentation-uploader/container';
import RandomUserSelectContainer from '/imports/ui/components/modal/random-user/container';
import { withDraggableContext } from '../media/webcam-draggable-overlay/context';
2018-01-08 14:17:18 +08:00
import { styles } from './styles';
2019-11-20 01:49:18 +08:00
import { makeCall } from '/imports/ui/services/api';
import ConnectionStatusService from '/imports/ui/components/connection-status/service';
import { NAVBAR_HEIGHT } from '/imports/ui/components/layout/layout-manager';
2016-04-29 03:02:51 +08:00
const MOBILE_MEDIA = 'only screen and (max-width: 40em)';
const APP_CONFIG = Meteor.settings.public.app;
2019-01-04 01:55:10 +08:00
const DESKTOP_FONT_SIZE = APP_CONFIG.desktopFontSize;
const MOBILE_FONT_SIZE = APP_CONFIG.mobileFontSize;
2019-06-13 04:27:49 +08:00
const ENABLE_NETWORK_MONITORING = Meteor.settings.public.networkMonitoring.enableNetworkMonitoring;
const intlMessages = defineMessages({
userListLabel: {
2017-09-23 01:51:47 +08:00
id: 'app.userList.label',
2017-04-10 23:50:03 +08:00
description: 'Aria-label for Userlist Nav',
},
chatLabel: {
2017-09-23 01:23:25 +08:00
id: 'app.chat.label',
2017-04-19 03:42:55 +08:00
description: 'Aria-label for Chat Section',
},
mediaLabel: {
2017-08-11 00:05:51 +08:00
id: 'app.media.label',
2017-04-19 03:42:55 +08:00
description: 'Aria-label for Media Section',
},
2017-08-11 00:05:51 +08:00
actionsBarLabel: {
id: 'app.actionsBar.label',
2017-04-19 03:42:55 +08:00
description: 'Aria-label for ActionsBar Section',
},
iOSWarning: {
id: 'app.iOSWarning.label',
description: 'message indicating to upgrade ios version',
},
clearedEmoji: {
id: 'app.toast.clearedEmoji.label',
2019-06-01 02:48:41 +08:00
description: 'message for cleared emoji status',
},
setEmoji: {
id: 'app.toast.setEmoji.label',
2019-06-01 02:48:41 +08:00
description: 'message when a user emoji has been set',
},
raisedHand: {
id: 'app.toast.setEmoji.raiseHand',
description: 'toast message for raised hand notification',
},
loweredHand: {
id: 'app.toast.setEmoji.lowerHand',
description: 'toast message for lowered hand notification',
},
meetingMuteOn: {
id: 'app.toast.meetingMuteOn.label',
2019-06-01 02:48:41 +08:00
description: 'message used when meeting has been muted',
},
meetingMuteOff: {
id: 'app.toast.meetingMuteOff.label',
2019-06-01 02:48:41 +08:00
description: 'message used when meeting has been unmuted',
},
pollPublishedLabel: {
id: 'app.whiteboard.annotations.poll',
description: 'message displayed when a poll is published',
},
});
2016-04-29 03:02:51 +08:00
const propTypes = {
navbar: PropTypes.element,
sidebar: PropTypes.element,
media: PropTypes.element,
actionsbar: PropTypes.element,
captions: PropTypes.element,
locale: PropTypes.string,
intl: PropTypes.object.isRequired,
};
const defaultProps = {
navbar: null,
sidebar: null,
media: null,
actionsbar: null,
captions: null,
locale: 'en',
2016-04-29 03:02:51 +08:00
};
const LAYERED_BREAKPOINT = 640;
const isLayeredView = window.matchMedia(`(max-width: ${LAYERED_BREAKPOINT}px)`);
class App extends Component {
constructor() {
super();
2016-09-15 01:48:50 +08:00
this.state = {
enableResize: !window.matchMedia(MOBILE_MEDIA).matches,
2016-09-15 01:48:50 +08:00
};
this.handleWindowResize = throttle(this.handleWindowResize).bind(this);
this.shouldAriaHide = this.shouldAriaHide.bind(this);
this.renderMedia = withDraggableContext(this.renderMedia.bind(this));
}
componentDidMount() {
const {
locale, notify, intl, validIOSVersion, startBandwidthMonitoring, handleNetworkConnection,
} = this.props;
const { browserName } = browserInfo;
2021-04-01 01:13:36 +08:00
const { isMobile, osName } = deviceInfo;
2017-07-04 22:32:22 +08:00
MediaService.setSwapLayout();
Modal.setAppElement('#app');
2017-07-04 22:32:22 +08:00
document.getElementsByTagName('html')[0].lang = locale;
2021-04-01 01:13:36 +08:00
document.getElementsByTagName('html')[0].style.fontSize = isMobile ? MOBILE_FONT_SIZE : DESKTOP_FONT_SIZE;
const body = document.getElementsByTagName('body')[0];
body.classList.add(`browser-${browserName.toLowerCase()}`);
2021-04-01 01:13:36 +08:00
body.classList.add(`os-${osName.split(' ').shift().toLowerCase()}`);
if (!validIOSVersion()) {
notify(
intl.formatMessage(intlMessages.iOSWarning), 'error', 'warning',
);
}
this.handleWindowResize();
window.addEventListener('resize', this.handleWindowResize, false);
window.ondragover = function (e) { e.preventDefault(); };
window.ondrop = function (e) { e.preventDefault(); };
2019-06-13 04:27:49 +08:00
if (ENABLE_NETWORK_MONITORING) {
if (navigator.connection) {
handleNetworkConnection();
navigator.connection.addEventListener('change', handleNetworkConnection);
}
startBandwidthMonitoring();
2019-03-12 08:34:34 +08:00
}
2021-04-01 01:13:36 +08:00
if (isMobile) makeCall('setMobileUser');
2019-11-20 01:49:18 +08:00
ConnectionStatusService.startRoundTripTime();
logger.info({ logCode: 'app_component_componentdidmount' }, 'Client loaded successfully');
}
componentDidUpdate(prevProps) {
const {
meetingMuted,
notify,
currentUserEmoji,
intl,
hasPublishedPoll,
randomlySelectedUser,
currentUserId,
mountModal,
} = this.props;
if (randomlySelectedUser === currentUserId) mountModal(<RandomUserSelectContainer />);
2019-06-01 02:36:52 +08:00
if (prevProps.currentUserEmoji.status !== currentUserEmoji.status) {
const formattedEmojiStatus = intl.formatMessage({ id: `app.actionsBar.emojiMenu.${currentUserEmoji.status}Label` })
|| currentUserEmoji.status;
const raisedHand = currentUserEmoji.status === 'raiseHand';
let statusLabel = '';
if (currentUserEmoji.status === 'none') {
statusLabel = prevProps.currentUserEmoji.status === 'raiseHand'
? intl.formatMessage(intlMessages.loweredHand)
: intl.formatMessage(intlMessages.clearedEmoji);
} else {
statusLabel = raisedHand
? intl.formatMessage(intlMessages.raisedHand)
: intl.formatMessage(intlMessages.setEmoji, ({ 0: formattedEmojiStatus }));
}
2019-06-01 02:36:52 +08:00
notify(
statusLabel,
2019-06-01 02:36:52 +08:00
'info',
currentUserEmoji.status === 'none'
? 'clear_status'
: 'user',
);
}
if (!prevProps.meetingMuted && meetingMuted) {
notify(
intl.formatMessage(intlMessages.meetingMuteOn), 'info', 'mute',
);
}
if (prevProps.meetingMuted && !meetingMuted) {
notify(
intl.formatMessage(intlMessages.meetingMuteOff), 'info', 'unmute',
);
}
if (!prevProps.hasPublishedPoll && hasPublishedPoll) {
notify(
intl.formatMessage(intlMessages.pollPublishedLabel), 'info', 'polling',
);
}
}
componentWillUnmount() {
const { handleNetworkConnection } = this.props;
window.removeEventListener('resize', this.handleWindowResize, false);
2019-05-25 06:41:30 +08:00
if (navigator.connection) {
navigator.connection.addEventListener('change', handleNetworkConnection, false);
2019-05-25 06:41:30 +08:00
}
ConnectionStatusService.stopRoundTripTime();
}
handleWindowResize() {
const { enableResize } = this.state;
const shouldEnableResize = !window.matchMedia(MOBILE_MEDIA).matches;
if (enableResize === shouldEnableResize) return;
this.setState({ enableResize: shouldEnableResize });
2016-09-15 01:48:50 +08:00
}
shouldAriaHide() {
2019-05-16 05:13:05 +08:00
const { openPanel, isPhone } = this.props;
return openPanel !== '' && (isPhone || isLayeredView.matches);
2019-03-12 08:34:34 +08:00
}
2018-11-20 07:29:48 +08:00
renderPanel() {
const { enableResize } = this.state;
2019-07-16 03:15:58 +08:00
const { openPanel, isRTL } = this.props;
2018-09-15 01:50:18 +08:00
return (
<PanelManager
{...{
openPanel,
2018-12-18 23:15:51 +08:00
enableResize,
2019-07-16 03:15:58 +08:00
isRTL,
}}
shouldAriaHide={this.shouldAriaHide}
/>
2018-09-15 01:50:18 +08:00
);
}
renderNavBar() {
2016-04-29 03:02:51 +08:00
const { navbar } = this.props;
2017-03-17 00:52:43 +08:00
if (!navbar) return null;
2016-04-29 03:02:51 +08:00
2017-03-17 00:52:43 +08:00
return (
<header
className={styles.navbar}
style={{
height: NAVBAR_HEIGHT,
}}
>
2017-03-17 00:52:43 +08:00
{navbar}
</header>
);
2016-04-29 03:02:51 +08:00
}
renderSidebar() {
const { sidebar } = this.props;
2016-04-29 03:02:51 +08:00
2017-03-17 00:52:43 +08:00
if (!sidebar) return null;
2016-04-29 03:02:51 +08:00
2017-03-17 00:52:43 +08:00
return (
<aside className={styles.sidebar}>
2017-03-17 00:52:43 +08:00
{sidebar}
</aside>
);
}
renderCaptions() {
const { captions } = this.props;
if (!captions) return null;
return (
<div className={styles.captionsWrapper}>
{captions}
2017-05-13 03:17:08 +08:00
</div>
2017-03-17 00:52:43 +08:00
);
2016-04-29 03:02:51 +08:00
}
renderMedia() {
const {
media,
intl,
} = this.props;
2016-04-29 03:02:51 +08:00
2017-03-17 00:52:43 +08:00
if (!media) return null;
2016-04-29 03:02:51 +08:00
2017-03-17 00:52:43 +08:00
return (
<section
className={styles.media}
2017-06-03 03:25:02 +08:00
aria-label={intl.formatMessage(intlMessages.mediaLabel)}
aria-hidden={this.shouldAriaHide()}
2017-06-03 03:25:02 +08:00
>
{media}
{this.renderCaptions()}
2017-03-17 00:52:43 +08:00
</section>
);
}
renderActionsBar() {
const {
actionsbar,
intl,
} = this.props;
2016-04-29 03:02:51 +08:00
2017-03-17 00:52:43 +08:00
if (!actionsbar) return null;
2016-04-29 03:02:51 +08:00
2016-05-12 04:43:07 +08:00
return (
<section
className={styles.actionsbar}
2017-08-11 00:05:51 +08:00
aria-label={intl.formatMessage(intlMessages.actionsBarLabel)}
aria-hidden={this.shouldAriaHide()}
2017-06-03 03:25:02 +08:00
>
{actionsbar}
2017-03-17 00:52:43 +08:00
</section>
2016-05-12 04:43:07 +08:00
);
}
2019-02-27 01:40:01 +08:00
renderActivityCheck() {
const { User } = this.props;
const { inactivityCheck, responseDelay } = User;
return (inactivityCheck ? (
<ActivityCheckContainer
inactivityCheck={inactivityCheck}
responseDelay={responseDelay}
/>) : null);
}
renderUserInformation() {
const { UserInfo, User } = this.props;
return (UserInfo.length > 0 ? (
<UserInfoContainer
UserInfo={UserInfo}
requesterUserId={User.userId}
meetingId={User.meetingId}
/>) : null);
}
render() {
const {
customStyle, customStyleUrl, openPanel, layoutContextState,
} = this.props;
2016-04-29 03:02:51 +08:00
return (
2016-05-03 06:42:54 +08:00
<main className={styles.main}>
2019-02-27 01:40:01 +08:00
{this.renderActivityCheck()}
{this.renderUserInformation()}
2019-03-16 04:07:14 +08:00
<BannerBarContainer />
<NotificationsBarContainer />
2016-05-03 06:42:54 +08:00
<section className={styles.wrapper}>
<div className={openPanel ? styles.content : styles.noPanelContent}>
{this.renderNavBar()}
2016-04-29 03:02:51 +08:00
{this.renderMedia()}
{this.renderActionsBar()}
2016-04-29 03:02:51 +08:00
</div>
2018-11-20 07:29:48 +08:00
{this.renderPanel()}
{this.renderSidebar()}
2016-04-29 03:02:51 +08:00
</section>
2020-03-10 23:07:59 +08:00
<UploaderContainer />
<BreakoutRoomInvitation />
{!layoutContextState.presentationIsFullscreen && !layoutContextState.screenShareIsFullscreen && <PollingContainer />}
2017-04-19 03:06:51 +08:00
<ModalContainer />
<AudioContainer />
<ToastContainer rtl />
<ChatAlertContainer />
<WaitingNotifierContainer />
<LockNotifier />
2020-06-30 10:43:20 +08:00
<StatusNotifier status="raiseHand" />
2019-06-13 02:03:23 +08:00
<ManyWebcamsNotifier />
{customStyleUrl ? <link rel="stylesheet" type="text/css" href={customStyleUrl} /> : null}
{customStyle ? <link rel="stylesheet" type="text/css" href={`data:text/css;charset=UTF-8,${encodeURIComponent(customStyle)}`} /> : null}
2016-04-29 03:02:51 +08:00
</main>
);
}
}
App.propTypes = propTypes;
App.defaultProps = defaultProps;
export default injectIntl(App);