2017-06-19 21:13:35 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-06-19 21:13:35 +08:00
|
|
|
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(status, String);
|
|
|
|
|
|
|
|
if (!VALID_CONNECTION_STATUS.includes(status)) {
|
|
|
|
throw new Meteor.Error('invalid-connection-status',
|
|
|
|
`Invalid connection status, received ${status} expecting ${VALID_CONNECTION_STATUS.join()}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
2017-07-26 22:09:07 +08:00
|
|
|
connectionStatus: status,
|
2017-06-19 21:13:35 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
2017-10-06 20:50:01 +08:00
|
|
|
Logger.error(`Updating connection status user=${userId}: ${err}`);
|
|
|
|
return;
|
2017-06-19 21:13:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (numChanged) {
|
2017-10-06 20:50:01 +08:00
|
|
|
Logger.info(`Updated connection status user=${userId} status=${
|
2017-06-19 21:13:35 +08:00
|
|
|
status} meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Users.update(selector, modifier, cb);
|
|
|
|
}
|