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
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
|
|
|
const numberAffected = Users.update(selector, modifier);
|
2018-02-20 22:21:51 +08:00
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
if (numberAffected) {
|
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
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Updating connectionId user=${userId}: ${err}`);
|
|
|
|
}
|
2018-02-20 22:21:51 +08:00
|
|
|
}
|