2017-02-16 02:49:40 +08:00
|
|
|
import Storage from '/imports/ui/services/storage/session';
|
2017-02-25 04:19:53 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-02-22 04:29:36 +08:00
|
|
|
import Captions from '/imports/api/captions';
|
2017-02-25 04:19:53 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2017-03-17 00:52:43 +08:00
|
|
|
import _ from 'lodash';
|
2017-02-16 02:49:40 +08:00
|
|
|
|
2017-02-25 04:19:53 +08:00
|
|
|
const updateSettings = (obj) => {
|
|
|
|
Object.keys(obj).forEach(k => Storage.setItem(`settings_${k}`, obj[k]));
|
2017-02-16 02:49:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const getSettingsFor = (key) => {
|
|
|
|
const setting = Storage.getItem(`settings_${key}`);
|
|
|
|
|
|
|
|
return setting;
|
|
|
|
};
|
|
|
|
|
2017-02-22 04:29:36 +08:00
|
|
|
const getClosedCaptionLocales = () => {
|
|
|
|
//list of unique locales in the Captions Collection
|
|
|
|
const locales = _.uniq(Captions.find({}, {
|
|
|
|
sort: { locale: 1 },
|
|
|
|
fields: { locale: true },
|
|
|
|
}).fetch().map(function (obj) {
|
|
|
|
return obj.locale;
|
|
|
|
}), true);
|
|
|
|
|
|
|
|
return locales;
|
|
|
|
};
|
|
|
|
|
2017-02-25 04:19:53 +08:00
|
|
|
const getUserRoles = () => {
|
|
|
|
const user = Users.findOne({
|
|
|
|
userId: Auth.userID,
|
|
|
|
}).user;
|
|
|
|
|
|
|
|
return user.role;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setDefaultSettings = () => {
|
|
|
|
const defaultSettings = {
|
|
|
|
application: {
|
|
|
|
chatAudioNotifications: false,
|
|
|
|
chatPushNotifications: false,
|
2017-03-16 21:10:39 +08:00
|
|
|
fontSize: '16px',
|
2017-02-25 04:19:53 +08:00
|
|
|
},
|
|
|
|
audio: {
|
|
|
|
inputDeviceId: undefined,
|
|
|
|
outputDeviceId: undefined,
|
|
|
|
},
|
|
|
|
video: {
|
|
|
|
viewParticipantsWebcams: true,
|
|
|
|
},
|
|
|
|
cc: {
|
|
|
|
backgroundColor: '#FFFFFF',
|
|
|
|
fontColor: '#000000',
|
|
|
|
closedCaptions: false,
|
|
|
|
fontFamily: 'Calibri',
|
|
|
|
fontSize: -1,
|
2017-03-13 19:48:00 +08:00
|
|
|
locale: undefined,
|
2017-02-25 04:19:53 +08:00
|
|
|
takeOwnership: false,
|
|
|
|
},
|
|
|
|
participants: {
|
|
|
|
muteAll: false,
|
|
|
|
lockAll: false,
|
|
|
|
lockAll: false,
|
|
|
|
microphone: false,
|
|
|
|
publicChat: false,
|
|
|
|
privateChat: false,
|
|
|
|
layout: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const savedSettings = {
|
|
|
|
application: getSettingsFor('application'),
|
|
|
|
audio: getSettingsFor('audio'),
|
|
|
|
video: getSettingsFor('video'),
|
2017-03-09 22:34:33 +08:00
|
|
|
cc: getSettingsFor('cc'),
|
|
|
|
participants: getSettingsFor('participants'),
|
2017-02-25 04:19:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
let settings = {};
|
|
|
|
|
|
|
|
Object.keys(defaultSettings).forEach(key => {
|
|
|
|
settings[key] = _.extend(defaultSettings[key], savedSettings[key]);
|
|
|
|
});
|
|
|
|
|
|
|
|
updateSettings(settings);
|
|
|
|
};
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
export {
|
|
|
|
updateSettings,
|
|
|
|
getSettingsFor,
|
2017-02-22 04:29:36 +08:00
|
|
|
getClosedCaptionLocales,
|
2017-02-25 04:19:53 +08:00
|
|
|
getUserRoles,
|
|
|
|
setDefaultSettings,
|
2017-02-16 02:49:40 +08:00
|
|
|
};
|