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

236 lines
7.1 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';
2024-04-20 04:34:43 +08:00
import { useVideoStreams } from '/imports/ui/components/video-provider/video-provider-graphql/hooks';
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';
import useSettings from '/imports/ui/services/settings/hooks/useSettings';
import { SETTINGS } from '/imports/ui/services/settings/enums';
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 = {
approved: PropTypes.bool,
};
2017-03-11 02:33:46 +08:00
const defaultProps = {
2019-06-05 03:23:44 +08:00
approved: 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,
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
}
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
2024-04-26 21:33:20 +08:00
if (Session.equals('layoutReady', true) && (sidebarContentPanel === PANELS.NONE)) {
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,
});
}
2024-04-26 21:33:20 +08:00
checkedUserSettings = true;
2021-07-20 21:19:48 +08:00
}
}
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
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 { isGridLayout } = props;
2021-09-13 19:34:03 +08:00
const sidebarContent = layoutSelectInput((i) => i.sidebarContent);
const { sidebarContentPanel } = sidebarContent;
const layoutContextDispatch = layoutDispatch();
2024-01-30 21:03:11 +08:00
const setLocalSettings = useUserChangedLocalSettings();
const { paginationEnabled, animations } = useSettings(SETTINGS.APPLICATION);
const { viewParticipantsWebcams, viewScreenshare } = useSettings(SETTINGS.DATA_SAVING);
2024-04-20 04:34:43 +08:00
const { streams: usersVideo } = useVideoStreams(
isGridLayout,
paginationEnabled,
viewParticipantsWebcams,
2024-04-20 04:34:43 +08:00
);
2024-01-30 21:03:11 +08:00
return (
<Base
{...{
sidebarContentPanel,
layoutContextDispatch,
setLocalSettings,
2024-04-20 04:34:43 +08:00
usersVideo,
animations,
viewScreenshare,
2024-01-30 21:03:11 +08:00
...props,
}}
/>
);
2021-09-13 19:34:03 +08:00
};
export default withTracker(() => {
2019-11-14 06:36:23 +08:00
const {
loggedIn,
} = Auth;
let userSubscriptionHandler;
const codeError = Session.get('codeError');
2024-04-20 04:34:43 +08:00
const isGridLayout = Session.get('isGridEnabled');
2017-03-11 02:33:46 +08:00
return {
userSubscriptionHandler,
2019-06-27 00:29:34 +08:00
isMeteorConnected: Meteor.status().connected,
2019-04-06 02:10:05 +08:00
meetingIsBreakout: AppService.meetingIsBreakout(),
loggedIn,
codeError,
2024-04-20 04:34:43 +08:00
isGridLayout,
2017-03-11 02:33:46 +08:00
};
2021-09-13 19:34:03 +08:00
})(BaseContainer);