bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/presentation/service.js

187 lines
5.1 KiB
JavaScript
Raw Normal View History

import PresentationPods from '/imports/api/presentation-pods';
import Presentations from '/imports/api/presentations';
import { Slides, SlidePositions } from '/imports/api/slides';
2016-11-12 03:02:46 +08:00
import Auth from '/imports/ui/services/auth';
const getCurrentPresentation = podId => Presentations.findOne({
podId,
2017-07-25 02:46:53 +08:00
current: true,
2016-11-12 03:02:46 +08:00
});
const downloadPresentationUri = (podId) => {
const currentPresentation = getCurrentPresentation(podId);
if (!currentPresentation) {
return null;
}
const presentationFileName = `${currentPresentation.id}.${currentPresentation.name.split('.').pop()}`;
const uri = `https://${window.document.location.hostname}/bigbluebutton/presentation/download/`
+ `${currentPresentation.meetingId}/${currentPresentation.id}`
+ `?presFilename=${encodeURIComponent(presentationFileName)}`;
return uri;
};
const isPresentationDownloadable = (podId) => {
const currentPresentation = getCurrentPresentation(podId);
if (!currentPresentation) {
return null;
}
return currentPresentation.downloadable;
};
const getCurrentSlide = (podId) => {
const currentPresentation = getCurrentPresentation(podId);
2016-11-12 03:02:46 +08:00
if (!currentPresentation) {
return null;
}
2019-03-12 00:21:12 +08:00
return Slides.findOne({
podId,
presentationId: currentPresentation.id,
current: true,
}, {
fields: {
meetingId: 0,
thumbUri: 0,
swfUri: 0,
txtUri: 0,
},
2019-03-12 00:21:12 +08:00
});
2016-11-12 03:02:46 +08:00
};
2016-07-16 04:45:54 +08:00
const getSlidePosition = (podId, presentationId, slideId) => SlidePositions.findOne({
podId,
presentationId,
id: slideId,
});
2019-02-22 05:01:39 +08:00
const currentSlidHasContent = () => {
const currentSlide = getCurrentSlide('DEFAULT_PRESENTATION_POD');
if (!currentSlide) return false;
2019-03-12 00:21:12 +08:00
const {
content,
} = currentSlide;
2019-02-22 05:01:39 +08:00
return !!content.length;
};
const parseCurrentSlideContent = (yesValue, noValue, abstentionValue, trueValue, falseValue) => {
2019-02-22 05:01:39 +08:00
const currentSlide = getCurrentSlide('DEFAULT_PRESENTATION_POD');
const quickPollOptions = [];
if (!currentSlide) return quickPollOptions;
2021-03-05 02:00:21 +08:00
let {
2019-03-12 00:21:12 +08:00
content,
} = currentSlide;
2019-02-22 05:01:39 +08:00
2019-10-25 02:46:19 +08:00
const pollRegex = /[1-6A-Fa-f][.)].*/g;
let optionsPoll = content.match(pollRegex) || [];
if (optionsPoll) optionsPoll = optionsPoll.map(opt => `\r${opt[0]}.`);
2019-10-25 02:46:19 +08:00
2019-02-22 05:01:39 +08:00
optionsPoll.reduce((acc, currentValue) => {
const lastElement = acc[acc.length - 1];
if (!lastElement) {
acc.push({
options: [currentValue],
});
return acc;
}
2019-03-12 00:21:12 +08:00
const {
options,
} = lastElement;
2019-02-22 05:01:39 +08:00
const lastOption = options[options.length - 1];
const isLastOptionInteger = !!parseInt(lastOption.charAt(1), 10);
const isCurrentValueInteger = !!parseInt(currentValue.charAt(1), 10);
if (isLastOptionInteger === isCurrentValueInteger) {
if (currentValue.toLowerCase().charCodeAt(1) > lastOption.toLowerCase().charCodeAt(1)) {
options.push(currentValue);
} else {
acc.push({
options: [currentValue],
});
}
} else {
acc.push({
options: [currentValue],
});
}
return acc;
2019-03-12 00:21:12 +08:00
}, []).filter(({
options,
}) => options.length > 1 && options.length < 7).forEach(poll => quickPollOptions.push({
type: `A-${poll.options.length}`,
poll,
}));
2021-03-05 02:00:21 +08:00
if (quickPollOptions.length > 0) {
content = content.replace(new RegExp(pollRegex), '');
}
const ynPollString = `(${yesValue}\\s*\\/\\s*${noValue})|(${noValue}\\s*\\/\\s*${yesValue})`;
const ynOptionsRegex = new RegExp(ynPollString, 'gi');
const ynPoll = content.match(ynOptionsRegex) || [];
const ynaPollString = `(${yesValue}\\s*\\/\\s*${noValue}\\s*\\/\\s*${abstentionValue})|(${yesValue}\\s*\\/\\s*${abstentionValue}\\s*\\/\\s*${noValue})|(${abstentionValue}\\s*\\/\\s*${yesValue}\\s*\\/\\s*${noValue})|(${abstentionValue}\\s*\\/\\s*${noValue}\\s*\\/\\s*${yesValue})|(${noValue}\\s*\\/\\s*${yesValue}\\s*\\/\\s*${abstentionValue})|(${noValue}\\s*\\/\\s*${abstentionValue}\\s*\\/\\s*${yesValue})`;
const ynaOptionsRegex = new RegExp(ynaPollString, 'gi');
const ynaPoll = content.match(ynaOptionsRegex) || [];
const tfPollString = `(${trueValue}\\s*\\/\\s*${falseValue})|(${falseValue}\\s*\\/\\s*${trueValue})`;
const tgOptionsRegex = new RegExp(tfPollString, 'gi');
const tfPoll = content.match(tgOptionsRegex) || [];
2019-03-12 00:21:12 +08:00
ynPoll.forEach(poll => quickPollOptions.push({
type: 'YN',
poll,
}));
ynaPoll.forEach(poll => quickPollOptions.push({
type: 'YNA',
poll,
}));
2019-03-12 00:21:12 +08:00
tfPoll.forEach(poll => quickPollOptions.push({
type: 'TF',
poll,
}));
return {
slideId: currentSlide.id,
quickPollOptions,
};
2019-02-22 05:01:39 +08:00
};
const isPresenter = (podId) => {
// a main presenter in the meeting always owns a default pod
if (podId !== 'DEFAULT_PRESENTATION_POD') {
// if a pod is not default, then we check whether this user owns a current pod
const selector = {
meetingId: Auth.meetingID,
podId,
};
const pod = PresentationPods.findOne(selector);
return pod.currentPresenterId === Auth.userID;
}
return true;
2016-11-22 23:46:08 +08:00
};
2016-11-12 03:02:46 +08:00
export default {
2016-11-12 03:02:46 +08:00
getCurrentSlide,
getSlidePosition,
2016-11-12 03:02:46 +08:00
isPresenter,
isPresentationDownloadable,
downloadPresentationUri,
2019-02-22 05:01:39 +08:00
currentSlidHasContent,
parseCurrentSlideContent,
getCurrentPresentation,
};