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';
|
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
export default async 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 {
|
2023-04-01 04:40:41 +08:00
|
|
|
const numberAffected = await Users.updateAsync(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
|
|
|
}
|