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

204 lines
5.9 KiB
React
Raw Normal View History

2021-05-18 04:25:07 +08:00
import React, { useContext } 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 AuthTokenValidation from '/imports/api/auth-token-validation';
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import { notify } from '/imports/ui/services/notification';
import CaptionsContainer from '/imports/ui/components/captions/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-18 04:25:07 +08:00
import { NLayoutContext } from '../layout/context/context';
2021-05-28 01:46:27 +08:00
import Settings from '/imports/ui/services/settings';
import MediaService from '/imports/ui/components/media/service';
2019-04-11 03:40:40 +08:00
import {
getFontSize,
2018-10-24 01:18:09 +08:00
getBreakoutRooms,
validIOSVersion,
} from './service';
2017-04-19 03:06:51 +08:00
import { withModalMounter } from '../modal/service';
import App from './component';
import ActionsBarContainer from '../actions-bar/container';
import MediaContainer from '../media/container';
2017-10-06 22:58:21 +08:00
const propTypes = {
actionsbar: PropTypes.node,
media: PropTypes.node,
meetingLayout: PropTypes.string.isRequired,
2017-10-06 22:58:21 +08:00
};
2016-04-29 03:02:51 +08:00
const defaultProps = {
2016-07-23 02:47:54 +08:00
actionsbar: <ActionsBarContainer />,
2016-07-21 22:24:50 +08:00
media: <MediaContainer />,
2016-04-29 03:02:51 +08:00
};
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) => {
2021-05-18 04:25:07 +08:00
const newLayoutContext = useContext(NLayoutContext);
const { newLayoutContextState, newLayoutContextDispatch } = newLayoutContext;
2017-10-06 22:58:21 +08:00
const {
actionsbar,
media,
meetingLayout,
2021-06-22 04:28:51 +08:00
settingsLayout,
pushLayoutToEveryone,
2021-06-30 22:29:03 +08:00
currentUserId,
2017-10-06 22:58:21 +08:00
...otherProps
} = props;
2021-05-18 04:25:07 +08:00
const {
input,
2021-06-01 04:28:57 +08:00
output,
2021-05-18 04:25:07 +08:00
layoutType,
layoutLoaded,
2021-05-18 04:25:07 +08:00
deviceType,
} = newLayoutContextState;
const { sidebarContent, sidebarNavigation } = input;
2021-06-01 04:28:57 +08:00
const { actionBar: actionsBarStyle } = output;
const { sidebarNavPanel } = sidebarNavigation;
const { sidebarContentPanel } = sidebarContent;
2021-05-18 04:25:07 +08:00
const sidebarNavigationIsOpen = sidebarNavigation.isOpen;
const sidebarContentIsOpen = sidebarContent.isOpen;
2017-10-06 22:58:21 +08:00
2021-07-21 21:19:47 +08:00
return currentUserId
? (
<App
{...{
actionsbar,
actionsBarStyle,
currentUserId,
media,
layoutType,
layoutLoaded,
meetingLayout,
settingsLayout,
pushLayoutToEveryone,
deviceType,
newLayoutContextDispatch,
sidebarNavPanel,
sidebarNavigationIsOpen,
sidebarContentPanel,
sidebarContentIsOpen,
}}
{...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 }) => {
const authTokenValidation = AuthTokenValidation.findOne({}, { sort: { updatedAt: -1 } });
if (authTokenValidation.connectionId !== Meteor.connection._lastSessionId) {
endMeeting('403');
}
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,
},
},
);
const currentMeeting = Meetings.findOne({ meetingId: Auth.meetingID },
{
fields: {
publishedPoll: 1,
voiceProp: 1,
randomlySelectedUser: 1,
layout: 1,
},
});
const {
publishedPoll,
voiceProp,
randomlySelectedUser,
layout,
} = currentMeeting;
2017-07-14 22:18:07 +08:00
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-18 04:25:07 +08:00
const layoutManagerLoaded = Session.get('layoutManagerLoaded');
2021-05-28 01:46:27 +08:00
const AppSettings = Settings.application;
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()
&& (viewScreenshare || MediaService.isUserPresenter()) && !shouldShowExternalVideo;
2021-05-18 04:25:07 +08:00
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: getFromUserSettings('bbb_custom_style_url', false),
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',
2019-06-01 02:36:52 +08:00
meetingMuted: voiceProp.muteOnStart,
currentUserEmoji: currentUserEmoji(currentUser),
2019-06-01 02:36:52 +08:00
hasPublishedPoll: publishedPoll,
2021-05-18 04:25:07 +08:00
layoutManagerLoaded,
randomlySelectedUser,
2021-06-30 22:29:03 +08:00
currentUserId: currentUser?.userId,
isPresenter: currentUser?.presenter,
meetingLayout: layout,
2021-06-22 04:28:51 +08:00
settingsLayout: AppSettings.selectedLayout,
pushLayoutToEveryone: AppSettings.pushLayoutToEveryone,
2021-05-28 01:46:27 +08:00
audioAlertEnabled: AppSettings.chatAudioAlerts,
pushAlertEnabled: AppSettings.chatPushAlerts,
shouldShowScreenshare,
2021-06-16 20:53:27 +08:00
shouldShowPresentation: !shouldShowScreenshare && !shouldShowExternalVideo,
shouldShowExternalVideo,
isLargeFont: Session.get('isLargeFont'),
2017-06-03 03:25:02 +08:00
};
2018-10-03 03:53:13 +08:00
})(AppContainer)));
AppContainer.defaultProps = defaultProps;
2017-10-06 22:58:21 +08:00
AppContainer.propTypes = propTypes;