2024-06-13 21:54:46 +08:00
|
|
|
import React, { useMemo } from 'react';
|
2019-06-12 02:23:27 +08:00
|
|
|
import { LockStruct } from './context';
|
2019-05-24 00:47:56 +08:00
|
|
|
import { withLockContext } from './withContext';
|
2024-06-13 02:09:09 +08:00
|
|
|
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
|
|
|
|
import useMeeting from '/imports/ui/core/hooks/useMeeting';
|
2019-05-24 00:47:56 +08:00
|
|
|
|
2024-06-13 02:09:09 +08:00
|
|
|
const lockContextContainer = (component) => (props) => {
|
2019-06-12 02:23:27 +08:00
|
|
|
const lockSetting = new LockStruct();
|
2024-06-13 02:09:09 +08:00
|
|
|
|
|
|
|
const { data: meeting } = useMeeting((m) => ({
|
|
|
|
lockSettings: m.lockSettings,
|
|
|
|
}));
|
|
|
|
const { data: user } = useCurrentUser((u) => ({
|
|
|
|
role: u.role,
|
|
|
|
locked: u.locked,
|
|
|
|
}));
|
2024-05-29 21:26:11 +08:00
|
|
|
|
|
|
|
const ROLE_MODERATOR = window.meetingClientSettings.public.user.role_moderator;
|
2024-06-13 02:09:09 +08:00
|
|
|
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;
|
2024-06-13 02:09:09 +08:00
|
|
|
lockSetting.userLocks.userWebcam = userIsLocked && lockSettings?.disableCam;
|
|
|
|
lockSetting.userLocks.userMic = userIsLocked && lockSettings?.disableMic;
|
|
|
|
lockSetting.userLocks.userNotes = userIsLocked && lockSettings?.disableNotes;
|
|
|
|
lockSetting.userLocks.userPrivateChat = userIsLocked && lockSettings?.disablePrivateChat;
|
|
|
|
lockSetting.userLocks.userPublicChat = userIsLocked && lockSettings?.disablePublicChat;
|
|
|
|
lockSetting.userLocks.hideViewersCursor = userIsLocked && lockSettings?.hideViewersCursor;
|
|
|
|
lockSetting.userLocks.hideViewersAnnotation = userIsLocked && lockSettings?.hideViewersAnnotation;
|
2019-05-24 00:47:56 +08:00
|
|
|
|
2024-06-13 21:54:46 +08:00
|
|
|
const ComponentWithContext = useMemo(() => withLockContext(component), []);
|
2024-06-13 02:09:09 +08:00
|
|
|
// 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;
|