bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/presentation/presentation-toolbar/container.jsx

125 lines
3.5 KiB
React
Raw Normal View History

import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import PresentationToolbar from './component';
import FullscreenService from '/imports/ui/components/common/fullscreen-button/service';
import { useIsPollingEnabled } from '/imports/ui/services/features';
import { PluginsContext } from '/imports/ui/components/components-data/plugin-context/context';
2023-12-09 04:24:57 +08:00
import { useSubscription, useMutation } from '@apollo/client';
2023-10-13 02:21:22 +08:00
import POLL_SUBSCRIPTION from '/imports/ui/core/graphql/queries/pollSubscription';
2023-12-11 21:31:13 +08:00
import { POLL_CANCEL, POLL_CREATE } from '/imports/ui/components/poll/mutations';
2024-01-20 22:01:20 +08:00
import { PRESENTATION_SET_PAGE } from '../mutations';
const PresentationToolbarContainer = (props) => {
const pluginsContext = useContext(PluginsContext);
const { pluginsExtensibleAreasAggregatedState } = pluginsContext;
2024-01-20 22:01:20 +08:00
const {
userIsPresenter,
layoutSwapped,
currentSlideNum,
presentationId,
} = props;
2016-08-03 06:55:20 +08:00
2023-10-13 02:21:22 +08:00
const { data: pollData } = useSubscription(POLL_SUBSCRIPTION);
const hasPoll = pollData?.poll?.length > 0;
const handleToggleFullScreen = (ref) => FullscreenService.toggleFullScreen(ref);
2023-12-09 04:24:57 +08:00
const [stopPoll] = useMutation(POLL_CANCEL);
2023-12-11 21:31:13 +08:00
const [createPoll] = useMutation(POLL_CREATE);
2024-01-20 22:01:20 +08:00
const [presentationSetPage] = useMutation(PRESENTATION_SET_PAGE);
2023-12-09 04:24:57 +08:00
2023-03-16 02:06:59 +08:00
const endCurrentPoll = () => {
2023-12-09 04:24:57 +08:00
if (hasPoll) stopPoll();
2023-03-16 02:24:34 +08:00
};
2023-03-16 02:06:59 +08:00
2024-01-20 22:01:20 +08:00
const setPresentationPage = (pageId) => {
presentationSetPage({
variables: {
presentationId,
pageId,
},
});
};
const skipToSlide = (slideNum) => {
const slideId = `${presentationId}/${slideNum}`;
setPresentationPage(slideId);
};
const previousSlide = () => {
const prevSlideNum = currentSlideNum - 1;
skipToSlide(prevSlideNum);
};
const nextSlide = () => {
const nextSlideNum = currentSlideNum + 1;
skipToSlide(nextSlideNum);
};
2023-12-11 21:31:13 +08:00
const startPoll = (pollType, pollId, answers = [], question, isMultipleResponse = false) => {
Session.set('openPanel', 'poll');
Session.set('forcePollOpen', true);
window.dispatchEvent(new Event('panelChanged'));
createPoll({
variables: {
pollType,
pollId: `${pollId}/${new Date().getTime()}`,
secretPoll: false,
question,
isMultipleResponse,
answers,
},
});
};
const isPollingEnabled = useIsPollingEnabled();
if (userIsPresenter && !layoutSwapped) {
// Only show controls if user is presenter and layout isn't swapped
const pluginProvidedPresentationToolbarItems = pluginsExtensibleAreasAggregatedState
?.presentationToolbarItems;
return (
<PresentationToolbar
{...props}
2021-11-24 00:04:45 +08:00
amIPresenter={userIsPresenter}
2023-03-16 02:06:59 +08:00
endCurrentPoll={endCurrentPoll}
isPollingEnabled={isPollingEnabled}
// TODO: Remove this
isMeteorConnected
{...{
pluginProvidedPresentationToolbarItems,
handleToggleFullScreen,
2023-12-11 21:31:13 +08:00
startPoll,
2024-01-20 22:01:20 +08:00
previousSlide,
nextSlide,
skipToSlide,
}}
/>
);
2016-08-03 06:55:20 +08:00
}
return null;
};
2016-08-03 06:55:20 +08:00
export default PresentationToolbarContainer;
2016-08-03 06:55:20 +08:00
PresentationToolbarContainer.propTypes = {
// Number of current slide being displayed
currentSlideNum: PropTypes.number.isRequired,
2018-08-23 01:49:33 +08:00
zoom: PropTypes.number.isRequired,
zoomChanger: PropTypes.func.isRequired,
// Total number of slides in this presentation
numberOfSlides: PropTypes.number.isRequired,
// Actions required for the presenter toolbar
layoutSwapped: PropTypes.bool,
};
PresentationToolbarContainer.defaultProps = {
layoutSwapped: false,
};