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

247 lines
7.3 KiB
React
Raw Normal View History

2021-09-13 19:34:03 +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';
import LoadingScreen from '/imports/ui/components/common/loading-screen/component';
2017-04-06 20:36:59 +08:00
import Settings from '/imports/ui/services/settings';
import logger from '/imports/startup/client/logger';
2018-10-13 01:05:30 +08:00
import { Session } from 'meteor/session';
import { Meteor } from 'meteor/meteor';
2019-03-20 04:06:13 +08:00
import AppService from '/imports/ui/components/app/service';
import deviceInfo from '/imports/utils/deviceInfo';
import getFromUserSettings from '/imports/ui/services/users-settings';
2021-09-11 04:48:52 +08:00
import { layoutSelectInput, layoutDispatch } from '../../ui/components/layout/context';
2020-04-23 22:07:44 +08:00
import VideoService from '/imports/ui/components/video-provider/service';
import DebugWindow from '/imports/ui/components/debug-window/component';
2021-05-18 04:25:07 +08:00
import { ACTIONS, PANELS } from '../../ui/components/layout/enums';
2022-03-09 22:19:25 +08:00
import { isChatEnabled } from '/imports/ui/services/features';
2024-01-30 21:03:11 +08:00
import useUserChangedLocalSettings from '/imports/ui/services/settings/hooks/useUserChangedLocalSettings';
const CHAT_CONFIG = window.meetingClientSettings.public.chat;
2023-08-17 21:54:35 +08:00
const PUBLIC_CHAT_ID = CHAT_CONFIG.public_group_id;
const HTML = document.getElementsByTagName('html')[0];
2021-03-18 02:01:08 +08:00
let checkedUserSettings = false;
const propTypes = {
subscriptionsReady: PropTypes.bool,
approved: PropTypes.bool,
};
2017-03-11 02:33:46 +08:00
const defaultProps = {
2019-06-05 03:23:44 +08:00
approved: 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',
];
2021-09-13 19:34:03 +08:00
class Base extends Component {
constructor(props) {
super(props);
2017-03-11 02:33:46 +08:00
2021-11-20 03:26:04 +08:00
this.handleFullscreenChange = this.handleFullscreenChange.bind(this);
}
handleFullscreenChange() {
const { layoutContextDispatch } = this.props;
if (document.fullscreenElement
|| document.webkitFullscreenElement
|| document.mozFullScreenElement
|| document.msFullscreenElement) {
Session.set('isFullscreen', true);
} else {
layoutContextDispatch({
type: ACTIONS.SET_FULLSCREEN_ELEMENT,
value: {
element: '',
group: '',
},
});
Session.set('isFullscreen', false);
}
2021-09-13 19:34:03 +08:00
}
componentDidMount() {
const { animations, usersVideo, layoutContextDispatch } = this.props;
layoutContextDispatch({
type: ACTIONS.SET_NUM_CAMERAS,
value: usersVideo.length,
});
if (animations) HTML.classList.add('animationsEnabled');
if (!animations) HTML.classList.add('animationsDisabled');
2019-03-12 00:21:12 +08:00
fullscreenChangedEvents.forEach((event) => {
2021-11-20 03:26:04 +08:00
document.addEventListener(event, this.handleFullscreenChange);
2019-03-12 00:21:12 +08:00
});
Session.set('isFullscreen', false);
2021-09-13 19:34:03 +08:00
}
2019-03-12 00:21:12 +08:00
componentDidUpdate(prevProps) {
2021-09-13 19:34:03 +08:00
const {
animations,
subscriptionsReady,
layoutContextDispatch,
sidebarContentPanel,
usersVideo,
2024-01-30 21:03:11 +08:00
setLocalSettings,
2021-09-13 19:34:03 +08:00
} = this.props;
2021-07-20 21:19:48 +08:00
2021-09-13 19:34:03 +08:00
if (usersVideo !== prevProps.usersVideo) {
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_NUM_CAMERAS,
value: usersVideo.length,
});
2020-06-09 11:09:46 +08:00
}
2021-09-13 19:34:03 +08:00
if (!prevProps.subscriptionsReady && subscriptionsReady) {
logger.info({ logCode: 'startup_client_subscriptions_ready' }, 'Subscriptions are ready');
}
const enabled = HTML.classList.contains('animationsEnabled');
const disabled = HTML.classList.contains('animationsDisabled');
2021-09-13 19:34:03 +08:00
if (animations && animations !== prevProps.animations) {
if (disabled) HTML.classList.remove('animationsDisabled');
HTML.classList.add('animationsEnabled');
2021-09-13 19:34:03 +08:00
} else if (!animations && animations !== prevProps.animations) {
if (enabled) HTML.classList.remove('animationsEnabled');
HTML.classList.add('animationsDisabled');
}
2021-07-20 21:19:48 +08:00
2022-12-01 02:32:47 +08:00
if (Session.equals('layoutReady', true) && (sidebarContentPanel === PANELS.NONE || Session.equals('subscriptionsReady', true))) {
2021-07-20 21:19:48 +08:00
if (!checkedUserSettings) {
const showAnimationsDefault = getFromUserSettings(
'bbb_show_animations_default',
window.meetingClientSettings.public.app.defaultSettings.application.animations
);
Settings.application.animations = showAnimationsDefault;
2024-01-30 21:03:11 +08:00
Settings.save(setLocalSettings);
if (getFromUserSettings('bbb_show_participants_on_login', window.meetingClientSettings.public.layout.showParticipantsOnLogin) && !deviceInfo.isPhone) {
if (isChatEnabled() && getFromUserSettings('bbb_show_public_chat_on_login', !window.meetingClientSettings.public.chat.startClosed)) {
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-07-20 21:19:48 +08:00
type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN,
value: true,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-07-20 21:19:48 +08:00
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: true,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-07-20 21:19:48 +08:00
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.CHAT,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-07-20 21:19:48 +08:00
type: ACTIONS.SET_ID_CHAT_OPEN,
value: PUBLIC_CHAT_ID,
});
} else {
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-07-20 21:19:48 +08:00
type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN,
value: true,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-07-20 21:19:48 +08:00
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: false,
});
}
} else {
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-07-20 21:19:48 +08:00
type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN,
value: false,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-07-20 21:19:48 +08:00
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: false,
});
}
if (Session.equals('subscriptionsReady', true)) {
checkedUserSettings = true;
}
}
}
2021-09-13 19:34:03 +08:00
}
2021-09-13 19:34:03 +08:00
componentWillUnmount() {
fullscreenChangedEvents.forEach((event) => {
2021-11-20 03:26:04 +08:00
document.removeEventListener(event, this.handleFullscreenChange);
2021-09-13 19:34:03 +08:00
});
}
2017-03-11 02:33:46 +08:00
render() {
2021-09-13 19:34:03 +08:00
const {
subscriptionsReady,
} = this.props;
if (!subscriptionsReady) {
return (<LoadingScreen />);
}
2021-09-13 19:34:03 +08:00
return (
<>
<DebugWindow />
<AppContainer {...this.props} />
2021-09-13 19:34:03 +08:00
</>
);
}
}
2017-03-11 02:33:46 +08:00
Base.propTypes = propTypes;
Base.defaultProps = defaultProps;
2021-09-13 19:34:03 +08:00
const BaseContainer = (props) => {
const sidebarContent = layoutSelectInput((i) => i.sidebarContent);
const { sidebarContentPanel } = sidebarContent;
const layoutContextDispatch = layoutDispatch();
2024-01-30 21:03:11 +08:00
const setLocalSettings = useUserChangedLocalSettings();
return (
<Base
{...{
sidebarContentPanel,
layoutContextDispatch,
setLocalSettings,
...props,
}}
/>
);
2021-09-13 19:34:03 +08:00
};
export default withTracker(() => {
const clientSettings = JSON.parse(sessionStorage.getItem('clientStartupSettings') || '{}')
2019-11-14 06:36:23 +08:00
const {
animations,
} = Settings.application;
const {
loggedIn,
} = Auth;
let userSubscriptionHandler;
const codeError = Session.get('codeError');
2021-03-02 22:56:10 +08:00
const { streams: usersVideo } = VideoService.getVideoStreams();
2017-03-11 02:33:46 +08:00
return {
userSubscriptionHandler,
animations,
2019-06-27 00:29:34 +08:00
isMeteorConnected: Meteor.status().connected,
2019-04-06 02:10:05 +08:00
meetingIsBreakout: AppService.meetingIsBreakout(),
subscriptionsReady: Session.get('subscriptionsReady') || clientSettings.skipMeteorConnection,
loggedIn,
codeError,
2020-04-23 22:07:44 +08:00
usersVideo,
2017-03-11 02:33:46 +08:00
};
2021-09-13 19:34:03 +08:00
})(BaseContainer);