bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/methods/publishPoll.js
2021-05-05 11:12:36 -03:00

35 lines
1.1 KiB
JavaScript

import RedisPubSub from '/imports/startup/server/redis';
import Polls from '/imports/api/polls';
import Logger from '/imports/startup/server/logger';
import { extractCredentials } from '/imports/api/common/server/helpers';
import { check } from 'meteor/check';
export default function publishPoll() {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'ShowPollResultReqMsg';
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
const poll = Polls.findOne({ meetingId }); // TODO--send pollid from client
if (!poll) {
Logger.error(`Attempted to publish inexisting poll for meetingId: ${meetingId}`);
return false;
}
RedisPubSub.publishUserMessage(
CHANNEL,
EVENT_NAME,
meetingId,
requesterUserId,
({ requesterId: requesterUserId, pollId: poll.id }),
);
} catch (err) {
Logger.error(`Exception while invoking method publishPoll ${err.stack}`);
}
}