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

210 lines
6.7 KiB
React
Raw Normal View History

2021-09-13 19:34:03 +08:00
import React, { Component } from 'react';
2017-03-11 02:33:46 +08:00
import Auth from '/imports/ui/services/auth';
import AppContainer from '/imports/ui/components/app/container';
import { getSettingsSingletonInstance } from '/imports/ui/services/settings';
import Session from '/imports/ui/services/storage/in-memory';
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-06-17 19:54:03 +08:00
import { useVideoStreams } from '/imports/ui/components/video-provider/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';
2024-06-14 21:30:48 +08:00
import { useIsChatEnabled } 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';
import { useStorageKey } from '/imports/ui/services/storage/hooks';
const HTML = document.getElementsByTagName('html')[0];
2021-03-18 02:01:08 +08:00
let checkedUserSettings = false;
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.setItem('isFullscreen', true);
2021-11-20 03:26:04 +08:00
} else {
layoutContextDispatch({
type: ACTIONS.SET_FULLSCREEN_ELEMENT,
value: {
element: '',
group: '',
},
});
Session.setItem('isFullscreen', false);
2021-11-20 03:26:04 +08:00
}
2021-09-13 19:34:03 +08:00
}
componentDidMount() {
const { animations, usersVideo, layoutContextDispatch } = this.props;
const CAPTIONS_ALWAYS_VISIBLE = window.meetingClientSettings.public.app.audioCaptions.alwaysVisible;
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.setItem('isFullscreen', false);
Session.setItem('audioCaptions', CAPTIONS_ALWAYS_VISIBLE);
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,
2024-06-14 21:30:48 +08:00
isChatEnabled,
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
);
const Settings = getSettingsSingletonInstance();
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) {
2024-06-14 21:30:48 +08:00
if (isChatEnabled && getFromUserSettings('bbb_show_public_chat_on_login', !window.meetingClientSettings.public.chat.startClosed)) {
const PUBLIC_CHAT_ID = window.meetingClientSettings.public.chat.public_group_id;
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
2021-09-13 19:34:03 +08:00
const BaseContainer = (props) => {
const codeError = useStorageKey('codeError');
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 applicationSettings = useSettings(SETTINGS.APPLICATION);
const animations = applicationSettings?.animations;
const { viewScreenshare } = useSettings(SETTINGS.DATA_SAVING);
const { streams: usersVideo } = useVideoStreams();
const loggedIn = Auth.useLoggedIn();
2024-06-14 21:30:48 +08:00
const isChatEnabled = useIsChatEnabled();
2024-01-30 21:03:11 +08:00
return (
<Base
{...{
sidebarContentPanel,
layoutContextDispatch,
setLocalSettings,
2024-04-20 04:34:43 +08:00
usersVideo,
animations,
viewScreenshare,
codeError,
loggedIn,
2024-06-14 21:30:48 +08:00
isChatEnabled,
2024-01-30 21:03:11 +08:00
...props,
}}
/>
);
2021-09-13 19:34:03 +08:00
};
2024-06-12 01:18:28 +08:00
export default BaseContainer;