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

93 lines
2.2 KiB
JavaScript
Raw Normal View History

import _ from 'lodash';
import Users from '/imports/api/users';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
2017-02-07 23:29:27 +08:00
import userLeaving from './methods/userLeaving';
import { extractCredentials } from '/imports/api/common/server/helpers';
2017-03-11 02:33:46 +08:00
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
function currentUser() {
if (!this.userId) {
return Users.find({ meetingId: '' });
}
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
const connectionId = this.connection.id;
const onCloseConnection = Meteor.bindEnvironment(() => {
try {
userLeaving(meetingId, requesterUserId, connectionId);
} catch (e) {
Logger.error(`Exception while executing userLeaving: ${e}`);
}
});
this._session.socket.on('close', _.debounce(onCloseConnection, 100));
2017-03-11 02:33:46 +08:00
const selector = {
meetingId,
userId: requesterUserId,
};
const options = {
fields: {
user: false,
authToken: false, // Not asking for authToken from client side but also not exposing it
2017-03-11 02:33:46 +08:00
},
};
return Users.find(selector, options);
}
function publishCurrentUser(...args) {
const boundUsers = currentUser.bind(this);
return boundUsers(...args);
}
Meteor.publish('current-user', publishCurrentUser);
2017-03-11 02:33:46 +08:00
function users() {
if (!this.userId) {
return Users.find({ meetingId: '' });
}
const { meetingId, requesterUserId } = extractCredentials(this.userId);
2017-02-07 23:29:27 +08:00
const selector = {
$or: [
{ meetingId },
],
};
const User = Users.findOne({ userId: requesterUserId, meetingId }, { fields: { role: 1 } });
if (!!User && User.role === ROLE_MODERATOR) {
selector.$or.push({
'breakoutProps.isBreakoutUser': true,
'breakoutProps.parentId': meetingId,
connectionStatus: 'online',
});
}
const options = {
fields: {
authToken: false,
2019-07-02 03:00:27 +08:00
lastPing: false,
},
};
Logger.debug(`Publishing Users for ${meetingId} ${requesterUserId}`);
return Users.find(selector, options);
}
2017-06-06 03:12:06 +08:00
function publish(...args) {
const boundUsers = users.bind(this);
return boundUsers(...args);
2017-06-06 03:12:06 +08:00
}
Meteor.publish('users', publish);