bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/actions-bar/container.jsx
Tainan Felipe 3bc40df230
Add: useDeduplicatedSubscription hook (#20376)
* Add: useDeduplicatedSubscription hook

* Fix: TS error

* Add: components using useDeduplicatedSubscription

* Change: Move to useDeduplicatedSubscription

* Change: unsubscribe logic to own useEffect

* Change: remove file import over package

* Fix: TS errors

* Fix: private chat not loading

* Change: revert changes on queries

* Fix: eslint error

* Remove: html-webpack-plugin package

* Fix: external video

* Add: comment about the stringToHash function

* Fix: video player showing tools over presentation
2024-06-04 10:40:54 -03:00

137 lines
5.1 KiB
JavaScript

import React, { useContext } from 'react';
import { Meteor } from 'meteor/meteor';
import { withTracker } from 'meteor/react-meteor-data';
import { injectIntl } from 'react-intl';
import { useMutation } from '@apollo/client';
import getFromUserSettings from '/imports/ui/services/users-settings';
import Auth from '/imports/ui/services/auth';
import ActionsBar from './component';
import { layoutSelectOutput, layoutDispatch } from '../layout/context';
import { isExternalVideoEnabled, isPollingEnabled, isPresentationEnabled, isTimerFeatureEnabled } from '/imports/ui/services/features';
import { isScreenBroadcasting, isCameraAsContentBroadcasting, useIsSharing, useSharingContentType } from '/imports/ui/components/screenshare/service';
import { PluginsContext } from '/imports/ui/components/components-data/plugin-context/context';
import {
CURRENT_PRESENTATION_PAGE_SUBSCRIPTION,
} from '/imports/ui/components/whiteboard/queries';
import MediaService from '../media/service';
import useMeeting from '/imports/ui/core/hooks/useMeeting';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import { EXTERNAL_VIDEO_STOP } from '../external-video-player/mutations';
import { PINNED_PAD_SUBSCRIPTION } from '../notes/queries';
import useDeduplicatedSubscription from '../../core/hooks/useDeduplicatedSubscription';
const ActionsBarContainer = (props) => {
const NOTES_CONFIG = window.meetingClientSettings.public.notes;
const RAISE_HAND_BUTTON_ENABLED = window.meetingClientSettings
.public.app.raiseHandActionButton.enabled;
const RAISE_HAND_BUTTON_CENTERED = window.meetingClientSettings
.public.app.raiseHandActionButton.centered;
const actionsBarStyle = layoutSelectOutput((i) => i.actionBar);
const layoutContextDispatch = layoutDispatch();
const { data: presentationPageData } = useDeduplicatedSubscription(
CURRENT_PRESENTATION_PAGE_SUBSCRIPTION,
);
const presentationPage = presentationPageData?.pres_page_curr[0] || {};
const isThereCurrentPresentation = !!presentationPage?.presentationId;
const { data: currentMeeting } = useMeeting((m) => ({
externalVideo: m.externalVideo,
componentsFlags: m.componentsFlags,
}));
const isSharingVideo = !!currentMeeting?.externalVideo?.externalVideoUrl;
const {
pluginsExtensibleAreasAggregatedState,
} = useContext(PluginsContext);
let actionBarItems = [];
if (pluginsExtensibleAreasAggregatedState.actionsBarItems) {
actionBarItems = [
...pluginsExtensibleAreasAggregatedState.actionsBarItems,
];
}
const { data: currentUserData } = useCurrentUser((user) => ({
presenter: user.presenter,
emoji: user.emoji,
isModerator: user.isModerator,
}));
const [stopExternalVideoShare] = useMutation(EXTERNAL_VIDEO_STOP);
const currentUser = {
userId: Auth.userID,
emoji: currentUserData?.emoji,
};
const amIPresenter = currentUserData?.presenter;
const amIModerator = currentUserData?.isModerator;
const { data: pinnedPadData } = useDeduplicatedSubscription(PINNED_PAD_SUBSCRIPTION);
const isSharedNotesPinnedFromGraphql = !!pinnedPadData
&& pinnedPadData.sharedNotes[0]?.sharedNotesExtId === NOTES_CONFIG.id;
const isSharedNotesPinned = isSharedNotesPinnedFromGraphql;
if (actionsBarStyle.display === false) return null;
if (!currentMeeting) return null;
return (
<ActionsBar {
...{
...props,
currentUser,
amIModerator,
layoutContextDispatch,
actionsBarStyle,
amIPresenter,
actionBarItems,
isThereCurrentPresentation,
isSharingVideo,
stopExternalVideoShare,
isSharedNotesPinned,
isTimerActive: currentMeeting.componentsFlags.hasTimer,
isTimerEnabled: isTimerFeatureEnabled(),
isRaiseHandButtonEnabled: RAISE_HAND_BUTTON_ENABLED,
isRaiseHandButtonCentered: RAISE_HAND_BUTTON_CENTERED,
}
}
/>
);
};
const isReactionsButtonEnabled = () => {
const USER_REACTIONS_ENABLED = window.meetingClientSettings.public.userReaction.enabled;
const REACTIONS_BUTTON_ENABLED = window.meetingClientSettings.public.app.reactionsButton.enabled;
return USER_REACTIONS_ENABLED && REACTIONS_BUTTON_ENABLED;
};
const ActionsBarTracker = withTracker(({ isSharing, sharingContentType }) => ({
enableVideo: getFromUserSettings('bbb_enable_video', window.meetingClientSettings.public.kurento.enableVideo),
setPresentationIsOpen: MediaService.setPresentationIsOpen,
hasScreenshare: isScreenBroadcasting(isSharing, sharingContentType),
hasCameraAsContent: isCameraAsContentBroadcasting(isSharing, sharingContentType),
isMeteorConnected: Meteor.status().connected,
isPollingEnabled: isPollingEnabled() && isPresentationEnabled(),
isReactionsButtonEnabled: isReactionsButtonEnabled(),
allowExternalVideo: isExternalVideoEnabled(),
}))(injectIntl(ActionsBarContainer));
// TODO: Remove this
// Temporary component until we remove all trackers
export default (props) => {
const isSharing = useIsSharing();
const sharingContentType = useSharingContentType();
return (
<ActionsBarTracker
{...{
...props,
isSharing,
sharingContentType,
}}
/>
);
};