2021-10-16 03:07:13 +08:00
|
|
|
import axios from 'axios';
|
2019-05-17 04:11:10 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2021-10-16 03:07:13 +08:00
|
|
|
import createCaptions from '/imports/api/captions/server/modifiers/createCaptions';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2019-05-17 04:11:10 +08:00
|
|
|
|
|
|
|
const CAPTIONS_CONFIG = Meteor.settings.public.captions;
|
2019-05-23 22:51:01 +08:00
|
|
|
const BASENAME = Meteor.settings.public.app.basename;
|
2021-10-16 03:07:13 +08:00
|
|
|
const HOST = Meteor.settings.private.app.host;
|
|
|
|
const LOCALES = Meteor.settings.private.app.localesUrl;
|
|
|
|
const LOCALES_URL = `http://${HOST}:${process.env.PORT}${BASENAME}${LOCALES}`;
|
|
|
|
|
|
|
|
const init = (meetingId) => {
|
|
|
|
axios({
|
|
|
|
method: 'get',
|
|
|
|
url: LOCALES_URL,
|
|
|
|
responseType: 'json',
|
2023-03-09 22:05:50 +08:00
|
|
|
}).then(async (response) => {
|
2021-10-16 03:07:13 +08:00
|
|
|
const { status } = response;
|
|
|
|
if (status !== 200) return;
|
|
|
|
|
|
|
|
const locales = response.data;
|
2023-03-09 22:05:50 +08:00
|
|
|
await Promise.all(locales.map(async (locale) => {
|
|
|
|
const caption = await createCaptions(meetingId, locale.locale, locale.name);
|
|
|
|
return caption;
|
|
|
|
}));
|
2021-10-16 03:07:13 +08:00
|
|
|
}).catch((error) => Logger.error(`Could not create captions for ${meetingId}: ${error}`));
|
2019-05-23 22:51:01 +08:00
|
|
|
};
|
2019-05-17 04:11:10 +08:00
|
|
|
|
2021-10-16 03:07:13 +08:00
|
|
|
const initCaptions = (meetingId) => {
|
|
|
|
if (CAPTIONS_CONFIG.enabled) init(meetingId);
|
2019-05-17 04:11:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export {
|
2021-10-16 03:07:13 +08:00
|
|
|
initCaptions,
|
2019-05-17 04:11:10 +08:00
|
|
|
};
|