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

242 lines
6.3 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { throttle } from 'lodash';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
import Modal from 'react-modal';
import browser from 'browser-detect';
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';
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';
2018-01-08 14:17:18 +08:00
import { styles } from './styles';
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;
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',
},
});
2016-04-29 03:02:51 +08:00
const propTypes = {
navbar: PropTypes.element,
sidebar: PropTypes.element,
media: PropTypes.element,
actionsbar: PropTypes.element,
closedCaption: PropTypes.element,
userListIsOpen: PropTypes.bool.isRequired,
chatIsOpen: PropTypes.bool.isRequired,
locale: PropTypes.string,
intl: intlShape.isRequired,
};
const defaultProps = {
navbar: null,
sidebar: null,
media: null,
actionsbar: null,
closedCaption: null,
locale: 'en',
2016-04-29 03:02:51 +08:00
};
class App extends Component {
constructor() {
super();
2017-03-10 03:50:21 +08:00
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);
}
componentDidMount() {
const { locale } = this.props;
const BROWSER_RESULTS = browser();
const isMobileBrowser = BROWSER_RESULTS.mobile || BROWSER_RESULTS.os.includes('Android');
2017-07-04 22:32:22 +08:00
Modal.setAppElement('#app');
2017-07-04 22:32:22 +08:00
document.getElementsByTagName('html')[0].lang = locale;
document.getElementsByTagName('html')[0].style.fontSize = isMobileBrowser ? MOBILE_FONT_SIZE : DESKTOP_FONT_SIZE;
const body = document.getElementsByTagName('body')[0];
if (BROWSER_RESULTS && BROWSER_RESULTS.name) {
body.classList.add(`browser-${BROWSER_RESULTS.name}`);
}
if (BROWSER_RESULTS && BROWSER_RESULTS.os) {
body.classList.add(`os-${BROWSER_RESULTS.os.split(' ').shift().toLowerCase()}`);
}
this.handleWindowResize();
window.addEventListener('resize', this.handleWindowResize, false);
logger.info({ logCode: 'app_component_componentdidmount' }, 'Client loaded successfully');
}
componentWillUnmount() {
window.removeEventListener('resize', this.handleWindowResize, false);
}
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
}
2018-11-20 07:29:48 +08:00
renderPanel() {
const { enableResize } = this.state;
const { openPanel } = this.props;
2018-09-15 01:50:18 +08:00
return (
<PanelManager
{...{
openPanel,
2018-12-18 23:15:51 +08:00
enableResize,
}}
/>
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}>
{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>
);
}
renderClosedCaption() {
const { closedCaption } = this.props;
if (!closedCaption) return null;
return (
<div className={styles.closedCaptionBox}>
{closedCaption}
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, chatIsOpen, userListIsOpen,
} = 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={userListIsOpen || chatIsOpen}
2017-06-03 03:25:02 +08:00
>
{media}
{this.renderClosedCaption()}
2017-03-17 00:52:43 +08:00
</section>
);
}
renderActionsBar() {
const {
actionsbar, intl, userListIsOpen, chatIsOpen,
} = 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={userListIsOpen || chatIsOpen}
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);
}
render() {
const {
customStyle, customStyleUrl, openPanel,
} = this.props;
2016-07-29 03:48:26 +08:00
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()}
<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>
2018-10-12 23:05:53 +08:00
<PollingContainer />
2017-04-19 03:06:51 +08:00
<ModalContainer />
<AudioContainer />
2017-10-13 02:53:33 +08:00
<ToastContainer />
<ChatAlertContainer />
{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);