bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/app/container.jsx
Oswaldo Acauan 2f741df97b Impl user-session based connections on server. Fix #5150
Implement a connectionId for each user, each time a user try to validate we change their connectionId
and end all other connections of that user.
2018-02-20 11:26:36 -03:00

110 lines
2.9 KiB
JavaScript

import React, { cloneElement } from 'react';
import { withTracker } from 'meteor/react-meteor-data';
import { withRouter } from 'react-router';
import { defineMessages, injectIntl } from 'react-intl';
import PropTypes from 'prop-types';
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';
import ClosedCaptionsContainer from '/imports/ui/components/closed-captions/container';
import {
getFontSize,
getCaptionsStatus,
meetingIsBreakout,
} from './service';
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';
const propTypes = {
navbar: PropTypes.node,
actionsbar: PropTypes.node,
media: PropTypes.node,
location: PropTypes.shape({}).isRequired,
};
const defaultProps = {
navbar: <NavBarContainer />,
actionsbar: <ActionsBarContainer />,
media: <MediaContainer />,
};
const intlMessages = defineMessages({
waitingApprovalMessage: {
id: 'app.guest.waiting',
description: 'Message while a guest is waiting to be approved',
},
});
const AppContainer = (props) => {
// inject location on the navbar container
const {
navbar,
actionsbar,
media,
...otherProps
} = props;
const navbarWithLocation = cloneElement(navbar, { location: props.location });
return (
<App
navbar={navbarWithLocation}
actionsbar={actionsbar}
media={media}
{...otherProps}
/>
);
};
export default withRouter(injectIntl(withModalMounter(withTracker(({ router, intl, baseControls }) => {
const currentUser = Users.findOne({ userId: Auth.userID });
const isMeetingBreakout = meetingIsBreakout();
if (!currentUser.approved) {
baseControls.updateLoadingState(intl.formatMessage(intlMessages.waitingApprovalMessage));
}
// Check if user is removed out of the session
Users.find({ userId: Auth.userID }).observeChanges({
changed(id, fields) {
const hasNewConnection = fields.connectionId !== Meteor.connection._lastSessionId;
if (fields.ejected || hasNewConnection) {
router.push(`/ended/${403}`);
}
},
});
// forcelly logged out when the meeting is ended
Meetings.find({ meetingId: Auth.meetingID }).observeChanges({
removed() {
if (isMeetingBreakout) return;
router.push(`/ended/${410}`);
},
});
// Close the widow when the current breakout room ends
Breakouts.find({ breakoutId: Auth.meetingID }).observeChanges({
removed() {
Auth.clearCredentials().then(window.close);
},
});
return {
closedCaption: getCaptionsStatus() ? <ClosedCaptionsContainer /> : null,
fontSize: getFontSize(),
};
})(AppContainer))));
AppContainer.defaultProps = defaultProps;
AppContainer.propTypes = propTypes;