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

236 lines
5.3 KiB
React
Raw Normal View History

2016-04-29 03:02:51 +08:00
import React, { Component, PropTypes } from 'react';
2016-07-29 03:48:26 +08:00
import { FormattedMessage } from 'react-intl';
2016-07-29 03:48:26 +08:00
import LoadingScreen from '../loading-screen/component';
import KickedScreen from '../kicked-screen/component';
import NotificationsBarContainer from '../notifications-bar/container';
import AudioNotificationContainer from '../audio-notification/container';
import LocalStorage from '/imports/ui/services/storage/local.js';
2016-07-29 03:48:26 +08:00
import Button from '../button/component';
2016-05-03 06:42:54 +08:00
import styles from './styles';
import cx from 'classnames';
2016-04-29 03:02:51 +08:00
const propTypes = {
navbar: PropTypes.element,
sidebar: PropTypes.element,
sidebarRight: PropTypes.element,
media: PropTypes.element,
actionsbar: PropTypes.element,
captions: PropTypes.element,
modal: PropTypes.element,
unreadMessageCount: PropTypes.array,
openChats: PropTypes.array,
2016-04-29 03:02:51 +08:00
};
export default class App extends Component {
2016-09-15 01:48:50 +08:00
constructor(props) {
super(props);
this.state = {
compactUserList: false, //TODO: Change this on userlist resize (?)
};
this.setDefaultSettings = props.setDefaultSettings;
}
setHtmlFontSize(size) {
document.getElementsByTagName('html')[0].style.fontSize = size;
};
componentDidMount() {
this.setDefaultSettings();
this.setHtmlFontSize(this.props.fontSize);
2016-09-15 01:48:50 +08:00
}
renderNavBar() {
2016-04-29 03:02:51 +08:00
const { navbar } = this.props;
2016-05-03 06:42:54 +08:00
if (navbar) {
2016-04-29 03:02:51 +08:00
return (
2017-03-15 23:24:57 +08:00
<div className={styles.navbar}>
2016-04-29 03:02:51 +08:00
{navbar}
2017-03-15 23:24:57 +08:00
</div>
2016-04-29 03:02:51 +08:00
);
}
return false;
}
renderSidebar() {
const { sidebar } = this.props;
2016-04-29 03:02:51 +08:00
2016-05-03 06:42:54 +08:00
if (sidebar) {
2016-04-29 03:02:51 +08:00
return (
<aside className={styles.sidebar}>
2016-04-29 03:02:51 +08:00
{sidebar}
</aside>
);
}
return false;
}
renderUserList() {
2016-09-15 01:48:50 +08:00
let { userList } = this.props;
const { compactUserList } = this.state;
2016-09-15 01:48:50 +08:00
let userListStyle = {};
userListStyle[styles.compact] = compactUserList;
if (userList) {
2016-09-15 01:48:50 +08:00
userList = React.cloneElement(userList, {
compact: compactUserList,
});
return (
2017-03-15 23:24:57 +08:00
<div className={cx(styles.userList, userListStyle)} role="region" aria-label="user list">
{userList}
2017-03-15 23:24:57 +08:00
</div>
);
}
return false;
}
renderChat() {
const { chat } = this.props;
if (chat) {
return (
2017-03-15 23:24:57 +08:00
<div className={styles.chat} role="region" aria-label="chat">
{chat}
2017-03-15 23:24:57 +08:00
</div>
);
}
return false;
}
2016-04-29 03:02:51 +08:00
renderMedia() {
const { media } = this.props;
2016-05-03 06:42:54 +08:00
if (media) {
2016-04-29 03:02:51 +08:00
return (
2017-03-15 23:24:57 +08:00
<div className={styles.media} role="region" aria-label="media">
2016-04-29 03:02:51 +08:00
{media}
2017-03-15 23:24:57 +08:00
</div>
2016-04-29 03:02:51 +08:00
);
}
return false;
}
renderClosedCaptions() {
const { captions } = this.props;
if (captions && this.props.getCaptionsStatus()) {
return (
2017-03-15 23:24:57 +08:00
<div className={styles.closedCaptions} role="region" aria-label="Closed Captions">
{captions}
2017-03-15 23:24:57 +08:00
</div>
);
}
}
renderActionsBar() {
2016-04-29 03:02:51 +08:00
const { actionsbar } = this.props;
2016-05-03 06:42:54 +08:00
if (actionsbar) {
2016-04-29 03:02:51 +08:00
return (
2017-03-15 23:24:57 +08:00
<div className={styles.actionsbar} role="region" aria-label="actions bar">
2016-04-29 03:02:51 +08:00
{actionsbar}
2017-03-15 23:24:57 +08:00
</div>
2016-04-29 03:02:51 +08:00
);
}
return false;
}
2016-05-12 04:43:07 +08:00
renderAudioElement() {
return (
<audio id="remote-media" autoPlay="autoplay"></audio>
2016-05-12 04:43:07 +08:00
);
}
renderModal() {
const { modal } = this.props;
if (modal) {
return (<div>{modal}</div>);
}
return false;
}
playSoundForUnreadMessages() {
const snd = new Audio('/html5client/resources/sounds/notify.mp3');
snd.play();
}
2017-01-17 05:24:21 +08:00
componentDidUpdate(prevProps) {
let { unreadMessageCount, openChats, openChat } = this.props;
unreadMessageCount.forEach((chat, i) => {
2017-01-17 05:24:21 +08:00
// When starting the new chat, if prevProps is undefined or null, it is assigned 0.
if (!prevProps.unreadMessageCount[i]) {
prevProps.unreadMessageCount[i] = 0;
}
2017-01-17 05:24:21 +08:00
// compare openChats(chatID) to chatID of currently opened chat room
if (openChats[i] !== openChat) {
2017-03-09 22:34:33 +08:00
let shouldPlaySound = this.props.applicationSettings.chatAudioNotifications;
if (shouldPlaySound && chat > prevProps.unreadMessageCount[i]) {
this.playSoundForUnreadMessages();
}
}
});
}
2016-04-29 03:02:51 +08:00
render() {
2016-07-29 03:48:26 +08:00
if (this.props.wasKicked) {
return (
<KickedScreen>
<FormattedMessage
id="app.kickMessage"
description="Message when the user is kicked out of the meeting"
defaultMessage="You have been kicked out of the meeting"
/>
<br/><br/>
<Button
label={'OK'}
onClick={this.props.redirectToLogoutUrl}/>
</KickedScreen>
);
}
2016-07-09 07:13:26 +08:00
if (this.props.isLoading) {
2016-07-29 03:48:26 +08:00
return <LoadingScreen/>;
}
2016-04-29 03:02:51 +08:00
return (
2017-03-15 23:24:57 +08:00
<main className={styles.main} role="main">
<AudioNotificationContainer />
<NotificationsBarContainer />
2016-05-03 06:42:54 +08:00
<section className={styles.wrapper}>
{this.renderUserList()}
{this.renderChat()}
2016-05-03 06:42:54 +08:00
<div className={styles.content}>
{this.renderNavBar()}
2016-04-29 03:02:51 +08:00
{this.renderMedia()}
{this.renderActionsBar()}
2016-04-29 03:02:51 +08:00
</div>
{this.renderSidebar()}
2016-12-21 07:54:39 +08:00
{this.renderClosedCaptions()}
2016-04-29 03:02:51 +08:00
</section>
2016-05-12 04:43:07 +08:00
{this.renderAudioElement()}
{this.renderModal()}
2016-04-29 03:02:51 +08:00
</main>
);
}
}
App.propTypes = propTypes;