bigbluebutton-Github/bigbluebutton-html5/imports/api/users-settings/server/methods/addUserSettings.js

125 lines
3.5 KiB
JavaScript
Raw Normal View History

import { check } from 'meteor/check';
import addUserSetting from '/imports/api/users-settings/server/modifiers/addUserSetting';
import logger from '/imports/startup/server/logger';
2020-04-29 12:41:16 +08:00
import { extractCredentials } from '/imports/api/common/server/helpers';
const oldParameters = {
2019-11-07 04:53:24 +08:00
askForFeedbackOnLogout: 'bbb_ask_for_feedback_on_logout',
autoJoin: 'bbb_auto_join_audio',
autoShareWebcam: 'bbb_auto_share_webcam',
autoSwapLayout: 'bbb_auto_swap_layout',
clientTitle: 'bbb_client_title',
2019-11-07 04:53:24 +08:00
customStyle: 'bbb_custom_style',
customStyleUrl: 'bbb_custom_style_url',
displayBrandingArea: 'bbb_display_branding_area',
enableScreensharing: 'bbb_enable_screen_sharing',
enableVideo: 'bbb_enable_video',
enableVideoStats: 'bbb_enable_video_stats',
2019-11-07 04:53:24 +08:00
forceListenOnly: 'bbb_force_listen_only',
hidePresentation: 'bbb_hide_presentation',
listenOnlyMode: 'bbb_listen_only_mode',
multiUserPenOnly: 'bbb_multi_user_pen_only',
multiUserTools: 'bbb_multi_user_tools',
2019-11-07 04:53:24 +08:00
outsideToggleRecording: 'bbb_outside_toggle_recording',
outsideToggleSelfVoice: 'bbb_outside_toggle_self_voice',
presenterTools: 'bbb_presenter_tools',
shortcuts: 'bbb_shortcuts',
skipCheck: 'bbb_skip_check_audio',
};
const oldParametersKeys = Object.keys(oldParameters);
const currentParameters = [
2019-07-18 21:22:39 +08:00
// APP
2019-11-07 04:53:24 +08:00
'bbb_ask_for_feedback_on_logout',
'bbb_auto_join_audio',
2019-11-07 04:53:24 +08:00
'bbb_client_title',
'bbb_force_listen_only',
2019-11-07 04:53:24 +08:00
'bbb_listen_only_mode',
'bbb_skip_check_audio',
2019-07-18 21:22:39 +08:00
// BRANDING
'bbb_display_branding_area',
2019-07-18 21:22:39 +08:00
// SHORTCUTS
'bbb_shortcuts',
2019-07-18 21:22:39 +08:00
// KURENTO
2019-11-07 04:53:24 +08:00
'bbb_auto_share_webcam',
2019-11-08 04:55:04 +08:00
'bbb_preferred_camera_profile',
'bbb_enable_screen_sharing',
'bbb_enable_video',
'bbb_enable_video_stats',
'bbb_skip_video_preview',
// PRESENTATION
'bbb_force_restore_presentation_on_new_events',
2019-07-18 21:22:39 +08:00
// WHITEBOARD
'bbb_multi_user_pen_only',
'bbb_presenter_tools',
'bbb_multi_user_tools',
2019-07-18 21:22:39 +08:00
// SKINNING/THEMMING
'bbb_custom_style',
'bbb_custom_style_url',
2019-07-18 21:22:39 +08:00
// LAYOUT
'bbb_auto_swap_layout',
'bbb_hide_presentation',
'bbb_show_participants_on_login',
'bbb_show_public_chat_on_login',
// OUTSIDE COMMANDS
2019-07-18 21:22:39 +08:00
'bbb_outside_toggle_self_voice',
'bbb_outside_toggle_recording',
2019-07-18 21:22:39 +08:00
];
function valueParser(val) {
try {
const parsedValue = JSON.parse(val.toLowerCase());
return parsedValue;
} catch (error) {
logger.error('Parameter value could not ber parsed');
return val;
}
}
2020-04-29 12:41:16 +08:00
export default function addUserSettings(settings) {
2018-09-20 04:32:17 +08:00
check(settings, [Object]);
2020-04-29 12:41:16 +08:00
const { meetingId, requesterUserId: userId } = extractCredentials(this.userId);
let parameters = {};
2018-09-20 04:32:17 +08:00
settings.forEach((el) => {
const settingKey = Object.keys(el).shift();
2019-07-27 01:55:40 +08:00
if (currentParameters.includes(settingKey)) {
if (!Object.keys(parameters).includes(settingKey)) {
parameters = {
[settingKey]: valueParser(el[settingKey]),
...parameters,
};
} else {
parameters[settingKey] = el[settingKey];
2019-07-18 21:22:39 +08:00
}
return;
2018-09-20 04:32:17 +08:00
}
if (oldParametersKeys.includes(settingKey)) {
const matchingNewKey = oldParameters[settingKey];
if (!Object.keys(parameters).includes(matchingNewKey)) {
parameters = {
[matchingNewKey]: valueParser(el[settingKey]),
...parameters,
};
2019-07-18 21:22:39 +08:00
}
return;
2018-09-20 04:32:17 +08:00
}
logger.warn(`Parameter ${settingKey} not handled`);
});
2018-09-18 01:05:39 +08:00
const settingsAdded = [];
Object.entries(parameters).forEach((el) => {
2018-09-18 01:05:39 +08:00
const setting = el[0];
const value = el[1];
settingsAdded.push(addUserSetting(meetingId, userId, setting, value));
});
return settingsAdded;
}