Refactor methods/events for user leaving iteractions

This commit is contained in:
Oswaldo Acauan 2017-02-07 13:08:06 +00:00
parent 32ba6ad724
commit fda22b0653
9 changed files with 120 additions and 14 deletions

View File

@ -1,8 +1,10 @@
import { Meteor } from 'meteor/meteor';
import kickUser from './methods/kickUser';
import listenOnlyRequestToggle from './methods/listenOnlyRequestToggle';
import userLogout from './methods/userLogout';
Meteor.methods({
kickUser,
listenOnlyRequestToggle,
userLogout,
});

View File

@ -1,3 +1,4 @@
import Meteor from 'meteor/meteor';
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';

View File

@ -1,3 +1,4 @@
import Meteor from 'meteor/meteor';
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';

View File

@ -0,0 +1,43 @@
import Meteor from 'meteor/meteor';
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
import { isAllowedTo } from '/imports/startup/server/userPermissions';
import listenOnlyRequestToggle from './listenOnlyRequestToggle';
export default function userLeaving(credentials, userId) {
const REDIS_CONFIG = Meteor.settings.redis;
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.meeting;
const EVENT_NAME = 'user_leaving_request';
const { meetingId, requesterUserId } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(userId, String);
// TODO: Should we check if requesterUserId is equal to userId?
const User = Users.findOne({
meetingId,
userId: requesterUserId,
});
if (!User) {
throw new Meteor.Error(
'user-not-found', `You need a valid user to be able to toggle audio`);
}
if (User.user.listenOnly) {
listenOnlyRequestToggle(credentials, false);
}
let payload = {
meeting_id: meetingId,
userid: userId,
};
Logger.verbose(`User '${requesterUserId}' ${isJoining ? 'joined' : 'left'} global audio from meeting '${meetingId}'`);
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload);
};

View File

@ -1,13 +1,14 @@
import Meteor from 'meteor/meteor';
import { isAllowedTo } from '/imports/startup/server/userPermissions';
import { requestUserLeaving } from '/imports/api/users/server/modifiers/requestUserLeaving';
import { logger } from '/imports/startup/server/logger';
Meteor.methods({
userLogout(credentials) {
if (isAllowedTo('logoutSelf', credentials)) {
const { meetingId, requesterUserId, requesterToken } = credentials;
logger.info(`a user is logging out from ${meetingId}:${requesterUserId}`);
return requestUserLeaving(meetingId, requesterUserId);
}
},
});
import userLeaving from './userLeaving';
export default function userLogout(credentials) {
if (!isAllowedTo('logoutSelf', credentials)) {
throw new Meteor.Error('not-allowed', `You are not allowed to logoutSelf`);
}
const { requesterUserId } = credentials;
return userLeaving(credentials, requesterUserId);
};

View File

@ -61,3 +61,22 @@ export function requestUserLeaving(meetingId, userId) {
return logger.info('did not have enough information to send a user_leaving_request');
}
};
if (this.connection == null) {
Meteor.users.update(update.id,{
$set: {
"profile.name": update.name
}
});
} else {
throw new Meteor.Error('server-only-method', 'Sorry, this method can only be called from the server.');
}

View File

@ -0,0 +1,38 @@
import { check } from 'meteor/check';
import Users from '/imports/api/slides';
import Logger from '/imports/startup/server/logger';
const VALID_CONNECTION_STATUS = ['online', 'offline'];
export default function setConnectionStatus(meetingId, userId, status = 'online') {
check(meetingId, String);
check(userId, String);
check(connectionStatus, String);
if (!VALID_CONNECTION_STATUS.includes(status)) {
throw `Invalid connection status, received ${status} expecting ${VALID_CONNECTION_STATUS.join()}`;
}
const selector = {
meetingId,
userId,
};
const modifier = {
$set: {
'user.connection_status': status,
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Updating connection status user=${userId}: ${err}`);
}
if (numChanged) {
return Logger.verbose(`Updated connection status user=${userId} status=${status} meeting=${meetingId}`);
}
};
return Users.update(selector, modifier, cb);
};

View File

@ -1,9 +1,11 @@
import Users from '/imports/api/Users';
import Users from '/imports/api/users';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import { isAllowedTo } from '/imports/startup/server/userPermissions';
import setConnectionStatus from './modifiers/setConnectionStatus';
Meteor.publish('Users', function (credentials) {
// TODO: Some publishers have ACL and others dont
// if (!isAllowedTo('@@@', credentials)) {
@ -22,7 +24,7 @@ Meteor.publish('Users', function (credentials) {
// - Update `connection_status` when the user disconnects
this.onStop(() => {
// update connection_status info to offline
setConnectionStatus(meetingId, requesterUserId, 'offline');
});
const selector = {

View File

@ -31,7 +31,6 @@ import '/imports/api/users/server';
import '/imports/api/users/server/methods/muteUser';
import '/imports/api/users/server/methods/setUserPresenter';
import '/imports/api/users/server/methods/unmuteUser';
import '/imports/api/users/server/methods/userLogout';
import '/imports/api/users/server/methods/userSetEmoji';
import '/imports/api/users/server/methods/validateAuthToken';
import '/imports/api/users/server/modifiers/clearUsersCollection';