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

347 lines
12 KiB
React
Raw Normal View History

2024-04-20 03:27:01 +08:00
import React, { useEffect, useRef } from 'react';
2024-01-30 00:27:30 +08:00
import AudioCaptionsLiveContainer from '/imports/ui/components/audio/audio-graphql/audio-captions/live/component';
import getFromUserSettings from '/imports/ui/services/users-settings';
import deviceInfo from '/imports/utils/deviceInfo';
import MediaService from '/imports/ui/components/media/service';
2024-06-14 21:30:48 +08:00
import { useIsPresentationEnabled, useIsScreenSharingEnabled, useIsExternalVideoEnabled } from '/imports/ui/services/features';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import useMeeting from '/imports/ui/core/hooks/useMeeting';
import { ACTIONS, LAYOUT_TYPE, PRESENTATION_AREA } from '/imports/ui/components/layout/enums';
import { useMutation, useReactiveVar } from '@apollo/client';
import {
layoutSelect,
layoutSelectInput,
layoutSelectOutput,
layoutDispatch,
2021-09-11 04:48:52 +08:00
} from '../layout/context';
2024-01-11 21:33:25 +08:00
import { SET_SYNC_WITH_PRESENTER_LAYOUT, SET_LAYOUT_PROPS } from './mutations';
import useSetSpeechOptions from '../audio/audio-graphql/hooks/useSetSpeechOptions';
2019-04-11 03:40:40 +08:00
import App from './component';
2024-01-30 21:03:11 +08:00
import useUserChangedLocalSettings from '../../services/settings/hooks/useUserChangedLocalSettings';
import { PINNED_PAD_SUBSCRIPTION } from '../notes/queries';
import connectionStatus from '../../core/graphql/singletons/connectionStatus';
import useDeduplicatedSubscription from '../../core/hooks/useDeduplicatedSubscription';
import VideoStreamsState from '../video-provider/video-provider-graphql/state';
import useSettings from '../../services/settings/hooks/useSettings';
import { SETTINGS } from '../../services/settings/enums';
import { useStorageKey } from '../../services/storage/hooks';
2024-06-07 02:47:41 +08:00
import useMuteMicrophone from '../audio/audio-graphql/hooks/useMuteMicrophone';
2024-06-12 05:55:38 +08:00
const currentUserEmoji = (currentUser) => (currentUser
? {
status: currentUser.reactionEmoji,
changedAt: currentUser.emojiTime,
}
: {
status: 'none',
changedAt: null,
}
);
2017-07-14 22:18:07 +08:00
const AppContainer = (props) => {
2024-06-12 05:55:38 +08:00
const LAYOUT_CONFIG = window.meetingClientSettings.public.layout;
2023-02-17 00:23:41 +08:00
const layoutType = useRef(null);
2017-10-06 22:58:21 +08:00
const {
actionsbar,
2021-06-30 22:29:03 +08:00
currentUserId,
shouldShowScreenshare: propsShouldShowScreenshare,
isModalOpen,
2017-10-06 22:58:21 +08:00
...otherProps
} = props;
2024-06-12 05:55:38 +08:00
const {
viewScreenshare,
} = useSettings(SETTINGS.DATA_SAVING);
const {
data: currentUser,
} = useCurrentUser((u) => ({
away: u.away,
reactionEmoji: u.reactionEmoji,
approved: 1,
raiseHand: u.raiseHand,
userId: u.userId,
role: u.role,
inactivityWarningDisplay: u.inactivityWarningDisplay,
presenter: u.presenter,
}));
const {
data: currentMeeting,
} = useMeeting((m) => ({
layout: m.layout,
componentsFlags: m.componentsFlags,
}));
const meetingLayout = LAYOUT_TYPE[currentMeeting?.layout.currentLayoutType];
const meetingLayoutUpdatedAt = new Date(currentMeeting?.layout.updatedAt).getTime();
const meetingPresentationIsOpen = !currentMeeting?.layout.presentationMinimized;
2024-06-13 22:48:15 +08:00
const presentationRestoreOnUpdate = getFromUserSettings(
'bbb_force_restore_presentation_on_new_events',
window.meetingClientSettings.public.presentation.restoreOnUpdate,
);
2024-06-12 05:55:38 +08:00
const {
propagateLayout: pushLayoutMeeting,
cameraDockIsResizing: isMeetingLayoutResizing,
cameraDockPlacement: meetingLayoutCameraPosition,
cameraDockAspectRatio: meetingLayoutVideoRate,
cameraWithFocus: meetingLayoutFocusedCamera,
} = (currentMeeting?.layout || {});
const isLargeFont = useStorageKey('isLargeFont');
const ignorePollNotifications = useStorageKey('ignorePollNotifications');
const NOTES_CONFIG = window.meetingClientSettings.public.notes;
const {
selectedLayout,
pushLayout,
audioAlertEnabled,
pushAlertEnabled,
darkTheme,
fontSize = '16px',
} = useSettings(SETTINGS.APPLICATION);
const { partialUtterances, minUtteranceLength } = useSettings(SETTINGS.TRANSCRIPTION);
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 hasExternalVideoOnLayout = layoutSelectInput((i) => i.externalVideo.hasExternalVideo);
2021-09-11 04:48:52 +08:00
const layoutContextDispatch = layoutDispatch();
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-30 21:03:11 +08:00
const setLocalSettings = useUserChangedLocalSettings();
const setSpeechOptions = useSetSpeechOptions();
const { data: pinnedPadData } = useDeduplicatedSubscription(PINNED_PAD_SUBSCRIPTION);
const isSharedNotesPinnedFromGraphql = !!pinnedPadData
&& pinnedPadData.sharedNotes[0]?.sharedNotesExtId === NOTES_CONFIG.id;
const isSharedNotesPinned = sharedNotesInput?.isPinned && isSharedNotesPinnedFromGraphql;
const isThereWebcam = VideoStreamsState.getStreams().length > 0;
2024-06-07 02:47:41 +08:00
const muteMicrophone = useMuteMicrophone();
2024-06-14 21:30:48 +08:00
const isScreenSharingEnabled = useIsScreenSharingEnabled();
const isExternalVideoEnabled = useIsExternalVideoEnabled();
const isPresentationEnabled = useIsPresentationEnabled();
2023-12-07 03:57:31 +08:00
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,
inactivityWarningDisplay: user.inactivityWarningDisplay,
inactivityWarningTimeoutSecs: user.inactivityWarningTimeoutSecs,
}));
const isModerator = currentUserData?.isModerator;
const isPresenter = currentUserData?.presenter;
const inactivityWarningDisplay = currentUserData?.inactivityWarningDisplay;
const inactivityWarningTimeoutSecs = currentUserData?.inactivityWarningTimeoutSecs;
const { sidebarContentPanel, isOpen: sidebarContentIsOpen } = sidebarContent;
const { sidebarNavPanel, isOpen: sidebarNavigationIsOpen } = sidebarNavigation;
const { isOpen } = presentation;
const presentationIsOpen = isOpen;
const { focusedId } = cameraDock;
const connected = useReactiveVar(connectionStatus.getConnectedStatusVar());
useEffect(() => {
if (
layoutContextDispatch
&& (typeof meetingLayout !== 'undefined')
&& (layoutType.current !== meetingLayout)
&& sharedNotesInput?.isPinned
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 isSharingVideo = currentMeeting?.componentsFlags.hasExternalVideo;
useEffect(() => {
MediaService.buildLayoutWhenPresentationAreaIsDisabled(
layoutContextDispatch,
isSharingVideo,
sharedNotesInput?.isPinned,
isThereWebcam,
2024-06-14 21:30:48 +08:00
isScreenSharingEnabled,
isPresentationEnabled,
);
});
useEffect(() => {
if (isSharingVideo && !hasExternalVideoOnLayout) {
layoutContextDispatch({
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
value: {
content: PRESENTATION_AREA.EXTERNAL_VIDEO,
open: true,
},
});
layoutContextDispatch({
type: ACTIONS.SET_HAS_EXTERNAL_VIDEO,
value: true,
});
}
}, [isSharingVideo]);
2024-06-14 21:30:48 +08:00
const shouldShowExternalVideo = isExternalVideoEnabled && isSharingVideo;
const shouldShowGenericComponent = !!genericComponent.genericComponentId;
2024-06-14 21:30:48 +08:00
const validateEnforceLayout = (currUser) => {
const layoutTypes = Object.keys(LAYOUT_TYPE);
2024-06-14 21:30:48 +08:00
const enforceLayout = currUser?.enforceLayout;
return enforceLayout && layoutTypes.includes(enforceLayout) ? enforceLayout : null;
};
2024-06-13 22:48:15 +08:00
const shouldShowScreenshare = (viewScreenshare || isPresenter)
&& currentMeeting?.componentsFlags?.hasScreenshare;
const shouldShowPresentation = (!shouldShowScreenshare && !isSharedNotesPinned
&& !shouldShowExternalVideo && !shouldShowGenericComponent
2024-06-14 21:30:48 +08:00
&& (presentationIsOpen || presentationRestoreOnUpdate)) && isPresentationEnabled;
2024-04-17 06:39:29 +08:00
2024-06-14 22:12:44 +08:00
useEffect(() => {
setSpeechOptions(
partialUtterances,
minUtteranceLength,
);
}, [partialUtterances, minUtteranceLength]);
// Update after editing app savings
useEffect(() => {
setSpeechOptions(
partialUtterances,
minUtteranceLength,
);
}, [partialUtterances, minUtteranceLength]);
2024-06-12 05:55:38 +08:00
const customStyleUrl = getFromUserSettings('bbb_custom_style_url', false)
|| window.meetingClientSettings.public.app.customStyleUrl;
2024-06-14 22:12:44 +08:00
if (!currentUserData) return null;
2024-06-12 05:55:38 +08:00
return currentUser?.userId
2021-07-21 21:19:47 +08:00
? (
<App
{...{
2024-06-13 22:48:15 +08:00
presentationRestoreOnUpdate,
2024-06-12 05:55:38 +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),
customStyle: getFromUserSettings('bbb_custom_style', false),
isPhone: deviceInfo.isPhone,
isRTL: document.documentElement.getAttribute('dir') === 'rtl',
currentUserEmoji: currentUserEmoji(currentUser),
currentUserAway: currentUser.away,
currentUserRaiseHand: currentUser.raiseHand,
currentUserId: currentUser.userId,
User: currentUser,
customStyleUrl,
connected,
2021-07-21 21:19:47 +08:00
actionsBarStyle,
captionsStyle,
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,
2024-01-30 21:03:11 +08:00
setLocalSettings,
genericComponentId: genericComponent.genericComponentId,
audioCaptions: <AudioCaptionsLiveContainer />,
inactivityWarningDisplay,
inactivityWarningTimeoutSecs,
setSpeechOptions,
audioAlertEnabled,
pushAlertEnabled,
darkTheme,
fontSize,
isLargeFont,
ignorePollNotifications,
2024-06-07 02:47:41 +08:00
muteMicrophone,
2024-06-15 02:40:40 +08:00
isPresentationEnabled,
2021-07-21 21:19:47 +08:00
}}
{...otherProps}
/>
)
: null;
2017-07-14 22:18:07 +08:00
};
2024-06-12 05:55:38 +08:00
export default AppContainer;