bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/closed-captions/service.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

import Captions from '/imports/api/captions';
import Auth from '/imports/ui/services/auth';
2017-04-06 19:46:15 +08:00
import Settings from '/imports/ui/services/settings';
2017-06-03 03:25:02 +08:00
const getCCData = () => {
const meetingID = Auth.meetingID;
2017-04-06 19:46:15 +08:00
const ccSettings = Settings.cc;
2016-12-23 16:26:22 +08:00
2017-06-03 03:25:02 +08:00
const CCEnabled = ccSettings.enabled;
2017-06-03 03:25:02 +08:00
// associative array that keeps locales with arrays of string objects related to those locales
const captions = [];
2017-06-03 03:25:02 +08:00
// list of unique locales in the Captions Collection
if (CCEnabled) {
2017-06-03 03:25:02 +08:00
const locales = _.uniq(Captions.find({}, {
2016-12-23 16:26:22 +08:00
sort: { locale: 1 },
fields: { locale: true },
2017-06-03 03:25:02 +08:00
}).fetch().map(obj => obj.locale), true);
2016-12-23 16:26:22 +08:00
2016-12-24 02:49:17 +08:00
locales.forEach((locale) => {
2017-06-03 03:25:02 +08:00
const captionObjects = Captions.find({
2016-12-23 16:26:22 +08:00
meetingId: meetingID,
2017-06-03 03:25:02 +08:00
locale,
2016-12-23 16:26:22 +08:00
}, {
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];
}
});
}
2017-06-03 03:25:02 +08:00
// 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 {
2016-12-23 16:26:22 +08:00
locale: selectedLocale,
fontFamily: ccFontFamily,
fontSize: ccFontSize,
fontColor: ccFontColor,
backgroundColor: ccBackgroundColor,
2017-06-03 03:25:02 +08:00
captions,
};
};
export default {
getCCData,
};