2018-02-20 22:21:51 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
|
2018-04-03 01:08:25 +08:00
|
|
|
export default function setConnectionIdAndAuthToken(meetingId, userId, connectionId, authToken) {
|
2018-02-20 22:21:51 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
2018-03-29 20:10:30 +08:00
|
|
|
check(authToken, String);
|
2018-02-20 22:21:51 +08:00
|
|
|
check(connectionId, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
connectionId,
|
2018-03-29 20:10:30 +08:00
|
|
|
authToken,
|
2018-02-20 22:21:51 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
Logger.error(`Updating connectionId user=${userId}: ${err}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numChanged) {
|
2018-04-03 01:08:25 +08:00
|
|
|
Logger.info(`Updated connectionId and authToken user=${userId} connectionId=${connectionId} meeting=${meetingId} authToken=${authToken}`);
|
2018-02-20 22:21:51 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Users.update(selector, modifier, cb);
|
|
|
|
}
|