bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/lock-viewers/context/container.jsx

49 lines
1.8 KiB
React
Raw Normal View History

import React, { useMemo } from 'react';
import { LockStruct } from './context';
2019-05-24 00:47:56 +08:00
import { withLockContext } from './withContext';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import useMeeting from '/imports/ui/core/hooks/useMeeting';
2019-05-24 00:47:56 +08:00
const lockContextContainer = (component) => (props) => {
const lockSetting = new LockStruct();
const { data: meeting } = useMeeting((m) => ({
lockSettings: m.lockSettings,
}));
const { data: user } = useCurrentUser((u) => ({
role: u.role,
locked: u.locked,
}));
const ROLE_MODERATOR = window.meetingClientSettings.public.user.role_moderator;
const userIsLocked = user ? user.locked && user.role !== ROLE_MODERATOR : true;
const { lockSettings } = meeting || {};
2019-05-24 00:47:56 +08:00
lockSetting.isLocked = userIsLocked;
lockSetting.lockSettings = lockSettings;
lockSetting.userLocks.userWebcam = (userIsLocked && lockSettings?.disableCam) || false;
lockSetting.userLocks.userMic = (userIsLocked && lockSettings?.disableMic) || false;
lockSetting.userLocks.userNotes = (userIsLocked && lockSettings?.disableNotes) || false;
lockSetting.userLocks.userPrivateChat = (userIsLocked
&& lockSettings?.disablePrivateChat) || false;
lockSetting.userLocks.userPublicChat = (userIsLocked && lockSettings?.disablePublicChat) || false;
lockSetting.userLocks.hideViewersCursor = (userIsLocked
&& lockSettings?.hideViewersCursor) || false;
lockSetting.userLocks.hideViewersAnnotation = (userIsLocked
&& lockSettings?.hideViewersAnnotation) || false;
2019-05-24 00:47:56 +08:00
const ComponentWithContext = useMemo(() => withLockContext(component), []);
// eslint-disable-next-line react/prop-types
const { children } = props;
return (
<ComponentWithContext
{...props}
{...lockSetting}
>
{children}
</ComponentWithContext>
);
};
2019-05-24 00:47:56 +08:00
export default lockContextContainer;