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

302 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';
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-04-10 01:55:10 +08:00
import Breakouts from '/imports/api/breakouts';
import AudioService from '/imports/ui/components/audio/service';
import { FormattedMessage } from 'react-intl';
2019-04-10 01:55:10 +08:00
import { notify } from '/imports/ui/services/notification';
const HTML = document.getElementsByTagName('html')[0];
2019-04-10 01:55:10 +08:00
let breakoutNotified = false;
const propTypes = {
subscriptionsReady: PropTypes.bool,
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,
2019-06-05 03:23:44 +08:00
approved: false,
meetingExist: false,
subscriptionsReady: 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 {
approved,
meetingExist,
animations,
2019-04-12 05:12:54 +08:00
ejected,
2019-06-27 00:29:34 +08:00
isMeteorConnected,
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');
}
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
2019-06-27 00:29:34 +08:00
if (isMeteorConnected && (prevState.meetingExisted !== meetingExisted) && meetingExisted) {
2019-03-20 04:06:13 +08:00
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 && subscriptionsReady) this.updateLoadingState(false);
if (prevProps.ejected || ejected) {
Session.set('codeError', '403');
Session.set('isMeetingEnded', true);
}
// In case the meteor restart avoid error log
2019-06-27 00:29:34 +08:00
if (isMeteorConnected && (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 };
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,
meetingExist,
2019-04-06 02:10:05 +08:00
meetingHasEnded,
meetingIsBreakout,
subscriptionsReady,
User,
} = this.props;
if ((loading || !subscriptionsReady) && !meetingHasEnded && meetingExist) {
2019-04-06 02:10:05 +08:00
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
if (((meetingHasEnded && !meetingIsBreakout)) || (codeError && (User && User.loggedOut))) {
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
}
if (codeError && !meetingHasEnded) {
// 680 is set for the codeError when the user requests a logout
if (codeError !== '680') {
logger.error({ logCode: 'startup_client_usercouldnotlogin_error' }, `User could not log in HTML5, hit ${codeError}`);
}
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;
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 (
(!meetingExisted && !meetingExist && Auth.loggedIn)
? <LoadingScreen />
: (
<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;
2018-10-03 03:53:13 +08:00
const BaseContainer = withTracker(() => {
const { locale, animations } = Settings.application;
const { credentials, loggedIn } = Auth;
const { meetingId } = credentials;
let breakoutRoomSubscriptionHandler;
2019-03-08 00:33:34 +08:00
let meetingModeratorSubscriptionHandler;
2019-03-20 04:06:13 +08:00
const User = Users.findOne({ intId: credentials.requesterUserId });
2019-03-20 04:06:13 +08:00
const meeting = Meetings.findOne({ meetingId });
if (meeting) {
const { meetingEnded } = meeting;
if (meetingEnded) Session.set('codeError', '410');
}
2019-06-05 03:23:44 +08:00
const approved = !!Users.findOne({ userId: Auth.userID, approved: true, guest: true });
const ejected = Users.findOne({ userId: Auth.userID, ejected: true });
let userSubscriptionHandler;
2019-04-10 01:55:10 +08:00
Breakouts.find().observeChanges({
added() {
breakoutNotified = false;
},
removed() {
if (!AudioService.isUsingAudio() && !breakoutNotified) {
if (meeting && !meeting.meetingEnded) {
notify(
<FormattedMessage
id="app.toast.breakoutRoomEnded"
description="message when the breakout room is ended"
/>,
'info',
'rooms',
);
}
breakoutNotified = true;
}
},
});
Meetings.find({ meetingId }).observe({
changed: (newDocument, oldDocument) => {
2019-04-11 02:20:31 +08:00
if (newDocument.recordProp) {
if (!oldDocument.recordProp.recording && newDocument.recordProp.recording) {
notify(
<FormattedMessage
id="app.notification.recordingStart"
description="Notification for when the recording starts"
/>,
'success',
'record',
);
}
2019-04-10 01:55:10 +08:00
2019-04-11 02:20:31 +08:00
if (oldDocument.recordProp.recording && !newDocument.recordProp.recording) {
notify(
<FormattedMessage
2019-06-10 22:36:33 +08:00
id="app.notification.recordingPaused"
2019-04-11 02:20:31 +08:00
description="Notification for when the recording stops"
/>,
'error',
'record',
);
}
2019-04-10 01:55:10 +08:00
}
},
});
2017-03-11 02:33:46 +08:00
return {
approved,
ejected,
locale,
userSubscriptionHandler,
breakoutRoomSubscriptionHandler,
2019-03-08 00:33:34 +08:00
meetingModeratorSubscriptionHandler,
animations,
User,
2019-06-27 00:29:34 +08:00
isMeteorConnected: Meteor.status().connected,
2019-04-11 02:20:31 +08:00
meetingExist: !!meeting,
2019-04-06 02:10:05 +08:00
meetingHasEnded: !!meeting && meeting.meetingEnded,
meetingIsBreakout: AppService.meetingIsBreakout(),
subscriptionsReady: Session.get('subscriptionsReady'),
loggedIn,
2017-03-11 02:33:46 +08:00
};
2018-10-03 03:53:13 +08:00
})(Base);
export default BaseContainer;