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

95 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-03-11 02:33:46 +08:00
import React, { Component } from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import IntlStartup from './intl';
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-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';
2017-03-11 02:33:46 +08:00
const BROWSER_LANGUAGE = window.navigator.userLanguage || window.navigator.language;
class Base extends Component {
constructor(props) {
super(props);
this.state = {
loading: false,
error: props.error || null,
};
this.updateLoadingState = this.updateLoadingState.bind(this);
this.updateErrorState = this.updateErrorState.bind(this);
}
updateLoadingState(loading = false) {
this.setState({
loading,
});
}
updateErrorState(error = null) {
this.setState({
error,
});
}
renderByState() {
const { updateLoadingState, updateErrorState } = this;
const stateControls = { updateLoadingState, updateErrorState };
const { loading, error } = this.state;
2017-03-11 04:47:23 +08:00
const { subscriptionsReady, errorCode } = this.props;
2017-03-11 02:33:46 +08:00
2017-03-11 04:47:23 +08:00
if (error || errorCode) {
return (<ErrorScreen code={errorCode}>{error}</ErrorScreen>);
2017-03-11 02:33:46 +08:00
}
if (loading || !subscriptionsReady) {
return (<LoadingScreen>{loading}</LoadingScreen>);
}
2017-06-03 03:25:02 +08:00
return (<AppContainer {...this.props} baseControls={stateControls} />);
2017-03-11 02:33:46 +08:00
}
render() {
const { updateLoadingState, updateErrorState } = this;
2017-04-06 20:36:59 +08:00
const { locale } = this.props;
2017-03-11 02:33:46 +08:00
const stateControls = { updateLoadingState, updateErrorState };
return (
2017-04-06 20:36:59 +08:00
<IntlStartup locale={locale || BROWSER_LANGUAGE} 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
const SUBSCRIPTIONS_NAME = [
2017-03-11 03:18:23 +08:00
'users', 'chat', 'cursor', 'deskshare', 'meetings',
2017-03-11 02:33:46 +08:00
'polls', 'presentations', 'shapes', 'slides', 'captions', 'breakouts',
];
2017-03-11 04:47:23 +08:00
export default BaseContainer = createContainer(({ params }) => {
2017-03-17 00:52:43 +08:00
if (params.errorCode) return params;
2017-03-11 04:47:23 +08:00
2017-03-11 02:33:46 +08:00
if (!Auth.loggedIn) {
return {
2017-03-11 04:47:23 +08:00
errorCode: 401,
error: 'You are unauthorized to access this meeting',
2017-03-11 02:33:46 +08:00
};
}
const credentials = Auth.credentials;
2017-03-11 02:33:46 +08:00
const subscriptionsHandlers = SUBSCRIPTIONS_NAME.map(name => Meteor.subscribe(name, credentials));
2017-03-11 03:18:23 +08:00
2017-03-11 02:33:46 +08:00
return {
2017-04-06 20:36:59 +08:00
locale: Settings.application.locale,
2017-03-11 02:33:46 +08:00
subscriptionsReady: subscriptionsHandlers.every(handler => handler.ready()),
};
}, Base);