Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SettingsMenu.js 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. /**
  55. *
  56. */
  57. function initHTML() {
  58. $(`#${sidePanelsContainerId}`)
  59. .append(htmlStr);
  60. // make sure we translate the panel, as adding it can be after i18n
  61. // library had initialized and translated already present html
  62. APP.translation.translateElement($(`#${sidePanelsContainerId}`));
  63. }
  64. /**
  65. * Generate html select options for available languages.
  66. *
  67. * @param {string[]} items available languages
  68. * @param {string} [currentLang] current language
  69. * @returns {string}
  70. */
  71. function generateLanguagesOptions(items, currentLang) {
  72. return items.map(lang => {
  73. const attrs = {
  74. value: lang,
  75. 'data-i18n': `languages:${lang}`
  76. };
  77. if (lang === currentLang) {
  78. attrs.selected = 'selected';
  79. }
  80. const attrsStr = UIUtil.attrsToString(attrs);
  81. return `<option ${attrsStr}></option>`;
  82. }).join('');
  83. }
  84. /**
  85. * Replace html select element to select2 custom dropdown
  86. *
  87. * @param {jQueryElement} $el native select element
  88. * @param {function} onSelectedCb fired if item is selected
  89. */
  90. function initSelect2($el, onSelectedCb) {
  91. $el.auiSelect2({
  92. minimumResultsForSearch: Infinity
  93. });
  94. if (typeof onSelectedCb === 'function') {
  95. $el.change(onSelectedCb);
  96. }
  97. }
  98. export default {
  99. init(emitter) {
  100. initHTML();
  101. // LANGUAGES BOX
  102. if (UIUtil.isSettingEnabled('language')) {
  103. const wrapperId = 'languagesSelectWrapper';
  104. const selectId = 'languagesSelect';
  105. const selectEl = AJS.$(`#${selectId}`);
  106. let selectInput; // eslint-disable-line prefer-const
  107. selectEl.html(generateLanguagesOptions(
  108. LANGUAGES,
  109. APP.translation.getCurrentLanguage()
  110. ));
  111. initSelect2(selectEl, () => {
  112. const val = selectEl.val();
  113. selectInput[0].dataset.i18n = `languages:${val}`;
  114. APP.translation.translateElement(selectInput);
  115. emitter.emit(UIEvents.LANG_CHANGED, val);
  116. });
  117. // find new selectInput element
  118. selectInput = $(`#s2id_${selectId} .select2-chosen`);
  119. // first select fix for languages options
  120. selectInput[0].dataset.i18n
  121. = `languages:${APP.translation.getCurrentLanguage()}`;
  122. // translate selectInput, which is the currently selected language
  123. // otherwise there will be no selected option
  124. APP.translation.translateElement(selectInput);
  125. APP.translation.translateElement(selectEl);
  126. APP.translation.addLanguageChangedListener(
  127. lng => {
  128. selectInput[0].dataset.i18n = `languages:${lng}`;
  129. });
  130. UIUtil.setVisible(wrapperId, true);
  131. }
  132. // DEVICES LIST
  133. if (UIUtil.isSettingEnabled('devices')) {
  134. const wrapperId = 'deviceOptionsWrapper';
  135. $('#deviceSelection').on('click', () =>
  136. APP.store.dispatch(openDeviceSelectionDialog()));
  137. // Only show the subtitle if this isn't the only setting section.
  138. if (interfaceConfig.SETTINGS_SECTIONS.length > 1) {
  139. UIUtil.setVisible('deviceOptionsTitle', true);
  140. }
  141. UIUtil.setVisible(wrapperId, true);
  142. }
  143. // MODERATOR
  144. if (UIUtil.isSettingEnabled('moderator')) {
  145. const wrapperId = 'moderatorOptionsWrapper';
  146. // START MUTED
  147. $('#startMutedOptions').change(() => {
  148. const startAudioMuted = $('#startAudioMuted').is(':checked');
  149. const startVideoMuted = $('#startVideoMuted').is(':checked');
  150. emitter.emit(
  151. UIEvents.START_MUTED_CHANGED,
  152. startAudioMuted,
  153. startVideoMuted
  154. );
  155. });
  156. // FOLLOW ME
  157. const followMeToggle = document.getElementById('followMeCheckBox');
  158. followMeToggle.addEventListener('change', () => {
  159. const isFollowMeEnabled = followMeToggle.checked;
  160. emitter.emit(UIEvents.FOLLOW_ME_ENABLED, isFollowMeEnabled);
  161. });
  162. UIUtil.setVisible(wrapperId, true);
  163. }
  164. },
  165. /**
  166. * If start audio muted/start video muted options should be visible or not.
  167. * @param {boolean} show
  168. */
  169. showStartMutedOptions(show) {
  170. if (show && UIUtil.isSettingEnabled('moderator')) {
  171. // Only show the subtitle if this isn't the only setting section.
  172. if (!$('#moderatorOptionsTitle').is(':visible')
  173. && interfaceConfig.SETTINGS_SECTIONS.length > 1) {
  174. UIUtil.setVisible('moderatorOptionsTitle', true);
  175. }
  176. UIUtil.setVisible('startMutedOptions', true);
  177. } else {
  178. // Only show the subtitle if this isn't the only setting section.
  179. if ($('#moderatorOptionsTitle').is(':visible')) {
  180. UIUtil.setVisible('moderatorOptionsTitle', false);
  181. }
  182. UIUtil.setVisible('startMutedOptions', false);
  183. }
  184. },
  185. updateStartMutedBox(startAudioMuted, startVideoMuted) {
  186. $('#startAudioMuted').attr('checked', startAudioMuted);
  187. $('#startVideoMuted').attr('checked', startVideoMuted);
  188. },
  189. /**
  190. * Shows/hides the follow me options in the settings dialog.
  191. *
  192. * @param {boolean} show {true} to show those options, {false} to hide them
  193. */
  194. showFollowMeOptions(show) {
  195. UIUtil.setVisible(
  196. 'followMeOptions',
  197. show && UIUtil.isSettingEnabled('moderator'));
  198. },
  199. /**
  200. * Check if settings menu is visible or not.
  201. * @returns {boolean}
  202. */
  203. isVisible() {
  204. return UIUtil.isVisible(document.getElementById('settings_container'));
  205. }
  206. };