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

286 lines
8.8 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-20 04:06:13 +08:00
import AppService from '/imports/ui/components/app/service';
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 propTypes = {
subscriptionsReady: PropTypes.bool.isRequired,
locale: PropTypes.string,
approved: PropTypes.bool,
2019-04-06 02:10:05 +08:00
meetingHasEnded: PropTypes.bool.isRequired,
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,
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() {
fullscreenChangedEvents.forEach((event) => {
document.addEventListener(event, Base.handleFullscreenChange);
});
Session.set('isFullscreen', false);
2019-03-12 00:21:12 +08:00
}
componentDidUpdate(prevProps, prevState) {
const {
approved,
meetingExist,
animations,
2019-02-07 23:34:21 +08:00
meteorIsConnected,
subscriptionsReady,
} = this.props;
2019-04-06 02:10:05 +08:00
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');
}
2019-03-20 04:06:13 +08:00
if (prevProps.meetingExist && !meetingExist && !meetingExisted) {
this.setMeetingExisted(true);
}
2019-03-20 04:06:13 +08:00
// In case the meteor restart avoid error log
if (meteorIsConnected && (prevState.meetingExisted !== meetingExisted) && meetingExisted) {
this.setMeetingExisted(false);
}
// In case the meeting delayed to load
2019-04-06 02:10:05 +08:00
if (!subscriptionsReady || !meetingExist) return;
if (approved && loading) this.updateLoadingState(false);
if (animations && animations !== prevProps.animations) {
document.documentElement.style.setProperty('--enableAnimation', 1);
} else if (!animations && animations !== prevProps.animations) {
document.documentElement.style.setProperty('--enableAnimation', 0);
}
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 };
2019-04-06 02:10:05 +08:00
const { loading } = this.state;
2018-10-13 01:05:30 +08:00
const codeError = Session.get('codeError');
const {
2019-03-20 04:06:13 +08:00
ejected,
subscriptionsReady,
2019-04-06 02:10:05 +08:00
meetingHasEnded,
meetingIsBreakout,
} = this.props;
2019-04-06 02:10:05 +08:00
if ((loading || !subscriptionsReady) && !meetingHasEnded) {
return (<LoadingScreen>{loading}</LoadingScreen>);
}
if (ejected && ejected.ejectedReason) {
const { ejectedReason } = ejected;
AudioManager.exitAudio();
return (<MeetingEnded code={ejectedReason} />);
}
2019-04-06 02:10:05 +08:00
if (meetingHasEnded && meetingIsBreakout) window.close();
2019-03-20 04:06:13 +08:00
2019-04-06 02:10:05 +08:00
if (meetingHasEnded && !meetingIsBreakout) {
2018-10-13 01:05:30 +08:00
AudioManager.exitAudio();
2019-03-20 04:06:13 +08:00
return (<MeetingEnded code={codeError} />);
2018-10-13 01:05:30 +08:00
}
2019-04-06 02:10:05 +08:00
if (codeError && !meetingHasEnded) {
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} />);
}
// 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;
2019-03-20 04:06:13 +08:00
const meeting = Meetings.findOne({ meetingId });
if (meeting) {
const { meetingEnded } = meeting;
if (meetingEnded) Session.set('codeError', '410');
}
let userSubscriptionHandler;
const subscriptionErrorHandler = {
onError: (error) => {
logger.error({ logCode: 'startup_client_subscription_error' }, error);
2018-10-13 01:05:30 +08:00
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 }),
locale,
subscriptionsReady,
annotationsHandler,
groupChatMessageHandler,
userSubscriptionHandler,
breakoutRoomSubscriptionHandler,
2019-03-08 00:33:34 +08:00
meetingModeratorSubscriptionHandler,
animations,
User,
2019-02-07 23:34:21 +08:00
meteorIsConnected: Meteor.status().connected,
2019-04-06 02:33:09 +08:00
meetingExist: !!Meetings.findOne({ meetingId }),
2019-04-06 02:10:05 +08:00
meetingHasEnded: !!meeting && meeting.meetingEnded,
meetingIsBreakout: AppService.meetingIsBreakout(),
2017-03-11 02:33:46 +08:00
};
2018-10-03 03:53:13 +08:00
})(Base);
export default BaseContainer;