bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/methods/startPoll.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

import RedisPubSub from '/imports/startup/server/redis';
import { check } from 'meteor/check';
import { extractCredentials } from '/imports/api/common/server/helpers';
2021-05-05 22:12:36 +08:00
import Logger from '/imports/startup/server/logger';
export default function startPoll(pollType, pollId, secretPoll, question, answers) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
2018-09-24 06:20:20 +08:00
let EVENT_NAME = 'StartPollReqMsg';
2021-05-05 22:12:36 +08:00
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
2021-05-05 22:12:36 +08:00
check(meetingId, String);
check(requesterUserId, String);
check(pollId, String);
check(pollType, String);
check(secretPoll, Boolean);
2021-05-05 22:12:36 +08:00
const payload = {
requesterId: requesterUserId,
pollId: `${pollId}/${new Date().getTime()}`,
pollType,
secretPoll,
2021-05-05 22:12:36 +08:00
question,
};
2021-05-05 22:12:36 +08:00
if (pollType === 'custom') {
EVENT_NAME = 'StartCustomPollReqMsg';
check(answers, Array);
payload.answers = answers;
}
2018-09-24 06:20:20 +08:00
2021-05-05 22:12:36 +08:00
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
} catch (err) {
Logger.error(`Exception while invoking method startPoll ${err.stack}`);
}
}