bigbluebutton-Github/bigbluebutton-html5/imports/api/breakouts/server/handlers/breakoutJoinURL.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Breakouts from '/imports/api/breakouts';
2023-03-02 00:38:40 +08:00
export default async function handleBreakoutJoinURL({ body }) {
2016-11-14 19:57:10 +08:00
const {
redirectToHtml5JoinURL,
userId,
breakoutId,
} = body;
2016-11-14 19:57:10 +08:00
check(redirectToHtml5JoinURL, String);
2016-11-15 00:12:54 +08:00
2016-11-14 19:57:10 +08:00
const selector = {
breakoutId,
2016-11-14 19:57:10 +08:00
};
const modifier = {
$set: {
[`url_${userId}`]: {
2021-09-30 01:52:30 +08:00
redirectToHtml5JoinURL,
insertedTime: new Date().getTime(),
},
2018-06-07 05:24:09 +08:00
},
};
try {
2021-09-07 02:54:12 +08:00
const ATTEMPT_EVERY_MS = 1000;
2016-11-29 03:48:02 +08:00
2021-09-07 02:54:12 +08:00
let numberAffected = 0;
const updateBreakout = async () => {
numberAffected = await Breakouts.updateAsync(selector, modifier);
};
2021-09-07 02:54:12 +08:00
2023-03-02 00:38:40 +08:00
await new Promise((resolve) => {
const updateBreakoutInterval = setInterval(async () => {
await updateBreakout();
2021-09-07 02:54:12 +08:00
if (numberAffected) {
resolve(clearInterval(updateBreakoutInterval));
}
}, ATTEMPT_EVERY_MS);
});
2023-03-02 00:38:40 +08:00
Logger.info(`Upserted breakout id=${breakoutId}`);
} catch (err) {
Logger.error(`Adding breakout to collection: ${err}`);
}
2016-11-14 19:57:10 +08:00
}