bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/app/container.jsx

278 lines
8.6 KiB
React
Raw Normal View History

2021-12-10 22:55:37 +08:00
import React, { useEffect, useRef } from 'react';
import { withTracker } from 'meteor/react-meteor-data';
import { defineMessages, injectIntl } from 'react-intl';
2017-10-06 22:58:21 +08:00
import PropTypes from 'prop-types';
2017-07-14 22:18:07 +08:00
import Auth from '/imports/ui/services/auth';
import Users from '/imports/api/users';
import Meetings, { LayoutMeetings } from '/imports/api/meetings';
import { notify } from '/imports/ui/services/notification';
import CaptionsContainer from '/imports/ui/components/captions/live/container';
import CaptionsService from '/imports/ui/components/captions/service';
import getFromUserSettings from '/imports/ui/services/users-settings';
import deviceInfo from '/imports/utils/deviceInfo';
2019-04-11 03:40:40 +08:00
import UserInfos from '/imports/api/users-infos';
2021-05-28 01:46:27 +08:00
import Settings from '/imports/ui/services/settings';
import MediaService from '/imports/ui/components/media/service';
import LayoutService from '/imports/ui/components/layout/service';
2022-01-11 13:02:24 +08:00
import _ from 'lodash';
import {
layoutSelect,
layoutSelectInput,
layoutSelectOutput,
layoutDispatch,
2021-09-11 04:48:52 +08:00
} from '../layout/context';
2019-04-11 03:40:40 +08:00
import {
getFontSize,
2018-10-24 01:18:09 +08:00
getBreakoutRooms,
validIOSVersion,
} from './service';
2022-02-15 23:54:55 +08:00
import { withModalMounter, getModal } from '/imports/ui/components/common/modal/service';
import App from './component';
const CUSTOM_STYLE_URL = Meteor.settings.public.app.customStyleUrl;
const intlMessages = defineMessages({
2017-07-14 22:18:07 +08:00
waitingApprovalMessage: {
id: 'app.guest.waiting',
description: 'Message while a guest is waiting to be approved',
},
});
2018-10-25 23:20:37 +08:00
const endMeeting = (code) => {
Session.set('codeError', code);
Session.set('isMeetingEnded', true);
};
2017-07-14 22:18:07 +08:00
const AppContainer = (props) => {
function usePrevious(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
}
2017-10-06 22:58:21 +08:00
const {
actionsbar,
meetingLayout,
meetingLayoutUpdatedAt,
selectedLayout,
pushLayout,
pushLayoutMeeting,
2021-06-30 22:29:03 +08:00
currentUserId,
2021-09-03 02:29:35 +08:00
shouldShowPresentation: propsShouldShowPresentation,
2021-09-22 19:48:25 +08:00
presentationRestoreOnUpdate,
isPresenter,
randomlySelectedUser,
isModalOpen,
presentationIsOpen: layoutPresOpen,
isResizing: layoutIsResizing,
cameraPosition: layoutCamPosition,
focusedCamera: layoutFocusedCam,
presentationVideoRate: layoutRate,
2017-10-06 22:58:21 +08:00
...otherProps
} = props;
2021-09-11 04:48:52 +08:00
const sidebarContent = layoutSelectInput((i) => i.sidebarContent);
const sidebarNavigation = layoutSelectInput((i) => i.sidebarNavigation);
const actionsBarStyle = layoutSelectOutput((i) => i.actionBar);
const captionsStyle = layoutSelectOutput((i) => i.captions);
const cameraDock = layoutSelectOutput((i) => i.cameraDock);
const cameraDockInput = layoutSelectInput((i) => i.cameraDock);
const presentation = layoutSelectInput((i) => i.presentation);
2021-09-11 04:48:52 +08:00
const layoutType = layoutSelect((i) => i.layoutType);
const deviceType = layoutSelect((i) => i.deviceType);
const layoutContextDispatch = layoutDispatch();
const { sidebarContentPanel, isOpen: sidebarContentIsOpen } = sidebarContent;
const { sidebarNavPanel, isOpen: sidebarNavigationIsOpen } = sidebarNavigation;
const { isOpen: presentationIsOpen } = presentation;
2021-09-22 19:48:25 +08:00
const shouldShowPresentation = propsShouldShowPresentation
&& (presentationIsOpen || presentationRestoreOnUpdate);
2017-10-06 22:58:21 +08:00
const { focusedId } = cameraDock;
const horizontalPosition = cameraDock.position === 'contentLeft' || cameraDock.position === 'contentRight';
// this is not exactly right yet
let presentationVideoRate;
if (horizontalPosition) {
presentationVideoRate = cameraDock.width / window.innerWidth;
} else {
presentationVideoRate = cameraDock.height / window.innerHeight;
}
presentationVideoRate = parseFloat(presentationVideoRate.toFixed(2));
const prevRandomUser = usePrevious(randomlySelectedUser);
const mountRandomUserModal = !isPresenter
2022-01-11 13:02:24 +08:00
&& !_.isEqual(prevRandomUser, randomlySelectedUser)
&& randomlySelectedUser.length > 0
&& !isModalOpen;
const setMeetingLayout = () => {
const { isResizing } = cameraDockInput;
LayoutService.setMeetingLayout({
layout: selectedLayout,
presentationIsOpen,
isResizing,
cameraPosition: cameraDock.position,
focusedCamera: focusedId,
presentationVideoRate,
pushLayout,
});
};
2021-07-21 21:19:47 +08:00
return currentUserId
? (
<App
{...{
actionsBarStyle,
captionsStyle,
2021-07-21 21:19:47 +08:00
currentUserId,
setMeetingLayout,
2021-07-21 21:19:47 +08:00
meetingLayout,
selectedLayout,
pushLayout,
pushLayoutMeeting,
meetingLayoutUpdatedAt,
presentationIsOpen,
cameraPosition: cameraDock.position,
focusedCamera: focusedId,
presentationVideoRate,
cameraWidth: cameraDock.width,
cameraHeight: cameraDock.height,
cameraIsResizing: cameraDockInput.isResizing,
layoutPresOpen,
layoutIsResizing,
layoutCamPosition,
layoutFocusedCam,
layoutRate,
horizontalPosition,
2021-07-21 21:19:47 +08:00
deviceType,
2021-08-05 19:03:24 +08:00
layoutContextDispatch,
2021-07-21 21:19:47 +08:00
sidebarNavPanel,
sidebarNavigationIsOpen,
sidebarContentPanel,
sidebarContentIsOpen,
2021-09-03 02:29:35 +08:00
shouldShowPresentation,
mountRandomUserModal,
isPresenter,
2021-07-21 21:19:47 +08:00
}}
{...otherProps}
/>
)
: null;
2017-07-14 22:18:07 +08:00
};
2021-05-18 04:25:07 +08:00
const currentUserEmoji = (currentUser) => (currentUser
? {
status: currentUser.emoji,
changedAt: currentUser.emojiTime,
}
: {
status: 'none',
changedAt: null,
2021-05-18 04:25:07 +08:00
}
);
2018-10-03 03:53:13 +08:00
export default injectIntl(withModalMounter(withTracker(({ intl, baseControls }) => {
Users.find({ userId: Auth.userID, meetingId: Auth.meetingID }).observe({
removed() {
endMeeting('403');
},
});
2021-05-18 04:25:07 +08:00
const currentUser = Users.findOne(
{ userId: Auth.userID },
{
fields:
{
approved: 1, emoji: 1, userId: 1, presenter: 1,
2021-05-18 04:25:07 +08:00
},
},
);
2022-01-11 13:02:24 +08:00
const currentMeeting = Meetings.findOne({ meetingId: Auth.meetingID },
{
fields: {
randomlySelectedUser: 1,
layout: 1,
},
});
const {
randomlySelectedUser,
} = currentMeeting;
2017-07-14 22:18:07 +08:00
const meetingLayout = LayoutMeetings.findOne({ meetingId: Auth.meetingID }) || {};
const { layout, pushLayout: pushLayoutMeeting, layoutUpdatedAt, presentationIsOpen, isResizing, cameraPosition, focusedCamera, presentationVideoRate } = meetingLayout;
2021-06-30 22:29:03 +08:00
if (currentUser && !currentUser.approved) {
2018-07-19 20:46:44 +08:00
baseControls.updateLoadingState(intl.formatMessage(intlMessages.waitingApprovalMessage));
}
2017-07-18 00:38:18 +08:00
2019-04-12 04:54:15 +08:00
const UserInfo = UserInfos.find({
meetingId: Auth.meetingID,
requesterUserId: Auth.userID,
}).fetch();
2021-05-28 01:46:27 +08:00
const AppSettings = Settings.application;
const { selectedLayout, pushLayout } = AppSettings;
const { viewScreenshare } = Settings.dataSaving;
2021-06-16 20:53:27 +08:00
const shouldShowExternalVideo = MediaService.shouldShowExternalVideo();
2021-07-21 21:19:47 +08:00
const shouldShowScreenshare = MediaService.shouldShowScreenshare()
2021-11-24 00:43:49 +08:00
&& (viewScreenshare || currentUser?.presenter);
let customStyleUrl = getFromUserSettings('bbb_custom_style_url', false);
if (!customStyleUrl && CUSTOM_STYLE_URL) {
customStyleUrl = CUSTOM_STYLE_URL;
}
2021-05-18 04:25:07 +08:00
2021-09-28 03:57:02 +08:00
const LAYOUT_CONFIG = Meteor.settings.public.layout;
const isPresenter = currentUser?.presenter;
2017-06-03 03:25:02 +08:00
return {
captions: CaptionsService.isCaptionsActive() ? <CaptionsContainer /> : null,
2017-06-03 03:25:02 +08:00
fontSize: getFontSize(),
2018-10-24 01:18:09 +08:00
hasBreakoutRooms: getBreakoutRooms().length > 0,
customStyle: getFromUserSettings('bbb_custom_style', false),
customStyleUrl,
2019-04-11 03:40:40 +08:00
UserInfo,
notify,
validIOSVersion,
2021-04-01 01:13:36 +08:00
isPhone: deviceInfo.isPhone,
2019-07-16 03:15:58 +08:00
isRTL: document.documentElement.getAttribute('dir') === 'rtl',
currentUserEmoji: currentUserEmoji(currentUser),
randomlySelectedUser,
2021-06-30 22:29:03 +08:00
currentUserId: currentUser?.userId,
isPresenter,
meetingLayout: layout,
meetingLayoutUpdatedAt: layoutUpdatedAt,
presentationIsOpen,
isResizing,
cameraPosition,
focusedCamera,
presentationVideoRate,
selectedLayout,
pushLayout,
pushLayoutMeeting,
2021-05-28 01:46:27 +08:00
audioAlertEnabled: AppSettings.chatAudioAlerts,
pushAlertEnabled: AppSettings.chatPushAlerts,
2022-04-09 03:05:29 +08:00
darkTheme: AppSettings.darkTheme,
shouldShowScreenshare,
2021-06-16 20:53:27 +08:00
shouldShowPresentation: !shouldShowScreenshare && !shouldShowExternalVideo,
shouldShowExternalVideo,
isLargeFont: Session.get('isLargeFont'),
2021-09-22 19:48:25 +08:00
presentationRestoreOnUpdate: getFromUserSettings(
'bbb_force_restore_presentation_on_new_events',
Meteor.settings.public.presentation.restoreOnUpdate,
),
2021-09-28 03:57:02 +08:00
hidePresentation: getFromUserSettings('bbb_hide_presentation', LAYOUT_CONFIG.hidePresentation),
hideActionsBar: getFromUserSettings('bbb_hide_actions_bar', false),
isModalOpen: !!getModal(),
2017-06-03 03:25:02 +08:00
};
2018-10-03 03:53:13 +08:00
})(AppContainer)));