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

343 lines
12 KiB
React
Raw Normal View History

2024-04-17 06:39:29 +08:00
import React, { useEffect, useRef } from 'react';
import { withTracker } from 'meteor/react-meteor-data';
2017-07-14 22:18:07 +08:00
import Auth from '/imports/ui/services/auth';
import Users from '/imports/api/users';
2024-04-17 06:39:29 +08:00
import Meetings from '/imports/api/meetings';
2024-01-30 00:27:30 +08:00
import AudioCaptionsLiveContainer from '/imports/ui/components/audio/audio-graphql/audio-captions/live/component';
import { notify } from '/imports/ui/services/notification';
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 { isPresentationEnabled, isExternalVideoEnabled } from '/imports/ui/services/features';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import useMeeting from '/imports/ui/core/hooks/useMeeting';
import { LAYOUT_TYPE } from '/imports/ui/components/layout/enums';
import { useMutation, useSubscription } from '@apollo/client';
import {
layoutSelect,
layoutSelectInput,
layoutSelectOutput,
layoutDispatch,
2021-09-11 04:48:52 +08:00
} from '../layout/context';
2023-12-07 03:57:31 +08:00
import { SET_MOBILE_FLAG } from '/imports/ui/core/graphql/mutations/userMutations';
2024-01-11 21:33:25 +08:00
import { SET_SYNC_WITH_PRESENTER_LAYOUT, SET_LAYOUT_PROPS } from './mutations';
2019-04-11 03:40:40 +08:00
import {
getFontSize,
2018-10-24 01:18:09 +08:00
getBreakoutRooms,
} from './service';
import App from './component';
2024-01-29 20:49:40 +08:00
import useToggleVoice from '../audio/audio-graphql/hooks/useToggleVoice';
2024-01-30 21:03:11 +08:00
import useUserChangedLocalSettings from '../../services/settings/hooks/useUserChangedLocalSettings';
import { PINNED_PAD_SUBSCRIPTION } from '../notes/notes-graphql/queries';
const CUSTOM_STYLE_URL = window.meetingClientSettings.public.app.customStyleUrl;
const NOTES_CONFIG = window.meetingClientSettings.public.notes;
2017-07-14 22:18:07 +08:00
const AppContainer = (props) => {
function usePrevious(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
}
2023-02-17 00:23:41 +08:00
const layoutType = useRef(null);
2017-10-06 22:58:21 +08:00
const {
actionsbar,
selectedLayout,
pushLayout,
pushLayoutMeeting,
2021-06-30 22:29:03 +08:00
currentUserId,
shouldShowScreenshare: propsShouldShowScreenshare,
2021-09-22 19:48:25 +08:00
presentationRestoreOnUpdate,
isModalOpen,
2022-09-03 02:18:17 +08:00
meetingLayout,
meetingLayoutUpdatedAt,
meetingPresentationIsOpen,
isMeetingLayoutResizing,
2022-09-03 02:18:17 +08:00
meetingLayoutCameraPosition,
meetingLayoutFocusedCamera,
meetingLayoutVideoRate,
viewScreenshare,
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 genericComponent = layoutSelectInput((i) => i.genericComponent);
2021-09-11 04:48:52 +08:00
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);
const sharedNotesInput = layoutSelectInput((i) => i.sharedNotes);
2021-09-11 04:48:52 +08:00
const deviceType = layoutSelect((i) => i.deviceType);
const layoutContextDispatch = layoutDispatch();
2023-12-07 03:57:31 +08:00
const [setMobileFlag] = useMutation(SET_MOBILE_FLAG);
2024-01-11 20:41:08 +08:00
const [setSyncWithPresenterLayout] = useMutation(SET_SYNC_WITH_PRESENTER_LAYOUT);
2024-01-11 21:33:25 +08:00
const [setMeetingLayoutProps] = useMutation(SET_LAYOUT_PROPS);
2024-01-29 20:49:40 +08:00
const toggleVoice = useToggleVoice();
2024-01-30 21:03:11 +08:00
const setLocalSettings = useUserChangedLocalSettings();
const { data: pinnedPadData } = useSubscription(PINNED_PAD_SUBSCRIPTION);
const isSharedNotesPinnedFromGraphql = !!pinnedPadData
&& pinnedPadData.sharedNotes[0]?.sharedNotesExtId === NOTES_CONFIG.id;
const isSharedNotesPinned = sharedNotesInput?.isPinned && isSharedNotesPinnedFromGraphql;
2023-12-07 03:57:31 +08:00
const setMobileUser = (mobile) => {
setMobileFlag({
variables: {
mobile,
},
});
};
const { data: currentUserData } = useCurrentUser((user) => ({
enforceLayout: user.enforceLayout,
isModerator: user.isModerator,
presenter: user.presenter,
2024-04-17 06:39:29 +08:00
speechLocale: user.speechLocale,
}));
const isModerator = currentUserData?.isModerator;
const isPresenter = currentUserData?.presenter;
const { sidebarContentPanel, isOpen: sidebarContentIsOpen } = sidebarContent;
const { sidebarNavPanel, isOpen: sidebarNavigationIsOpen } = sidebarNavigation;
const { isOpen } = presentation;
const presentationIsOpen = isOpen;
const { focusedId } = cameraDock;
useEffect(() => {
if (
layoutContextDispatch
&& (typeof meetingLayout !== 'undefined')
&& (layoutType.current !== meetingLayout)
2023-07-31 22:24:25 +08:00
&& isSharedNotesPinned
2023-02-17 00:23:41 +08:00
) {
layoutType.current = meetingLayout;
MediaService.setPresentationIsOpen(layoutContextDispatch, true);
}
}, [meetingLayout, layoutContextDispatch, layoutType]);
2023-02-17 00:23:41 +08:00
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 setPushLayout = () => {
2024-01-11 20:41:08 +08:00
setSyncWithPresenterLayout({
variables: {
syncWithPresenterLayout: pushLayout,
},
});
};
const setMeetingLayout = () => {
const { isResizing } = cameraDockInput;
2024-01-11 21:33:25 +08:00
setMeetingLayoutProps({
variables: {
layout: selectedLayout,
syncWithPresenterLayout: pushLayout,
presentationIsOpen,
isResizing,
2024-04-02 21:59:01 +08:00
cameraPosition: cameraDock.position || 'contentTop',
2024-01-11 21:33:25 +08:00
focusedCamera: focusedId,
presentationVideoRate,
},
});
};
const { data: currentMeeting } = useMeeting((m) => ({
externalVideo: m.externalVideo,
}));
const isSharingVideo = !!currentMeeting?.externalVideo?.externalVideoUrl;
useEffect(() => {
MediaService.buildLayoutWhenPresentationAreaIsDisabled(layoutContextDispatch, isSharingVideo);
});
const shouldShowExternalVideo = isExternalVideoEnabled() && isSharingVideo;
const shouldShowGenericComponent = !!genericComponent.genericComponentId;
const validateEnforceLayout = (currentUser) => {
const layoutTypes = Object.values(LAYOUT_TYPE);
const enforceLayout = currentUser?.enforceLayout;
return enforceLayout && layoutTypes.includes(enforceLayout) ? enforceLayout : null;
};
const shouldShowScreenshare = propsShouldShowScreenshare
&& (viewScreenshare || isPresenter);
const shouldShowPresentation = (!shouldShowScreenshare && !isSharedNotesPinned
&& !shouldShowExternalVideo && !shouldShowGenericComponent
&& (presentationIsOpen || presentationRestoreOnUpdate)) && isPresentationEnabled();
2024-04-17 06:39:29 +08:00
if (!currentUserData) return null;
2021-07-21 21:19:47 +08:00
return currentUserId
? (
<App
{...{
actionsBarStyle,
captionsStyle,
2021-07-21 21:19:47 +08:00
currentUserId,
setPushLayout,
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,
2022-09-03 02:18:17 +08:00
meetingPresentationIsOpen,
isMeetingLayoutResizing,
2022-09-03 02:18:17 +08:00
meetingLayoutCameraPosition,
meetingLayoutFocusedCamera,
meetingLayoutVideoRate,
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,
shouldShowExternalVideo,
isPresenter,
numCameras: cameraDockInput.numCameras,
enforceLayout: validateEnforceLayout(currentUserData),
2024-04-17 06:39:29 +08:00
speechLocale: currentUserData?.speechLocale,
isModerator,
shouldShowScreenshare,
isSharedNotesPinned,
shouldShowPresentation,
2023-12-07 03:57:31 +08:00
setMobileUser,
2024-01-29 20:49:40 +08:00
toggleVoice,
2024-01-30 21:03:11 +08:00
setLocalSettings,
genericComponentId: genericComponent.genericComponentId,
2024-04-20 03:35:39 +08:00
audioCaptions: <AudioCaptionsLiveContainer speechLocale={currentUserData?.speechLocale} />,
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
}
);
export default withTracker(() => {
2021-05-18 04:25:07 +08:00
const currentUser = Users.findOne(
{ userId: Auth.userID },
{
fields:
{
approved: 1, emoji: 1, raiseHand: 1, away: 1, userId: 1, role: 1, inactivityCheck: 1,
2021-05-18 04:25:07 +08:00
},
},
);
2022-01-11 13:02:24 +08:00
const meetingLayoutObj = Meetings
.findOne({ meetingId: Auth.meetingID }) || {};
const { layout } = meetingLayoutObj;
2022-09-03 02:18:17 +08:00
const {
propagateLayout: pushLayoutMeeting,
cameraDockIsResizing: isMeetingLayoutResizing,
cameraDockPlacement: meetingLayoutCameraPosition,
2024-04-01 22:20:10 +08:00
cameraDockAspectRatio: meetingLayoutVideoRate,
cameraWithFocus: meetingLayoutFocusedCamera,
} = layout;
2024-04-01 22:20:10 +08:00
const meetingLayout = LAYOUT_TYPE[layout.currentLayoutType];
const meetingLayoutUpdatedAt = new Date(layout.updatedAt).getTime();
const meetingPresentationIsOpen = !layout.presentationMinimized;
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;
const shouldShowScreenshare = MediaService.shouldShowScreenshare();
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
const LAYOUT_CONFIG = window.meetingClientSettings.public.layout;
2021-09-28 03:57:02 +08:00
2017-06-03 03:25:02 +08:00
return {
2024-04-20 03:27:01 +08:00
audioCaptions: <AudioCaptionsLiveContainer />,
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,
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),
currentUserAway: currentUser.away,
currentUserRaiseHand: currentUser.raiseHand,
2021-06-30 22:29:03 +08:00
currentUserId: currentUser?.userId,
2022-09-03 02:18:17 +08:00
meetingLayout,
meetingLayoutUpdatedAt,
meetingPresentationIsOpen,
isMeetingLayoutResizing,
meetingLayoutCameraPosition,
meetingLayoutFocusedCamera,
meetingLayoutVideoRate,
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,
viewScreenshare,
isLargeFont: Session.get('isLargeFont'),
2021-09-22 19:48:25 +08:00
presentationRestoreOnUpdate: getFromUserSettings(
'bbb_force_restore_presentation_on_new_events',
window.meetingClientSettings.public.presentation.restoreOnUpdate,
2021-09-22 19:48:25 +08:00
),
hidePresentationOnJoin: getFromUserSettings('bbb_hide_presentation_on_join', LAYOUT_CONFIG.hidePresentationOnJoin),
hideActionsBar: getFromUserSettings('bbb_hide_actions_bar', false),
hideNavBar: getFromUserSettings('bbb_hide_nav_bar', false),
ignorePollNotifications: Session.get('ignorePollNotifications'),
User: currentUser,
2017-06-03 03:25:02 +08:00
};
})(AppContainer);