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

223 lines
4.8 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 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 (?)
};
}
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 (
2016-05-03 06:42:54 +08:00
<header className={styles.navbar}>
2016-04-29 03:02:51 +08:00
{navbar}
</header>
);
}
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 (
<nav className={cx(styles.userList, userListStyle)}>
{userList}
</nav>
);
}
return false;
}
renderChat() {
const { chat } = this.props;
if (chat) {
return (
<section className={styles.chat} role="log">
{chat}
</section>
);
}
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 (
2016-05-03 06:42:54 +08:00
<section className={styles.media}>
2016-04-29 03:02:51 +08:00
{media}
</section>
);
}
return false;
}
renderClosedCaptions() {
const { captions } = this.props;
2017-01-17 05:24:21 +08:00
if (captions && this.props.getCaptionsStatus()) {
return (
<section className={styles.closedCaptions}>
{captions}
</section>
);
}
}
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 (
2016-05-03 06:42:54 +08:00
<section className={styles.actionsbar}>
2016-04-29 03:02:51 +08:00
{actionsbar}
</section>
);
}
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) {
let shouldPlaySound = LocalStorage.getItem('audioNotifChat') || Meteor.settings.public.app.audioChatNotification;
if (shouldPlaySound && chat > prevProps.unreadMessageCount[i]) {
this.playSoundForUnreadMessages();
}
}
});
}
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 (
2016-05-03 06:42:54 +08:00
<main className={styles.main}>
<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.renderClosedCaptions()}
{this.renderActionsBar()}
2016-04-29 03:02:51 +08:00
</div>
{this.renderSidebar()}
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;