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-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';
|
2019-04-10 03:37:06 +08:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2019-04-10 01:55:10 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2019-01-22 03:28:37 +08:00
|
|
|
|
2019-04-11 23:04:10 +08:00
|
|
|
const HTML = document.getElementsByTagName('html')[0];
|
2018-08-06 20:05:07 +08:00
|
|
|
|
2019-04-10 01:55:10 +08:00
|
|
|
let breakoutNotified = false;
|
2018-08-06 20:05:07 +08:00
|
|
|
|
2017-06-06 20:33:53 +08:00
|
|
|
const propTypes = {
|
2019-04-23 22:22:11 +08:00
|
|
|
subscriptionsReady: PropTypes.bool,
|
2017-06-06 20:33:53 +08:00
|
|
|
locale: PropTypes.string,
|
2018-08-11 01:51:12 +08:00
|
|
|
approved: PropTypes.bool,
|
2019-04-06 02:10:05 +08:00
|
|
|
meetingHasEnded: PropTypes.bool.isRequired,
|
2019-02-07 18:56:29 +08:00
|
|
|
meetingExist: 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,
|
2019-06-05 03:23:44 +08:00
|
|
|
approved: false,
|
2019-02-07 18:56:29 +08:00
|
|
|
meetingExist: false,
|
2019-04-23 22:22:11 +08:00
|
|
|
subscriptionsReady: false,
|
2017-06-06 20:33:53 +08:00
|
|
|
};
|
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) {
|
2019-03-13 01:05:32 +08:00
|
|
|
Session.set('isFullscreen', true);
|
2019-03-12 00:21:12 +08:00
|
|
|
} else {
|
2019-03-13 01:05:32 +08:00
|
|
|
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,
|
2019-01-22 03:28:37 +08:00
|
|
|
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() {
|
2019-04-11 23:04:10 +08:00
|
|
|
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);
|
|
|
|
});
|
2019-03-13 01:05:32 +08:00
|
|
|
Session.set('isFullscreen', false);
|
2019-03-12 00:21:12 +08:00
|
|
|
}
|
|
|
|
|
2019-02-07 18:56:29 +08:00
|
|
|
componentDidUpdate(prevProps, prevState) {
|
2019-01-22 03:28:37 +08:00
|
|
|
const {
|
|
|
|
approved,
|
|
|
|
meetingExist,
|
2019-02-01 20:59:52 +08:00
|
|
|
animations,
|
2019-04-12 05:12:54 +08:00
|
|
|
ejected,
|
2019-02-07 23:34:21 +08:00
|
|
|
meteorIsConnected,
|
2019-03-11 20:56:41 +08:00
|
|
|
subscriptionsReady,
|
2019-01-22 03:28:37 +08:00
|
|
|
} = 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
|
|
|
|
2019-03-11 20:56:41 +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-01-18 02:31:04 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2019-01-22 03:28:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// In case the meeting delayed to load
|
2019-04-06 02:10:05 +08:00
|
|
|
if (!subscriptionsReady || !meetingExist) return;
|
2019-01-18 02:31:04 +08:00
|
|
|
|
2019-04-25 04:48:16 +08:00
|
|
|
if (approved && loading && subscriptionsReady) this.updateLoadingState(false);
|
2019-01-03 01:31:57 +08:00
|
|
|
|
|
|
|
if (prevProps.ejected || ejected) {
|
|
|
|
Session.set('codeError', '403');
|
|
|
|
Session.set('isMeetingEnded', true);
|
|
|
|
}
|
2019-01-25 00:16:23 +08:00
|
|
|
|
2019-02-07 18:56:29 +08:00
|
|
|
// In case the meteor restart avoid error log
|
2019-02-07 23:34:21 +08:00
|
|
|
if (meteorIsConnected && (prevState.meetingExisted !== meetingExisted)) {
|
2019-02-07 18:56:29 +08:00
|
|
|
this.setMeetingExisted(false);
|
|
|
|
}
|
|
|
|
|
2019-04-11 23:04:10 +08:00
|
|
|
const enabled = HTML.classList.contains('animationsEnabled');
|
|
|
|
const disabled = HTML.classList.contains('animationsDisabled');
|
|
|
|
|
2019-01-25 00:16:23 +08:00
|
|
|
if (animations && animations !== prevProps.animations) {
|
2019-04-11 23:04:10 +08:00
|
|
|
if (disabled) HTML.classList.remove('animationsDisabled');
|
|
|
|
HTML.classList.add('animationsEnabled');
|
2019-01-25 00:16:23 +08:00
|
|
|
} else if (!animations && animations !== prevProps.animations) {
|
2019-04-11 23:04:10 +08:00
|
|
|
if (enabled) HTML.classList.remove('animationsEnabled');
|
|
|
|
HTML.classList.add('animationsDisabled');
|
2019-01-25 00:16:23 +08:00
|
|
|
}
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-22 03:28:37 +08:00
|
|
|
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');
|
2019-01-22 03:28:37 +08:00
|
|
|
const {
|
2019-03-20 04:06:13 +08:00
|
|
|
ejected,
|
2019-01-22 03:28:37 +08:00
|
|
|
meetingExist,
|
2019-04-06 02:10:05 +08:00
|
|
|
meetingHasEnded,
|
|
|
|
meetingIsBreakout,
|
2019-04-25 04:48:16 +08:00
|
|
|
subscriptionsReady,
|
2019-05-18 03:39:05 +08:00
|
|
|
User,
|
2019-01-22 03:28:37 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-04-27 00:01:58 +08:00
|
|
|
if ((loading || !subscriptionsReady) && !meetingHasEnded && meetingExist) {
|
2019-04-06 02:10:05 +08:00
|
|
|
return (<LoadingScreen>{loading}</LoadingScreen>);
|
|
|
|
}
|
2019-01-22 03:28:37 +08:00
|
|
|
|
2019-03-15 02:02:04 +08:00
|
|
|
if (ejected && ejected.ejectedReason) {
|
2019-03-13 02:02:52 +08:00
|
|
|
const { ejectedReason } = ejected;
|
2019-03-15 02:02:04 +08:00
|
|
|
AudioManager.exitAudio();
|
2019-03-13 02:02:52 +08:00
|
|
|
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-05-18 03:39:05 +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
|
|
|
}
|
|
|
|
|
2019-04-27 00:01:58 +08:00
|
|
|
if (codeError && !meetingHasEnded) {
|
2019-05-25 06:56:17 +08:00
|
|
|
// 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}`);
|
|
|
|
}
|
2019-04-27 00:01:58 +08:00
|
|
|
return (<ErrorScreen code={codeError} />);
|
|
|
|
}
|
2018-05-12 00:01:24 +08:00
|
|
|
// 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-04-27 00:01:58 +08:00
|
|
|
const { locale, meetingExist } = this.props;
|
2018-10-13 01:05:30 +08:00
|
|
|
const stateControls = { updateLoadingState };
|
2019-04-27 00:01:58 +08:00
|
|
|
const { meetingExisted } = this.state;
|
2017-03-11 02:33:46 +08:00
|
|
|
|
|
|
|
return (
|
2019-04-27 00:01:58 +08:00
|
|
|
(!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
|
|
|
|
2017-06-06 20:33:53 +08:00
|
|
|
Base.propTypes = propTypes;
|
|
|
|
Base.defaultProps = defaultProps;
|
|
|
|
|
2018-10-03 03:53:13 +08:00
|
|
|
const BaseContainer = withTracker(() => {
|
2019-01-25 00:16:23 +08:00
|
|
|
const { locale, animations } = Settings.application;
|
2018-03-17 03:22:27 +08:00
|
|
|
const { credentials, loggedIn } = Auth;
|
2019-04-25 04:48:16 +08:00
|
|
|
const { meetingId } = credentials;
|
2018-11-22 00:27:01 +08:00
|
|
|
let breakoutRoomSubscriptionHandler;
|
2019-03-08 00:33:34 +08:00
|
|
|
let meetingModeratorSubscriptionHandler;
|
2019-03-20 04:06:13 +08:00
|
|
|
|
2019-05-18 03:39:05 +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 });
|
2019-04-24 20:20:38 +08:00
|
|
|
const ejected = Users.findOne({ userId: Auth.userID, ejected: true });
|
2019-02-08 03:40:27 +08:00
|
|
|
let userSubscriptionHandler;
|
2018-01-11 19:19:56 +08:00
|
|
|
|
2018-05-12 00:01:24 +08:00
|
|
|
|
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 {
|
2019-04-24 20:20:38 +08:00
|
|
|
approved,
|
|
|
|
ejected,
|
2018-03-17 03:22:27 +08:00
|
|
|
locale,
|
2019-02-08 03:40:27 +08:00
|
|
|
userSubscriptionHandler,
|
2018-11-22 00:27:01 +08:00
|
|
|
breakoutRoomSubscriptionHandler,
|
2019-03-08 00:33:34 +08:00
|
|
|
meetingModeratorSubscriptionHandler,
|
2019-01-25 00:16:23 +08:00
|
|
|
animations,
|
2019-01-22 03:28:37 +08:00
|
|
|
User,
|
2019-02-07 23:34:21 +08:00
|
|
|
meteorIsConnected: 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(),
|
2019-04-25 04:48:16 +08:00
|
|
|
subscriptionsReady: Session.get('subscriptionsReady'),
|
2019-04-23 22:22:11 +08:00
|
|
|
loggedIn,
|
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;
|