bigbluebutton-Github/bigbluebutton-html5/imports/api/breakouts/server/publishers.js

90 lines
2.6 KiB
JavaScript
Raw Normal View History

import { Meteor } from 'meteor/meteor';
import Breakouts from '/imports/api/breakouts';
2019-03-08 04:23:42 +08:00
import Users from '/imports/api/users';
import Logger from '/imports/startup/server/logger';
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
import { publicationSafeGuard } from '/imports/api/common/server/helpers';
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
async function breakouts() {
const tokenValidation = await AuthTokenValidation
.findOneAsync({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing Breakouts was requested by unauth connection ${this.connection.id}`);
return Breakouts.find({ meetingId: '' });
}
const { meetingId, userId } = tokenValidation;
const User = await Users.findOneAsync({ userId, meetingId }, { fields: { role: 1 } });
2020-11-24 23:13:09 +08:00
Logger.debug('Publishing Breakouts', { meetingId, userId });
2022-08-31 03:21:12 +08:00
const fields = {
fields: {
[`url_${userId}`]: 1,
breakoutId: 1,
externalId: 1,
freeJoin: 1,
isDefaultName: 1,
joinedUsers: 1,
name: 1,
parentMeetingId: 1,
sequence: 1,
shortName: 1,
timeRemaining: 1,
captureNotes: 1,
captureSlides: 1,
sendInviteToModerators: 1,
2022-08-31 03:21:12 +08:00
},
};
if (!!User && User.role === ROLE_MODERATOR) {
const presenterSelector = {
$or: [
{ parentMeetingId: meetingId },
{ breakoutId: meetingId },
],
};
// Monitor this publication and stop it when user is not a moderator anymore
const comparisonFunc = async () => {
const user = await Users.findOneAsync({ userId, meetingId }, { fields: { role: 1, userId: 1 } });
const condition = user.role === ROLE_MODERATOR;
if (!condition) {
Logger.info(`conditions aren't filled anymore in publication ${this._name}:
user.role === ROLE_MODERATOR :${condition}, user.role: ${user.role} ROLE_MODERATOR: ${ROLE_MODERATOR}`);
}
return condition;
};
publicationSafeGuard(comparisonFunc, this);
2022-08-31 03:21:12 +08:00
return Breakouts.find(presenterSelector, fields);
}
2018-06-07 05:24:09 +08:00
const selector = {
$or: [
{
parentMeetingId: meetingId,
freeJoin: true,
},
{
parentMeetingId: meetingId,
[`url_${userId}`]: { $exists: true },
},
{
breakoutId: meetingId,
},
],
2018-06-07 05:24:09 +08:00
};
return Breakouts.find(selector, fields);
2017-06-06 03:12:06 +08:00
}
function publish(...args) {
const boundBreakouts = breakouts.bind(this);
return boundBreakouts(...args);
2017-06-06 03:12:06 +08:00
}
Meteor.publish('breakouts', publish);