2018-03-17 03:18:10 +08:00
|
|
|
import _ from 'lodash';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-02-06 23:56:09 +08:00
|
|
|
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';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2019-06-29 04:52:19 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
|
2020-02-14 03:19:29 +08:00
|
|
|
function currentUser() {
|
2020-02-07 04:47:28 +08:00
|
|
|
if (!this.userId) {
|
|
|
|
return Users.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2017-02-06 23:56:09 +08:00
|
|
|
|
2020-02-14 03:19:29 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
|
2018-03-17 03:18:10 +08:00
|
|
|
const connectionId = this.connection.id;
|
|
|
|
const onCloseConnection = Meteor.bindEnvironment(() => {
|
|
|
|
try {
|
2020-02-07 04:47:28 +08:00
|
|
|
userLeaving(meetingId, requesterUserId, connectionId);
|
2018-03-17 03:18:10 +08:00
|
|
|
} 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,
|
2020-02-07 04:47:28 +08:00
|
|
|
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);
|
2020-02-14 03:19:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publishCurrentUser(...args) {
|
|
|
|
const boundUsers = currentUser.bind(this);
|
|
|
|
return boundUsers(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('current-user', publishCurrentUser);
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
function users(isModerator = false) {
|
|
|
|
if (!this.userId) {
|
|
|
|
return Users.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2017-02-07 23:29:27 +08:00
|
|
|
|
2017-02-06 23:56:09 +08:00
|
|
|
const selector = {
|
2019-02-08 00:42:47 +08:00
|
|
|
$or: [
|
|
|
|
{ meetingId },
|
|
|
|
],
|
2017-02-06 23:56:09 +08:00
|
|
|
};
|
|
|
|
|
2019-02-08 03:40:27 +08:00
|
|
|
if (isModerator) {
|
2020-03-04 23:54:32 +08:00
|
|
|
const User = Users.findOne({ userId: requesterUserId, meetingId });
|
2019-06-29 04:52:19 +08:00
|
|
|
if (!!User && User.role === ROLE_MODERATOR) {
|
2019-03-08 04:23:42 +08:00
|
|
|
selector.$or.push({
|
|
|
|
'breakoutProps.isBreakoutUser': true,
|
|
|
|
'breakoutProps.parentId': meetingId,
|
|
|
|
connectionStatus: 'online',
|
|
|
|
});
|
|
|
|
}
|
2019-02-08 03:40:27 +08:00
|
|
|
}
|
|
|
|
|
2017-02-06 23:56:09 +08:00
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
authToken: false,
|
2019-07-02 03:00:27 +08:00
|
|
|
lastPing: false,
|
2017-02-06 23:56:09 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
Logger.debug(`Publishing Users for ${meetingId} ${requesterUserId}`);
|
2017-02-06 23:56:09 +08:00
|
|
|
|
|
|
|
return Users.find(selector, options);
|
2017-06-01 21:12:11 +08:00
|
|
|
}
|
2017-06-06 03:12:06 +08:00
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundUsers = users.bind(this);
|
2018-11-06 03:30:37 +08:00
|
|
|
return boundUsers(...args);
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 03:07:02 +08:00
|
|
|
Meteor.publish('users', publish);
|