2017-03-11 02:33:46 +08:00
|
|
|
import React, { Component } from 'react';
|
2018-01-08 12:44:42 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
2017-06-06 20:33:53 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-11 02:33:46 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import AppContainer from '/imports/ui/components/app/container';
|
2017-03-11 04:47:23 +08:00
|
|
|
import ErrorScreen from '/imports/ui/components/error-screen/component';
|
2017-12-15 03:03:34 +08:00
|
|
|
import MeetingEnded from '/imports/ui/components/meeting-ended/component';
|
2017-03-11 02:33:46 +08:00
|
|
|
import LoadingScreen from '/imports/ui/components/loading-screen/component';
|
2017-04-06 20:36:59 +08:00
|
|
|
import Settings from '/imports/ui/services/settings';
|
2018-01-25 19:07:32 +08:00
|
|
|
import AudioManager from '/imports/ui/services/audio-manager';
|
2018-07-12 06:03:56 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2018-07-19 20:46:44 +08:00
|
|
|
import Users from '/imports/api/users';
|
2018-05-12 00:01:24 +08:00
|
|
|
import Annotations from '/imports/api/annotations';
|
|
|
|
import AnnotationsLocal from '/imports/ui/components/whiteboard/service';
|
2018-08-06 20:05:07 +08:00
|
|
|
import GroupChat from '/imports/api/group-chat';
|
2018-11-22 00:27:01 +08:00
|
|
|
import mapUser from '/imports/ui/services/user/mapUser';
|
2018-10-13 01:05:30 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2018-07-19 20:46:44 +08:00
|
|
|
import IntlStartup from './intl';
|
2018-05-12 00:01:24 +08:00
|
|
|
|
2018-08-06 20:05:07 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_GROUP_CHAT_ID = CHAT_CONFIG.public_group_id;
|
|
|
|
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
|
|
|
|
|
2017-06-06 20:33:53 +08:00
|
|
|
const propTypes = {
|
|
|
|
subscriptionsReady: PropTypes.bool.isRequired,
|
|
|
|
locale: PropTypes.string,
|
2018-08-11 01:51:12 +08:00
|
|
|
approved: PropTypes.bool,
|
2018-10-13 05:14:28 +08:00
|
|
|
meetingEnded: PropTypes.bool,
|
2017-06-06 20:33:53 +08:00
|
|
|
};
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2017-06-06 20:33:53 +08:00
|
|
|
const defaultProps = {
|
2017-11-01 01:13:44 +08:00
|
|
|
locale: undefined,
|
2018-08-11 01:51:12 +08:00
|
|
|
approved: undefined,
|
2018-10-13 05:14:28 +08:00
|
|
|
meetingEnded: false,
|
2017-06-06 20:33:53 +08:00
|
|
|
};
|
2017-03-11 02:33:46 +08:00
|
|
|
|
|
|
|
class Base extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
loading: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.updateLoadingState = this.updateLoadingState.bind(this);
|
|
|
|
}
|
|
|
|
|
2019-01-03 01:31:57 +08:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const { ejected, approved } = this.props;
|
2018-12-18 19:04:23 +08:00
|
|
|
const { loading } = this.state;
|
2018-07-19 20:46:44 +08:00
|
|
|
|
2018-12-18 19:04:23 +08:00
|
|
|
if (approved && loading) this.updateLoadingState(false);
|
2019-01-03 01:31:57 +08:00
|
|
|
|
|
|
|
if (prevProps.ejected || ejected) {
|
|
|
|
Session.set('codeError', '403');
|
|
|
|
Session.set('isMeetingEnded', true);
|
|
|
|
}
|
2018-07-19 20:46:44 +08:00
|
|
|
}
|
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
updateLoadingState(loading = false) {
|
|
|
|
this.setState({
|
|
|
|
loading,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderByState() {
|
2018-10-13 01:05:30 +08:00
|
|
|
const { updateLoadingState } = this;
|
|
|
|
const stateControls = { updateLoadingState };
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2018-10-13 01:05:30 +08:00
|
|
|
const { loading } = this.state;
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2018-10-13 01:05:30 +08:00
|
|
|
const codeError = Session.get('codeError');
|
2018-10-13 05:14:28 +08:00
|
|
|
const { subscriptionsReady, meetingEnded } = this.props;
|
2018-10-13 01:05:30 +08:00
|
|
|
|
2018-10-13 05:14:28 +08:00
|
|
|
if (meetingEnded) {
|
2018-10-13 01:05:30 +08:00
|
|
|
AudioManager.exitAudio();
|
|
|
|
return (<MeetingEnded code={Session.get('codeError')} />);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (codeError) {
|
|
|
|
logger.error(`User could not log in HTML5, hit ${codeError}`);
|
|
|
|
return (<ErrorScreen code={codeError} />);
|
|
|
|
}
|
2017-03-11 02:33:46 +08:00
|
|
|
|
|
|
|
if (loading || !subscriptionsReady) {
|
|
|
|
return (<LoadingScreen>{loading}</LoadingScreen>);
|
|
|
|
}
|
2018-05-12 00:01:24 +08:00
|
|
|
// this.props.annotationsHandler.stop();
|
|
|
|
|
2018-08-11 01:51:12 +08:00
|
|
|
if (subscriptionsReady) {
|
2018-12-07 01:26:08 +08:00
|
|
|
logger.info('Subscriptions are ready');
|
2018-08-11 01:51:12 +08:00
|
|
|
}
|
2018-08-09 05:20:55 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
return (<AppContainer {...this.props} baseControls={stateControls} />);
|
2017-03-11 02:33:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-10-13 01:05:30 +08:00
|
|
|
const { updateLoadingState } = this;
|
2017-04-06 20:36:59 +08:00
|
|
|
const { locale } = this.props;
|
2018-10-13 01:05:30 +08:00
|
|
|
const stateControls = { updateLoadingState };
|
2017-03-11 02:33:46 +08:00
|
|
|
|
|
|
|
return (
|
2017-06-06 20:33:53 +08:00
|
|
|
<IntlStartup locale={locale} baseControls={stateControls}>
|
2017-03-11 02:33:46 +08:00
|
|
|
{this.renderByState()}
|
|
|
|
</IntlStartup>
|
|
|
|
);
|
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2017-06-06 20:33:53 +08:00
|
|
|
Base.propTypes = propTypes;
|
|
|
|
Base.defaultProps = defaultProps;
|
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
const SUBSCRIPTIONS_NAME = [
|
2018-07-27 21:44:21 +08:00
|
|
|
'users', 'meetings', 'polls', 'presentations',
|
2018-11-22 00:27:01 +08:00
|
|
|
'slides', 'captions', 'voiceUsers', 'whiteboard-multi-user', 'screenshare',
|
2018-09-14 02:09:30 +08:00
|
|
|
'group-chat', 'presentation-pods', 'users-settings',
|
2017-03-11 02:33:46 +08:00
|
|
|
];
|
|
|
|
|
2018-10-03 03:53:13 +08:00
|
|
|
const BaseContainer = withTracker(() => {
|
2018-03-17 03:22:27 +08:00
|
|
|
const { locale } = Settings.application;
|
|
|
|
const { credentials, loggedIn } = Auth;
|
2018-08-06 20:05:07 +08:00
|
|
|
const { meetingId, requesterUserId } = credentials;
|
2018-11-22 00:27:01 +08:00
|
|
|
let breakoutRoomSubscriptionHandler;
|
2018-03-17 03:22:27 +08:00
|
|
|
if (!loggedIn) {
|
|
|
|
return {
|
|
|
|
locale,
|
|
|
|
subscriptionsReady: false,
|
|
|
|
};
|
|
|
|
}
|
2018-01-11 19:19:56 +08:00
|
|
|
|
2017-12-14 01:58:56 +08:00
|
|
|
const subscriptionErrorHandler = {
|
|
|
|
onError: (error) => {
|
2018-07-12 06:03:56 +08:00
|
|
|
logger.error(error);
|
2018-10-13 01:05:30 +08:00
|
|
|
Session.set('isMeetingEnded', true);
|
|
|
|
Session.set('codeError', error.error);
|
2017-12-14 01:58:56 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-12-18 19:04:23 +08:00
|
|
|
const subscriptionsHandlers = SUBSCRIPTIONS_NAME
|
|
|
|
.map(name => Meteor.subscribe(name, credentials, subscriptionErrorHandler));
|
2017-12-14 01:58:56 +08:00
|
|
|
|
2018-08-06 20:05:07 +08:00
|
|
|
const chats = GroupChat.find({
|
|
|
|
$or: [
|
|
|
|
{
|
|
|
|
meetingId,
|
|
|
|
access: PUBLIC_CHAT_TYPE,
|
|
|
|
chatId: { $ne: PUBLIC_GROUP_CHAT_ID },
|
|
|
|
},
|
|
|
|
{ meetingId, users: { $all: [requesterUserId] } },
|
|
|
|
],
|
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
const chatIds = chats.map(chat => chat.chatId);
|
|
|
|
|
|
|
|
const groupChatMessageHandler = Meteor.subscribe('group-chat-msg', credentials, chatIds, subscriptionErrorHandler);
|
2018-12-18 19:04:23 +08:00
|
|
|
const User = Users.findOne({ intId: credentials.requesterUserId });
|
|
|
|
|
2018-11-22 00:27:01 +08:00
|
|
|
if (User) {
|
|
|
|
const mappedUser = mapUser(User);
|
|
|
|
breakoutRoomSubscriptionHandler = Meteor.subscribe('breakouts', credentials, mappedUser.isModerator, subscriptionErrorHandler);
|
|
|
|
}
|
2018-08-06 20:05:07 +08:00
|
|
|
|
2018-05-12 00:01:24 +08:00
|
|
|
const annotationsHandler = Meteor.subscribe('annotations', credentials, {
|
|
|
|
onReady: () => {
|
2018-06-30 01:34:39 +08:00
|
|
|
AnnotationsLocal.remove({});
|
2018-06-30 02:11:11 +08:00
|
|
|
Annotations.find({}, { reactive: false }).forEach((a) => {
|
2018-05-12 00:01:24 +08:00
|
|
|
try {
|
2018-06-30 02:11:11 +08:00
|
|
|
AnnotationsLocal.insert(a);
|
2018-05-12 00:01:24 +08:00
|
|
|
} catch (e) {
|
2018-07-23 23:06:25 +08:00
|
|
|
// TODO
|
2018-05-12 00:01:24 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
annotationsHandler.stop();
|
|
|
|
},
|
|
|
|
...subscriptionErrorHandler,
|
|
|
|
});
|
|
|
|
|
|
|
|
const subscriptionsReady = subscriptionsHandlers.every(handler => handler.ready());
|
2017-03-11 02:33:46 +08:00
|
|
|
return {
|
2018-07-24 00:46:53 +08:00
|
|
|
approved: Users.findOne({ userId: Auth.userID, approved: true, guest: true }),
|
2019-01-03 01:31:57 +08:00
|
|
|
ejected: Users.findOne({ userId: Auth.userID, ejected: true }),
|
2018-10-13 05:14:28 +08:00
|
|
|
meetingEnded: Session.get('isMeetingEnded'),
|
2018-03-17 03:22:27 +08:00
|
|
|
locale,
|
2018-05-12 00:01:24 +08:00
|
|
|
subscriptionsReady,
|
|
|
|
annotationsHandler,
|
2018-08-06 20:05:07 +08:00
|
|
|
groupChatMessageHandler,
|
2018-11-22 00:27:01 +08:00
|
|
|
breakoutRoomSubscriptionHandler,
|
2017-03-11 02:33:46 +08:00
|
|
|
};
|
2018-10-03 03:53:13 +08:00
|
|
|
})(Base);
|
2017-06-06 20:33:53 +08:00
|
|
|
|
|
|
|
export default BaseContainer;
|