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

58 lines
1.9 KiB
React
Raw Normal View History

import React, { useContext } from 'react';
import { makeCall } from '/imports/ui/services/api';
2018-09-24 06:20:20 +08:00
import { withTracker } from 'meteor/react-meteor-data';
import Presentations from '/imports/api/presentations';
import PresentationAreaService from '/imports/ui/components/presentation/service';
2019-03-15 03:34:53 +08:00
import Poll from '/imports/ui/components/poll/component';
import Service from './service';
import Auth from '/imports/ui/services/auth';
import { UsersContext } from '../components-data/users-context/context';
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_CHAT_KEY = CHAT_CONFIG.public_id;
const PollContainer = ({ ...props }) => {
const usingUsersContext = useContext(UsersContext);
const { users } = usingUsersContext;
const usernames = {};
Object.values(users[Auth.meetingID]).forEach((user) => {
usernames[user.userId] = { userId: user.userId, name: user.name };
});
return <Poll {...props} usernames={usernames} />;
};
2018-09-24 06:20:20 +08:00
export default withTracker(() => {
Meteor.subscribe('current-poll');
2018-10-29 23:27:50 +08:00
const currentPresentation = Presentations.findOne({
current: true,
}, { fields: { podId: 1 } }) || {};
const currentSlide = PresentationAreaService.getCurrentSlide(currentPresentation.podId);
const pollId = currentSlide ? currentSlide.id : PUBLIC_CHAT_KEY;
const startPoll = (type, question = '') => makeCall('startPoll', type, pollId, question);
const startCustomPoll = (type, question = '', answers) => makeCall('startPoll', type, pollId, question, answers);
2018-09-24 06:20:20 +08:00
const stopPoll = () => makeCall('stopPoll');
2018-09-24 06:20:20 +08:00
return {
currentSlide,
amIPresenter: Service.amIPresenter(),
pollTypes: Service.pollTypes,
2018-09-24 06:20:20 +08:00
startPoll,
startCustomPoll,
stopPoll,
publishPoll: Service.publishPoll,
currentPoll: Service.currentPoll(),
resetPollPanel: Session.get('resetPollPanel') || false,
2019-05-23 02:00:44 +08:00
pollAnswerIds: Service.pollAnswerIds,
isMeteorConnected: Meteor.status().connected,
2018-09-24 06:20:20 +08:00
};
})(PollContainer);