bigbluebutton-Github/bigbluebutton-html5/imports/api/captions/server/helpers.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

import { Meteor } from 'meteor/meteor';
import { hashFNV32a } from '/imports/api/common/server/helpers';
import { check } from 'meteor/check';
const CAPTIONS_CONFIG = Meteor.settings.public.captions;
2019-05-23 22:51:01 +08:00
const BASENAME = Meteor.settings.public.app.basename;
const APP = Meteor.settings.private.app;
const LOCALES_URL = `http://${APP.host}:${APP.port}${BASENAME}${APP.localesUrl}`;
const CAPTIONS = '_captions_';
const TOKEN = '$';
// Captions padId should look like: {padId}_captions_{locale}
const generatePadId = (meetingId, locale) => {
const padId = `${hashFNV32a(meetingId, true)}${CAPTIONS}${locale}`;
return padId;
};
2019-05-29 22:31:27 +08:00
const isCaptionsPad = (padId) => {
const splitPadId = padId.split(CAPTIONS);
2019-05-29 22:31:27 +08:00
return splitPadId.length === 2;
2019-05-23 22:51:01 +08:00
};
2019-05-29 22:31:27 +08:00
const getDataFromChangeset = (changeset) => {
const splitChangeset = changeset.split(TOKEN);
if (splitChangeset.length > 1) {
splitChangeset.shift();
return splitChangeset.join(TOKEN);
}
2019-05-29 22:31:27 +08:00
return '';
2019-05-23 22:51:01 +08:00
};
2019-05-29 22:31:27 +08:00
const isEnabled = () => CAPTIONS_CONFIG.enabled;
const getLocalesURL = () => LOCALES_URL;
const processForCaptionsPadOnly = fn => (message, ...args) => {
const { body } = message;
const { pad } = body;
const { id } = pad;
check(id, String);
if (isCaptionsPad(id)) return fn(message, ...args);
return () => {};
};
export {
generatePadId,
processForCaptionsPadOnly,
isEnabled,
getLocalesURL,
getDataFromChangeset,
};