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

194 lines
6.7 KiB
JavaScript
Raw Normal View History

2016-10-22 00:27:47 +08:00
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import Meetings, {
RecordMeetings,
MeetingTimeRemaining,
ExternalVideoMeetings,
LayoutMeetings,
} from '/imports/api/meetings';
2019-03-08 04:23:42 +08:00
import Users from '/imports/api/users';
2016-10-22 00:27:47 +08:00
import Logger from '/imports/startup/server/logger';
import { publicationSafeGuard } from '/imports/api/common/server/helpers';
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
2022-03-11 03:33:25 +08:00
import notificationEmitter from '../notificationEmitter';
2016-10-22 00:27:47 +08:00
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
function meetings() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing Meetings was requested by unauth connection ${this.connection.id}`);
return Meetings.find({ meetingId: '' });
}
2016-10-22 00:27:47 +08:00
const { meetingId, userId } = tokenValidation;
2020-11-24 23:13:09 +08:00
Logger.debug('Publishing meeting', { meetingId, userId });
2016-10-22 00:27:47 +08:00
const selector = {
2018-10-17 01:55:20 +08:00
$or: [
{ meetingId },
],
};
const User = Users.findOne({ userId, meetingId }, { fields: { userId: 1, role: 1 } });
if (!!User && User.role === ROLE_MODERATOR) {
selector.$or.push({
'meetingProp.isBreakout': true,
'breakoutProps.parentId': meetingId,
});
// Monitor this publication and stop it when user is not a moderator anymore
const comparisonFunc = () => {
const user = Users.findOne({ 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}`);
}
2019-03-08 00:33:34 +08:00
return condition;
};
publicationSafeGuard(comparisonFunc, this);
}
const options = {
fields: {
password: false,
'welcomeProp.modOnlyMessage': false,
},
};
if (User.role !== ROLE_MODERATOR) {
options.fields.learningDashboardAccessToken = false;
}
return Meetings.find(selector, options);
2017-06-06 03:12:06 +08:00
}
function publish(...args) {
const boundMeetings = meetings.bind(this);
return boundMeetings(...args);
2017-06-06 03:12:06 +08:00
}
Meteor.publish('meetings', publish);
function recordMeetings() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing RecordMeetings was requested by unauth connection ${this.connection.id}`);
return RecordMeetings.find({ meetingId: '' });
}
const { meetingId, userId } = tokenValidation;
Logger.debug(`Publishing RecordMeetings for ${meetingId} ${userId}`);
return RecordMeetings.find({ meetingId });
}
function recordPublish(...args) {
const boundRecordMeetings = recordMeetings.bind(this);
return boundRecordMeetings(...args);
}
Meteor.publish('record-meetings', recordPublish);
function layoutMeetings() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing LayoutMeetings was requested by unauth connection ${this.connection.id}`);
return LayoutMeetings.find({ meetingId: '' });
}
const { meetingId, userId } = tokenValidation;
Logger.debug(`Publishing LayoutMeetings for ${meetingId} ${userId}`);
return LayoutMeetings.find({ meetingId });
}
function layoutPublish(...args) {
const boundLayoutMeetings = layoutMeetings.bind(this);
return boundLayoutMeetings(...args);
}
Meteor.publish('layout-meetings', layoutPublish);
function externalVideoMeetings() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing ExternalVideoMeetings was requested by unauth connection ${this.connection.id}`);
return ExternalVideoMeetings.find({ meetingId: '' });
}
const { meetingId, userId } = tokenValidation;
Logger.debug(`Publishing ExternalVideoMeetings for ${meetingId} ${userId}`);
return ExternalVideoMeetings.find({ meetingId });
}
function externalVideoPublish(...args) {
const boundExternalVideoMeetings = externalVideoMeetings.bind(this);
return boundExternalVideoMeetings(...args);
}
Meteor.publish('external-video-meetings', externalVideoPublish);
function meetingTimeRemaining() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing MeetingTimeRemaining was requested by unauth connection ${this.connection.id}`);
return MeetingTimeRemaining.find({ meetingId: '' });
}
const { meetingId, userId } = tokenValidation;
Logger.debug(`Publishing MeetingTimeRemaining for ${meetingId} ${userId}`);
2019-09-09 22:48:50 +08:00
return MeetingTimeRemaining.find({ meetingId });
}
function timeRemainingPublish(...args) {
const boundtimeRemaining = meetingTimeRemaining.bind(this);
return boundtimeRemaining(...args);
}
Meteor.publish('meeting-time-remaining', timeRemainingPublish);
2022-03-11 03:33:25 +08:00
function notifications() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
2022-04-13 00:56:54 +08:00
if (tokenValidation && tokenValidation.validationStatus === ValidationStates.VALIDATED) {
2022-03-11 03:33:25 +08:00
notificationEmitter.on('notification', (notification) => {
const { meetingId, userId } = tokenValidation;
switch (notification.type) {
case 'notifyAllInMeeting':
if (notification.meetingId === meetingId) this.added('notifications', Random.id(), notification);
2022-03-11 03:33:25 +08:00
break;
case 'NotifyUserInMeeting':
if (notification.meetingId === meetingId && notification.userId === userId) this.added('notifications', Random.id(), notification);
2022-03-11 03:33:25 +08:00
break;
case 'NotifyRoleInMeeting': {
const user = Users.findOne({ userId, meetingId }, { fields: { role: 1, userId: 1 } });
if (notification.meetingId === meetingId && notification.role === user.role) this.added('notifications', Random.id(), notification);
2022-03-11 03:33:25 +08:00
break;
}
default: Logger.warn(`wrong type: ${notification.type} userId: ${userId}`);
}
});
this.ready();
} else {
Logger.warn(`Publishing notification was requested by unauth connection ${this.connection.id}`);
}
}
function notificationsPublish(...args) {
const boundNotifications = notifications.bind(this);
return boundNotifications(...args);
}
Meteor.publish('notifications', notificationsPublish);