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

125 lines
3.4 KiB
React
Raw Normal View History

2017-07-14 22:18:07 +08:00
import React, { cloneElement } from 'react';
2016-04-29 03:02:51 +08:00
import { createContainer } from 'meteor/react-meteor-data';
import { withRouter } from 'react-router';
import { defineMessages, injectIntl } from 'react-intl';
2017-10-06 22:58:21 +08:00
import PropTypes from 'prop-types';
2017-07-14 22:18:07 +08:00
import Auth from '/imports/ui/services/auth';
import Users from '/imports/api/users';
import Breakouts from '/imports/api/breakouts';
import Meetings from '/imports/api/meetings';
2017-07-14 22:18:07 +08:00
import ClosedCaptionsContainer from '/imports/ui/components/closed-captions/container';
import {
getFontSize,
getCaptionsStatus,
2017-10-06 22:58:21 +08:00
meetingIsBreakout,
} from './service';
2017-04-19 03:06:51 +08:00
import { withModalMounter } from '../modal/service';
import App from './component';
import NavBarContainer from '../nav-bar/container';
import ActionsBarContainer from '../actions-bar/container';
import MediaContainer from '../media/container';
2017-10-06 22:58:21 +08:00
const propTypes = {
navbar: PropTypes.node,
actionsbar: PropTypes.node,
media: PropTypes.node,
location: PropTypes.object.isRequired,
};
2016-04-29 03:02:51 +08:00
const defaultProps = {
2016-07-21 22:24:50 +08:00
navbar: <NavBarContainer />,
2016-07-23 02:47:54 +08:00
actionsbar: <ActionsBarContainer />,
2016-07-21 22:24:50 +08:00
media: <MediaContainer />,
2016-04-29 03:02:51 +08:00
};
const intlMessages = defineMessages({
kickedMessage: {
id: 'app.error.kicked',
description: 'Message when the user is kicked out of the meeting',
},
2017-07-14 22:18:07 +08:00
waitingApprovalMessage: {
id: 'app.guest.waiting',
description: 'Message while a guest is waiting to be approved',
},
endMeetingMessage: {
id: 'app.error.meeting.ended',
description: 'You have logged out of the conference',
},
});
2017-07-14 22:18:07 +08:00
const AppContainer = (props) => {
// inject location on the navbar container
2017-10-06 22:58:21 +08:00
const {
navbar,
actionsbar,
media,
...otherProps
} = props;
const navbarWithLocation = cloneElement(navbar, { location: props.location });
2016-07-21 22:24:50 +08:00
2017-07-14 22:18:07 +08:00
return (
2017-10-06 22:58:21 +08:00
<App
navbar={navbarWithLocation}
actionsbar={actionsbar}
media={media}
{...otherProps}
/>
2017-07-14 22:18:07 +08:00
);
};
2017-04-19 03:06:51 +08:00
export default withRouter(injectIntl(withModalMounter(createContainer((
2017-07-14 22:18:07 +08:00
{ router, intl, baseControls }) => {
const currentUser = Users.findOne({ userId: Auth.userID });
if (!currentUser.approved) {
baseControls.updateLoadingState(intl.formatMessage(intlMessages.waitingApprovalMessage));
}
2017-07-18 00:38:18 +08:00
2017-07-06 06:56:13 +08:00
// Displayed error messages according to the mode (kicked, end meeting)
2017-07-18 00:38:18 +08:00
const sendToError = (code, message) => {
2017-07-06 06:56:13 +08:00
Auth.clearCredentials()
.then(() => {
router.push(`/error/${code}`);
baseControls.updateErrorState(message);
2017-07-06 06:56:13 +08:00
});
};
2017-07-14 22:18:07 +08:00
// Check if user is kicked out of the session
2017-06-03 03:25:02 +08:00
Users.find({ userId: Auth.userID }).observeChanges({
changed(id, fields) {
if (fields.ejected) {
sendToError(403, intl.formatMessage(intlMessages.kickedMessage));
2017-06-03 03:25:02 +08:00
}
},
});
2017-07-06 06:56:13 +08:00
// forcelly logged out when the meeting is ended
Meetings.find({ meetingId: Auth.meetingID }).observeChanges({
2017-07-18 00:38:18 +08:00
removed() {
2017-10-06 22:58:21 +08:00
if (!meetingIsBreakout) {
sendToError(410, intl.formatMessage(intlMessages.endMeetingMessage));
}
2017-06-03 03:25:02 +08:00
},
});
2017-07-06 06:56:13 +08:00
// Close the widow when the current breakout room ends
2017-08-12 04:17:35 +08:00
Breakouts.find({ breakoutId: Auth.meetingID }).observeChanges({
2017-07-14 22:18:07 +08:00
removed() {
2017-06-03 03:25:02 +08:00
Auth.clearCredentials().then(window.close);
},
});
2017-06-03 03:25:02 +08:00
return {
closedCaption: getCaptionsStatus() ? <ClosedCaptionsContainer /> : null,
fontSize: getFontSize(),
};
}, AppContainer))));
AppContainer.defaultProps = defaultProps;
2017-10-06 22:58:21 +08:00
AppContainer.propTypes = propTypes;