bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/closed-captions/service.js
Oleksandr Zhurbenko 251bd22738 PR review fixes
2017-09-06 12:36:52 -07:00

67 lines
1.9 KiB
JavaScript

import Captions from '/imports/api/2.0/captions';
import Auth from '/imports/ui/services/auth';
import Settings from '/imports/ui/services/settings';
const getCCData = () => {
const meetingID = Auth.meetingID;
const ccSettings = Settings.cc;
const CCEnabled = ccSettings.enabled;
// associative array that keeps locales with arrays of string objects related to those locales
const captions = [];
// list of unique locales in the Captions Collection
if (CCEnabled) {
const locales = _.uniq(Captions.find({}, {
sort: { locale: 1 },
fields: { locale: true },
}).fetch().map(obj => obj.locale), true);
locales.forEach((locale) => {
const captionObjects = Captions.find({
meetingId: meetingID,
locale,
}, {
sort: {
locale: 1,
'captionHistory.index': 1,
},
}).fetch();
let current = captionObjects[0];
captions[current.locale] = {
ownerId: current.captionHistory.ownerId ? current.captionHistory.ownerId : null,
captions: [],
};
while (current != null) {
captions[current.locale].captions.push({
captions: current.captionHistory.captions,
index: current.captionHistory.index,
});
current = captionObjects[current.captionHistory.next];
}
});
}
// fetching settings for the captions
const selectedLocale = ccSettings.locale;
const ccFontFamily = ccSettings.fontFamily ? ccSettings.fontFamily : 'Arial';
const ccFontSize = ccSettings.fontSize ? ccSettings.fontSize : 18;
const ccBackgroundColor = ccSettings.backgroundColor ? ccSettings.backgroundColor : '#f3f6f9';
const ccFontColor = ccSettings.fontColor ? ccSettings.fontColor : '#000000';
return {
locale: selectedLocale,
fontFamily: ccFontFamily,
fontSize: ccFontSize,
fontColor: ccFontColor,
backgroundColor: ccBackgroundColor,
captions,
};
};
export default {
getCCData,
};