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';
|
2017-03-11 02:33:46 +08:00
|
|
|
|
2018-03-17 03:18:10 +08:00
|
|
|
Meteor.publish('current-user', function currentUserPub(credentials) {
|
2017-02-06 23:56:09 +08:00
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
2018-03-17 03:18:10 +08:00
|
|
|
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));
|
|
|
|
|
2017-02-06 23:56:09 +08:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2017-06-01 01:54:43 +08:00
|
|
|
function users(credentials) {
|
|
|
|
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
|
|
|
|
2017-02-06 23:56:09 +08:00
|
|
|
const selector = {
|
2017-04-13 04:19:39 +08:00
|
|
|
meetingId,
|
2017-02-06 23:56:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
authToken: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-10-13 03:07:02 +08:00
|
|
|
Logger.info(`Publishing Users for ${meetingId} ${requesterUserId} ${requesterToken}`);
|
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);
|