bigbluebutton-Github/bigbluebutton-html5/imports/startup/client/base.jsx

299 lines
9.1 KiB
React
Raw Normal View History

2017-03-11 02:33:46 +08:00
import React, { Component } from 'react';
import { withTracker } from 'meteor/react-meteor-data';
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';
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';
import AudioManager from '/imports/ui/services/audio-manager';
import logger from '/imports/startup/client/logger';
2018-07-19 20:46:44 +08:00
import Users from '/imports/api/users';
import Annotations from '/imports/api/annotations';
import AnnotationsLocal from '/imports/ui/components/whiteboard/service';
import GroupChat from '/imports/api/group-chat';
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';
2019-01-18 00:43:44 +08:00
import Meetings from '../../api/meetings';
2019-03-29 05:12:49 +08:00
import AnnotationsTextService from '/imports/ui/components/whiteboard/annotations/text/service';
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;
const HTML = document.getElementsByTagName('html')[0];
const propTypes = {
subscriptionsReady: PropTypes.bool.isRequired,
locale: PropTypes.string,
approved: PropTypes.bool,
meetingEnded: PropTypes.bool,
meetingExist: PropTypes.bool,
};
2017-03-11 02:33:46 +08:00
const defaultProps = {
2017-11-01 01:13:44 +08:00
locale: undefined,
approved: undefined,
meetingEnded: false,
meetingExist: false,
};
2017-03-11 02:33:46 +08:00
2019-03-12 21:56:05 +08:00
const fullscreenChangedEvents = [
'fullscreenchange',
'webkitfullscreenchange',
'mozfullscreenchange',
'MSFullscreenChange',
];
2017-03-11 02:33:46 +08:00
class Base extends Component {
2019-03-12 00:21:12 +08:00
static handleFullscreenChange() {
if (document.fullscreenElement
|| document.webkitFullscreenElement
|| document.mozFullScreenElement
|| document.msFullscreenElement) {
Session.set('isFullscreen', true);
2019-03-12 00:21:12 +08:00
} else {
Session.set('isFullscreen', false);
2019-03-12 00:21:12 +08:00
}
}
2017-03-11 02:33:46 +08:00
constructor(props) {
super(props);
this.state = {
loading: false,
meetingExisted: false,
2017-03-11 02:33:46 +08:00
};
this.updateLoadingState = this.updateLoadingState.bind(this);
}
2019-03-12 00:21:12 +08:00
componentDidMount() {
const { animations } = this.props;
if (animations) HTML.classList.add('animationsEnabled');
if (!animations) HTML.classList.add('animationsDisabled');
2019-03-12 00:21:12 +08:00
fullscreenChangedEvents.forEach((event) => {
document.addEventListener(event, Base.handleFullscreenChange);
});
Session.set('isFullscreen', false);
2019-03-12 00:21:12 +08:00
}
componentDidUpdate(prevProps, prevState) {
const {
ejected,
approved,
meetingExist,
animations,
2019-02-07 23:34:21 +08:00
meteorIsConnected,
subscriptionsReady,
} = this.props;
2019-03-12 00:21:12 +08:00
const {
loading,
meetingExisted,
} = this.state;
2018-07-19 20:46:44 +08:00
if (!prevProps.subscriptionsReady && subscriptionsReady) {
logger.info({ logCode: 'startup_client_subscriptions_ready' }, 'Subscriptions are ready');
}
if (!prevProps.meetingExist && meetingExist) {
Session.set('isMeetingEnded', false);
}
if (prevProps.meetingExist && !meetingExist) {
Session.set('isMeetingEnded', true);
this.setMeetingExisted(true);
}
// In case the meeting delayed to load
if (!meetingExist) return;
if (approved && loading) this.updateLoadingState(false);
if (prevProps.ejected || ejected) {
Session.set('codeError', '403');
Session.set('isMeetingEnded', true);
}
// In case the meteor restart avoid error log
2019-02-07 23:34:21 +08:00
if (meteorIsConnected && (prevState.meetingExisted !== meetingExisted)) {
this.setMeetingExisted(false);
}
const enabled = HTML.classList.contains('animationsEnabled');
const disabled = HTML.classList.contains('animationsDisabled');
if (animations && animations !== prevProps.animations) {
if (disabled) HTML.classList.remove('animationsDisabled');
HTML.classList.add('animationsEnabled');
} else if (!animations && animations !== prevProps.animations) {
if (enabled) HTML.classList.remove('animationsEnabled');
HTML.classList.add('animationsDisabled');
}
2018-07-19 20:46:44 +08:00
}
2019-03-12 00:21:12 +08:00
componentWillUnmount() {
fullscreenChangedEvents.forEach((event) => {
document.removeEventListener(event, Base.handleFullscreenChange);
});
}
setMeetingExisted(meetingExisted) {
this.setState({ meetingExisted });
}
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
const { ejected } = this.props;
const { loading, meetingExisted } = this.state;
2017-03-11 02:33:46 +08:00
2018-10-13 01:05:30 +08:00
const codeError = Session.get('codeError');
const {
subscriptionsReady,
meetingExist,
} = this.props;
if (ejected && ejected.ejectedReason) {
const { ejectedReason } = ejected;
AudioManager.exitAudio();
return (<MeetingEnded code={ejectedReason} />);
}
if ((meetingExisted && !meetingExist)) {
2018-10-13 01:05:30 +08:00
AudioManager.exitAudio();
return (<MeetingEnded code={Session.get('codeError')} />);
}
if (codeError) {
logger.error({ logCode: 'startup_client_usercouldnotlogin_error' }, `User could not log in HTML5, hit ${codeError}`);
2018-10-13 01:05:30 +08:00
return (<ErrorScreen code={codeError} />);
}
2017-03-11 02:33:46 +08:00
if (loading || !subscriptionsReady) {
return (<LoadingScreen>{loading}</LoadingScreen>);
}
// this.props.annotationsHandler.stop();
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;
2019-01-18 00:43:44 +08:00
const { locale, meetingExist } = this.props;
2018-10-13 01:05:30 +08:00
const stateControls = { updateLoadingState };
const { meetingExisted } = this.state;
2017-03-11 02:33:46 +08:00
return (
2019-01-30 19:52:24 +08:00
(!meetingExisted && !meetingExist && Auth.loggedIn)
? <LoadingScreen />
: (
2019-01-18 00:43:44 +08:00
<IntlStartup locale={locale} baseControls={stateControls}>
{this.renderByState()}
</IntlStartup>
)
2017-03-11 02:33:46 +08:00
);
}
2017-06-03 03:25:02 +08:00
}
2017-03-11 02:33:46 +08:00
Base.propTypes = propTypes;
Base.defaultProps = defaultProps;
2017-03-11 02:33:46 +08:00
const SUBSCRIPTIONS_NAME = [
'users', 'meetings', 'polls', 'presentations',
'slides', 'captions', 'voiceUsers', 'whiteboard-multi-user', 'screenshare',
'group-chat', 'presentation-pods', 'users-settings', 'guestUser',
2017-03-11 02:33:46 +08:00
];
2018-10-03 03:53:13 +08:00
const BaseContainer = withTracker(() => {
const { locale, animations } = Settings.application;
const { credentials, loggedIn } = Auth;
const { meetingId, requesterUserId } = credentials;
let breakoutRoomSubscriptionHandler;
2019-03-08 00:33:34 +08:00
let meetingModeratorSubscriptionHandler;
let userSubscriptionHandler;
const subscriptionErrorHandler = {
onError: (error) => {
logger.error({ logCode: 'startup_client_subscription_error' }, error);
2018-10-13 01:05:30 +08:00
Session.set('isMeetingEnded', true);
Session.set('codeError', error.error);
},
};
const subscriptionsHandlers = SUBSCRIPTIONS_NAME
.map(name => Meteor.subscribe(name, credentials, subscriptionErrorHandler));
2019-02-07 19:19:35 +08:00
const subscriptionsReady = subscriptionsHandlers.every(handler => handler.ready())
&& loggedIn;
2019-01-18 00:43:44 +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);
const User = Users.findOne({ intId: credentials.requesterUserId });
if (User) {
const mappedUser = mapUser(User);
// override meteor subscription to verify if is moderator
userSubscriptionHandler = Meteor.subscribe('users', credentials, mappedUser.isModerator, subscriptionErrorHandler);
breakoutRoomSubscriptionHandler = Meteor.subscribe('breakouts', credentials, mappedUser.isModerator, subscriptionErrorHandler);
meetingModeratorSubscriptionHandler = Meteor.subscribe('meetings', credentials, mappedUser.isModerator, subscriptionErrorHandler);
}
const annotationsHandler = Meteor.subscribe('annotations', credentials, {
onReady: () => {
2019-03-29 05:12:49 +08:00
const activeTextShapeId = AnnotationsTextService.activeTextShapeId();
AnnotationsLocal.remove({ id: { $ne: `${activeTextShapeId}-fake` } });
Annotations.find({ id: { $ne: activeTextShapeId } }, { reactive: false }).forEach((a) => {
try {
2018-06-30 02:11:11 +08:00
AnnotationsLocal.insert(a);
} catch (e) {
// TODO
}
});
annotationsHandler.stop();
},
...subscriptionErrorHandler,
});
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 }),
ejected: Users.findOne({ userId: Auth.userID, ejected: true }),
meetingEnded: Session.get('isMeetingEnded'),
locale,
subscriptionsReady,
annotationsHandler,
groupChatMessageHandler,
userSubscriptionHandler,
breakoutRoomSubscriptionHandler,
2019-03-08 00:33:34 +08:00
meetingModeratorSubscriptionHandler,
animations,
meetingExist: !!Meetings.find({ meetingId }).count(),
User,
2019-02-07 23:34:21 +08:00
meteorIsConnected: Meteor.status().connected,
2017-03-11 02:33:46 +08:00
};
2018-10-03 03:53:13 +08:00
})(Base);
export default BaseContainer;