Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SettingsMenu.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* global APP, $ */
  2. import UIUtil from "../../util/UIUtil";
  3. import UIEvents from "../../../../service/UI/UIEvents";
  4. import languages from "../../../../service/translation/languages";
  5. import Settings from '../../../settings/Settings';
  6. /**
  7. * Generate html select options for available languages.
  8. * @param {string[]} items available languages
  9. * @param {string} [currentLang] current language
  10. * @returns {string}
  11. */
  12. function generateLanguagesOptions(items, currentLang) {
  13. return items.map(function (lang) {
  14. let attrs = {
  15. value: lang,
  16. 'data-i18n': `languages:${lang}`
  17. };
  18. if (lang === currentLang) {
  19. attrs.selected = 'selected';
  20. }
  21. let attrsStr = UIUtil.attrsToString(attrs);
  22. return `<option ${attrsStr}></option>`;
  23. }).join('\n');
  24. }
  25. /**
  26. * Generate html select options for available physical devices.
  27. * @param {{ deviceId, label }[]} items available devices
  28. * @param {string} [selectedId] id of selected device
  29. * @returns {string}
  30. */
  31. function generateDevicesOptions(items, selectedId) {
  32. return items.map(function (item) {
  33. let attrs = {
  34. value: item.deviceId
  35. };
  36. if (item.deviceId === selectedId) {
  37. attrs.selected = 'selected';
  38. }
  39. let attrsStr = UIUtil.attrsToString(attrs);
  40. return `<option ${attrsStr}>${item.label}</option>`;
  41. }).join('\n');
  42. }
  43. export default {
  44. init (emitter) {
  45. // DISPLAY NAME
  46. function updateDisplayName () {
  47. emitter.emit(UIEvents.NICKNAME_CHANGED, $('#setDisplayName').val());
  48. }
  49. $('#setDisplayName')
  50. .val(Settings.getDisplayName())
  51. .keyup(function (event) {
  52. if (event.keyCode === 13) { // enter
  53. updateDisplayName();
  54. }
  55. })
  56. .focusout(updateDisplayName);
  57. // EMAIL
  58. function updateEmail () {
  59. emitter.emit(UIEvents.EMAIL_CHANGED, $('#setEmail').val());
  60. }
  61. $('#setEmail')
  62. .val(Settings.getEmail())
  63. .keyup(function (event) {
  64. if (event.keyCode === 13) { // enter
  65. updateEmail();
  66. }
  67. }).focusout(updateEmail);
  68. // START MUTED
  69. $("#startMutedOptions").change(function () {
  70. let startAudioMuted = $("#startAudioMuted").is(":checked");
  71. let startVideoMuted = $("#startVideoMuted").is(":checked");
  72. emitter.emit(
  73. UIEvents.START_MUTED_CHANGED,
  74. startAudioMuted,
  75. startVideoMuted
  76. );
  77. });
  78. // LANGUAGES BOX
  79. let languagesBox = $("#languages_selectbox");
  80. languagesBox.html(generateLanguagesOptions(
  81. languages.getLanguages(),
  82. APP.translation.getCurrentLanguage()
  83. ));
  84. APP.translation.translateElement(languagesBox);
  85. languagesBox.change(function () {
  86. emitter.emit(UIEvents.LANG_CHANGED, languagesBox.val());
  87. });
  88. // DEVICES LIST
  89. this.changeDevicesList([]);
  90. $('#selectCamera').change(function () {
  91. let cameraDeviceId = $(this).val();
  92. if (cameraDeviceId !== Settings.getCameraDeviceId()) {
  93. emitter.emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
  94. }
  95. });
  96. $('#selectMic').change(function () {
  97. let micDeviceId = $(this).val();
  98. if (micDeviceId !== Settings.getMicDeviceId()) {
  99. emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
  100. }
  101. });
  102. },
  103. /**
  104. * If start audio muted/start video muted options should be visible or not.
  105. * @param {boolean} show
  106. */
  107. showStartMutedOptions (show) {
  108. if (show) {
  109. $("#startMutedOptions").css("display", "block");
  110. } else {
  111. $("#startMutedOptions").css("display", "none");
  112. }
  113. },
  114. updateStartMutedBox (startAudioMuted, startVideoMuted) {
  115. $("#startAudioMuted").attr("checked", startAudioMuted);
  116. $("#startVideoMuted").attr("checked", startVideoMuted);
  117. },
  118. /**
  119. * Check if settings menu is visible or not.
  120. * @returns {boolean}
  121. */
  122. isVisible () {
  123. return $('#settingsmenu').is(':visible');
  124. },
  125. /**
  126. * Change user display name in the settings menu.
  127. * @param {string} newDisplayName
  128. */
  129. changeDisplayName (newDisplayName) {
  130. $('#setDisplayName').val(newDisplayName);
  131. },
  132. /**
  133. * Change user avatar in the settings menu.
  134. * @param {string} avatarUrl url of the new avatar
  135. */
  136. changeAvatar (avatarUrl) {
  137. $('#avatar').attr('src', avatarUrl);
  138. },
  139. /**
  140. * Change available cameras/microphones or hide selects completely if
  141. * no devices available.
  142. * @param {{ deviceId, label, kind }[]} devices list of available devices
  143. */
  144. changeDevicesList (devices) {
  145. if (!devices.length) {
  146. $('#devicesOptions').hide();
  147. return;
  148. }
  149. let audio = devices.filter(device => device.kind === 'audioinput');
  150. let video = devices.filter(device => device.kind === 'videoinput');
  151. $('#selectCamera').html(
  152. generateDevicesOptions(video, Settings.getCameraDeviceId())
  153. );
  154. $('#selectMic').html(
  155. generateDevicesOptions(audio, Settings.getMicDeviceId())
  156. );
  157. $('#devicesOptions').show();
  158. }
  159. };