fix crash from invalid online users

This commit is contained in:
Chad Pilkey 2019-07-08 18:51:34 +00:00
parent 28cf3ec9cf
commit cb58037ea1
4 changed files with 8 additions and 11 deletions

View File

@ -3,7 +3,7 @@ import Logger from '/imports/startup/server/logger';
import _ from 'lodash'; import _ from 'lodash';
const COLLECTION_NAME = 'ping-pong'; const COLLECTION_NAME = 'ping-pong';
const POLL_INTERVAL = 5000; const POLL_INTERVAL = 15000;
function pingPong(credentials) { function pingPong(credentials) {
const { meetingId, requesterUserId } = credentials; const { meetingId, requesterUserId } = credentials;

View File

@ -1,7 +1,6 @@
import { check } from 'meteor/check'; import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger'; import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users'; import Users from '/imports/api/users';
import setConnectionStatus from '/imports/api/users/server/modifiers/setConnectionStatus';
import userJoin from '../methods/userJoin'; import userJoin from '../methods/userJoin';
const clearOtherSessions = (sessionUserId, current = false) => { const clearOtherSessions = (sessionUserId, current = false) => {
@ -54,7 +53,6 @@ export default function handleValidateAuthToken({ body }, meetingId) {
if (valid) { if (valid) {
const sessionUserId = `${meetingId}-${userId}`; const sessionUserId = `${meetingId}-${userId}`;
const currentConnectionId = User.connectionId ? User.connectionId : false; const currentConnectionId = User.connectionId ? User.connectionId : false;
setConnectionStatus(meetingId, userId);
clearOtherSessions(sessionUserId, currentConnectionId); clearOtherSessions(sessionUserId, currentConnectionId);
} }

View File

@ -3,7 +3,6 @@ import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis'; import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger'; import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users'; import Users from '/imports/api/users';
import setConnectionStatus from '/imports/api/users/server/modifiers/setConnectionStatus';
export default function userLeaving(credentials, userId, connectionId) { export default function userLeaving(credentials, userId, connectionId) {
const REDIS_CONFIG = Meteor.settings.private.redis; const REDIS_CONFIG = Meteor.settings.private.redis;
@ -38,6 +37,5 @@ export default function userLeaving(credentials, userId, connectionId) {
}; };
Logger.info(`User '${userId}' is leaving meeting '${meetingId}'`); Logger.info(`User '${userId}' is leaving meeting '${meetingId}'`);
setConnectionStatus(meetingId, userId, 'offline');
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload); return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
} }

View File

@ -11,7 +11,7 @@ import setMinBrowserVersions from './minBrowserVersion';
import userLeaving from '/imports/api/users/server/methods/userLeaving'; import userLeaving from '/imports/api/users/server/methods/userLeaving';
const parse = Npm.require('url').parse; const parse = Npm.require('url').parse;
const INTERVAL_TIME = 10000; const INTERVAL_TIME = 30000;
const AVAILABLE_LOCALES = fs.readdirSync('assets/app/locales'); const AVAILABLE_LOCALES = fs.readdirSync('assets/app/locales');
Meteor.startup(() => { Meteor.startup(() => {
@ -49,19 +49,20 @@ Meteor.startup(() => {
Logger.info('Checking for inactive users'); Logger.info('Checking for inactive users');
const users = Users.find({ const users = Users.find({
connectionStatus: 'online', connectionStatus: 'online',
clientType: 'HTML5',
lastPing: { lastPing: {
$lt: (currentTime - INTERVAL_TIME), // get user who has not pinged in the last 10 seconds $lt: (currentTime - INTERVAL_TIME), // get user who has not pinged in the last 10 seconds
}, },
loginTime: {
$lt: (currentTime - INTERVAL_TIME),
},
}).fetch(); }).fetch();
if (!users.length) return Logger.info('No inactive users'); if (!users.length) return Logger.info('No inactive users');
Logger.info('Removing inactive users'); Logger.info('Removing inactive users');
users.forEach((user) => { users.forEach((user) => {
const loginTimeDelta = currentTime - user.loginTime; Logger.info(`Detected inactive user, userId:${user.userId}, meetingId:${user.meetingId}`);
const lastPingDelta = currentTime - user.lastPing;
user.requesterUserId = user.userId; user.requesterUserId = user.userId;
return loginTimeDelta >= INTERVAL_TIME return userLeaving(user, user.userId, user.connectionId);
&& lastPingDelta >= INTERVAL_TIME
&& userLeaving(user, user.userId, user.connectionId);
}); });
return Logger.info('All inactive user have been removed'); return Logger.info('All inactive user have been removed');
}, INTERVAL_TIME); }, INTERVAL_TIME);