bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/publishers.js
Oswaldo Acauan 2f741df97b Impl user-session based connections on server. Fix #5150
Implement a connectionId for each user, each time a user try to validate we change their connectionId
and end all other connections of that user.
2018-02-20 11:26:36 -03:00

71 lines
1.5 KiB
JavaScript

import Users from '/imports/api/users';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import mapToAcl from '/imports/startup/mapToAcl';
import userLeaving from './methods/userLeaving';
Meteor.publish('current-user', (credentials) => {
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
const selector = {
meetingId,
userId: requesterUserId,
authToken: requesterToken,
};
const options = {
fields: {
user: false,
},
};
return Users.find(selector, options);
});
function users(credentials) {
const {
meetingId,
requesterUserId,
requesterToken,
} = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
this.onStop(() => {
try {
userLeaving(credentials, requesterUserId, this.connection.id);
} catch (e) {
Logger.error(`Exception while executing userLeaving: ${e}`);
}
});
const selector = {
meetingId,
};
const options = {
fields: {
authToken: false,
},
};
Logger.info(`Publishing Users for ${meetingId} ${requesterUserId} ${requesterToken}`);
return Users.find(selector, options);
}
function publish(...args) {
const boundUsers = users.bind(this);
return mapToAcl('subscriptions.users', boundUsers)(args);
}
Meteor.publish('users', publish);