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

88 lines
1.9 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';
2017-03-11 02:33:46 +08:00
Meteor.publish('current-user', function currentUserPub(credentials) {
const { meetingId, requesterUserId, requesterToken } = credentials;
const connectionId = this.connection.id;
const onCloseConnection = Meteor.bindEnvironment(() => {
try {
userLeaving(credentials, requesterUserId, connectionId);
} catch (e) {
Logger.error(`Exception while executing userLeaving: ${e}`);
}
});
this._session.socket.on('close', _.debounce(onCloseConnection, 100));
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
2017-03-11 02:33:46 +08:00
const selector = {
meetingId,
userId: requesterUserId,
authToken: requesterToken,
};
const options = {
fields: {
user: false,
},
};
return Users.find(selector, options);
});
function users(credentials, isModerator = false) {
2017-06-01 01:54:43 +08:00
const {
meetingId,
requesterUserId,
2017-06-06 00:40:36 +08:00
requesterToken,
2017-06-01 01:54:43 +08:00
} = credentials;
2017-03-11 02:33:46 +08:00
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
2017-02-07 23:29:27 +08:00
const selector = {
$or: [
{ meetingId },
],
};
if (isModerator) {
2019-03-08 04:23:42 +08:00
const User = Users.findOne({ userId: requesterUserId });
if (!!User && User.moderator) {
2019-03-08 04:23:42 +08:00
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} ${requesterToken}`);
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);