You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SettingsMenu.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* global $, APP, AJS, interfaceConfig */
  2. import { LANGUAGES } from "../../../../react/features/base/i18n";
  3. import { openDeviceSelectionDialog }
  4. from '../../../../react/features/device-selection';
  5. import UIUtil from "../../util/UIUtil";
  6. import UIEvents from "../../../../service/UI/UIEvents";
  7. const sidePanelsContainerId = 'sideToolbarContainer';
  8. const deviceSelectionButtonClasses
  9. = 'button-control button-control_primary button-control_full-width';
  10. const htmlStr = `
  11. <div id="settings_container" class="sideToolbarContainer__inner">
  12. <div class="title" data-i18n="settings.title"></div>
  13. <form class="aui">
  14. <div id="languagesSelectWrapper"
  15. class="sideToolbarBlock first hide">
  16. <select id="languagesSelect"></select>
  17. </div>
  18. <div id="deviceOptionsWrapper" class="hide">
  19. <div id="deviceOptionsTitle" class="subTitle hide"
  20. data-i18n="settings.audioVideo"></div>
  21. <div class="sideToolbarBlock first">
  22. <button
  23. class="${deviceSelectionButtonClasses}"
  24. data-i18n="deviceSelection.deviceSettings"
  25. id="deviceSelection"
  26. type="button"></button>
  27. </div>
  28. </div>
  29. <div id="moderatorOptionsWrapper" class="hide">
  30. <div id="moderatorOptionsTitle" class="subTitle hide"
  31. data-i18n="settings.moderator"></div>
  32. <div id="startMutedOptions" class="hide">
  33. <div class="sideToolbarBlock first">
  34. <input type="checkbox" id="startAudioMuted">
  35. <label class="startMutedLabel" for="startAudioMuted"
  36. data-i18n="settings.startAudioMuted"></label>
  37. </div>
  38. <div class="sideToolbarBlock">
  39. <input type="checkbox" id="startVideoMuted">
  40. <label class="startMutedLabel" for="startVideoMuted"
  41. data-i18n="settings.startVideoMuted"></label>
  42. </div>
  43. </div>
  44. <div id="followMeOptions" class="hide">
  45. <div class="sideToolbarBlock">
  46. <input type="checkbox" id="followMeCheckBox">
  47. <label class="followMeLabel" for="followMeCheckBox"
  48. data-i18n="settings.followMe"></label>
  49. </div>
  50. </div>
  51. </div>
  52. </form>
  53. </div>`;
  54. function initHTML() {
  55. $(`#${sidePanelsContainerId}`)
  56. .append(htmlStr);
  57. // make sure we translate the panel, as adding it can be after i18n
  58. // library had initialized and translated already present html
  59. APP.translation.translateElement($(`#${sidePanelsContainerId}`));
  60. }
  61. /**
  62. * Generate html select options for available languages.
  63. *
  64. * @param {string[]} items available languages
  65. * @param {string} [currentLang] current language
  66. * @returns {string}
  67. */
  68. function generateLanguagesOptions(items, currentLang) {
  69. return items.map(function (lang) {
  70. let attrs = {
  71. value: lang,
  72. 'data-i18n': `languages:${lang}`
  73. };
  74. if (lang === currentLang) {
  75. attrs.selected = 'selected';
  76. }
  77. let attrsStr = UIUtil.attrsToString(attrs);
  78. return `<option ${attrsStr}></option>`;
  79. }).join('');
  80. }
  81. /**
  82. * Replace html select element to select2 custom dropdown
  83. *
  84. * @param {jQueryElement} $el native select element
  85. * @param {function} onSelectedCb fired if item is selected
  86. */
  87. function initSelect2($el, onSelectedCb) {
  88. $el.auiSelect2({
  89. minimumResultsForSearch: Infinity
  90. });
  91. if (typeof onSelectedCb === 'function') {
  92. $el.change(onSelectedCb);
  93. }
  94. }
  95. export default {
  96. init (emitter) {
  97. initHTML();
  98. //LANGUAGES BOX
  99. if (UIUtil.isSettingEnabled('language')) {
  100. const wrapperId = 'languagesSelectWrapper';
  101. const selectId = 'languagesSelect';
  102. const selectEl = AJS.$(`#${selectId}`);
  103. let selectInput;
  104. selectEl.html(generateLanguagesOptions(
  105. LANGUAGES,
  106. APP.translation.getCurrentLanguage()
  107. ));
  108. initSelect2(selectEl, () => {
  109. const val = selectEl.val();
  110. selectInput[0].dataset.i18n = `languages:${val}`;
  111. APP.translation.translateElement(selectInput);
  112. emitter.emit(UIEvents.LANG_CHANGED, val);
  113. });
  114. //find new selectInput element
  115. selectInput = $(`#s2id_${selectId} .select2-chosen`);
  116. //first select fix for languages options
  117. selectInput[0].dataset.i18n =
  118. `languages:${APP.translation.getCurrentLanguage()}`;
  119. // translate selectInput, which is the currently selected language
  120. // otherwise there will be no selected option
  121. APP.translation.translateElement(selectInput);
  122. APP.translation.translateElement(selectEl);
  123. APP.translation.addLanguageChangedListener(
  124. lng => selectInput[0].dataset.i18n = `languages:${lng}`);
  125. UIUtil.setVisible(wrapperId, true);
  126. }
  127. // DEVICES LIST
  128. if (UIUtil.isSettingEnabled('devices')) {
  129. const wrapperId = 'deviceOptionsWrapper';
  130. $('#deviceSelection').on('click', () =>
  131. APP.store.dispatch(openDeviceSelectionDialog()));
  132. // Only show the subtitle if this isn't the only setting section.
  133. if (interfaceConfig.SETTINGS_SECTIONS.length > 1)
  134. UIUtil.setVisible("deviceOptionsTitle", true);
  135. UIUtil.setVisible(wrapperId, true);
  136. }
  137. // MODERATOR
  138. if (UIUtil.isSettingEnabled('moderator')) {
  139. const wrapperId = 'moderatorOptionsWrapper';
  140. // START MUTED
  141. $("#startMutedOptions").change(function () {
  142. let startAudioMuted = $("#startAudioMuted").is(":checked");
  143. let startVideoMuted = $("#startVideoMuted").is(":checked");
  144. emitter.emit(
  145. UIEvents.START_MUTED_CHANGED,
  146. startAudioMuted,
  147. startVideoMuted
  148. );
  149. });
  150. // FOLLOW ME
  151. const followMeToggle = document.getElementById('followMeCheckBox');
  152. followMeToggle.addEventListener('change', () => {
  153. const isFollowMeEnabled = followMeToggle.checked;
  154. emitter.emit(UIEvents.FOLLOW_ME_ENABLED, isFollowMeEnabled);
  155. });
  156. UIUtil.setVisible(wrapperId, true);
  157. }
  158. },
  159. /**
  160. * If start audio muted/start video muted options should be visible or not.
  161. * @param {boolean} show
  162. */
  163. showStartMutedOptions (show) {
  164. if (show && UIUtil.isSettingEnabled('moderator')) {
  165. // Only show the subtitle if this isn't the only setting section.
  166. if (!$("#moderatorOptionsTitle").is(":visible")
  167. && interfaceConfig.SETTINGS_SECTIONS.length > 1)
  168. UIUtil.setVisible("moderatorOptionsTitle", true);
  169. UIUtil.setVisible("startMutedOptions", true);
  170. } else {
  171. // Only show the subtitle if this isn't the only setting section.
  172. if ($("#moderatorOptionsTitle").is(":visible"))
  173. UIUtil.setVisible("moderatorOptionsTitle", false);
  174. UIUtil.setVisible("startMutedOptions", false);
  175. }
  176. },
  177. updateStartMutedBox (startAudioMuted, startVideoMuted) {
  178. $("#startAudioMuted").attr("checked", startAudioMuted);
  179. $("#startVideoMuted").attr("checked", startVideoMuted);
  180. },
  181. /**
  182. * Shows/hides the follow me options in the settings dialog.
  183. *
  184. * @param {boolean} show {true} to show those options, {false} to hide them
  185. */
  186. showFollowMeOptions (show) {
  187. UIUtil.setVisible(
  188. "followMeOptions",
  189. show && UIUtil.isSettingEnabled('moderator'));
  190. },
  191. /**
  192. * Check if settings menu is visible or not.
  193. * @returns {boolean}
  194. */
  195. isVisible () {
  196. return UIUtil.isVisible(document.getElementById("settings_container"));
  197. }
  198. };