bigbluebutton-Github/bigbluebutton-html5/imports/ui/services/settings/index.js
2019-07-12 21:44:27 +00:00

74 lines
1.9 KiB
JavaScript

import Storage from '/imports/ui/services/storage/session';
import _ from 'lodash';
import { makeCall } from '/imports/ui/services/api';
const SETTINGS = [
'application',
'audio',
'video',
'cc',
'participants',
'dataSaving',
];
class Settings {
constructor(defaultValues = {}) {
SETTINGS.forEach((p) => {
const privateProp = `_${p}`;
this[privateProp] = {
tracker: new Tracker.Dependency(),
value: undefined,
};
Object.defineProperty(this, p, {
get: () => {
this[privateProp].tracker.depend();
return this[privateProp].value;
},
set: (v) => {
this[privateProp].value = v;
this[privateProp].tracker.changed();
},
});
});
// Sets default locale to browser locale
defaultValues.application.locale = navigator.languages ? navigator.languages[0] : false
|| navigator.language
|| defaultValues.application.locale;
this.setDefault(defaultValues);
}
setDefault(defaultValues) {
const savedSettings = {};
SETTINGS.forEach((s) => {
savedSettings[s] = Storage.getItem(`settings_${s}`);
});
Object.keys(defaultValues).forEach((key) => {
this[key] = _.extend(defaultValues[key], savedSettings[key]);
});
this.save();
}
save() {
Object.keys(this).forEach((k) => {
// if (k === '_dataSaving') {
// const { value: { viewParticipantsWebcams } } = this[k];
//
// makeCall('userChangedSettings', 'viewParticipantsWebcams', viewParticipantsWebcams);
// }
// TODO https://github.com/bigbluebutton/bigbluebutton/issue/7774
Storage.setItem(`settings${k}`, this[k].value);
});
}
}
const SettingsSingleton = new Settings(Meteor.settings.public.app.defaultSettings);
export default SettingsSingleton;