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 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* global APP, $, JitsiMeetJS */
  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. *
  9. * @param {string[]} items available languages
  10. * @param {string} [currentLang] current language
  11. * @returns {string}
  12. */
  13. function generateLanguagesOptions(items, currentLang) {
  14. return items.map(function (lang) {
  15. let attrs = {
  16. value: lang,
  17. 'data-i18n': `languages:${lang}`
  18. };
  19. if (lang === currentLang) {
  20. attrs.selected = 'selected';
  21. }
  22. let attrsStr = UIUtil.attrsToString(attrs);
  23. return `<option ${attrsStr}></option>`;
  24. }).join('\n');
  25. }
  26. /**
  27. * Generate html select options for available physical devices.
  28. *
  29. * @param {{ deviceId, label }[]} items available devices
  30. * @param {string} [selectedId] id of selected device
  31. * @param {boolean} permissionGranted if permission to use selected device type
  32. * is granted
  33. * @returns {string}
  34. */
  35. function generateDevicesOptions(items, selectedId, permissionGranted) {
  36. if (!permissionGranted && items.length) {
  37. return '<option data-i18n="settings.noPermission"></option>';
  38. }
  39. var options = items.map(function (item) {
  40. let attrs = {
  41. value: item.deviceId
  42. };
  43. if (item.deviceId === selectedId) {
  44. attrs.selected = 'selected';
  45. }
  46. let attrsStr = UIUtil.attrsToString(attrs);
  47. return `<option ${attrsStr}>${item.label}</option>`;
  48. });
  49. if (!items.length) {
  50. options.unshift('<option data-i18n="settings.noDevice"></option>');
  51. }
  52. return options.join('');
  53. }
  54. export default {
  55. init (emitter) {
  56. if (UIUtil.isSettingEnabled('devices')) {
  57. // DEVICES LIST
  58. JitsiMeetJS.mediaDevices.isDeviceListAvailable()
  59. .then((isDeviceListAvailable) => {
  60. if (isDeviceListAvailable &&
  61. JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
  62. this._initializeDeviceSelectionSettings(emitter);
  63. }
  64. });
  65. UIUtil.showElement("deviceOptionsTitle");
  66. UIUtil.showElement("devicesOptions");
  67. }
  68. if (UIUtil.isSettingEnabled('language')) {
  69. //LANGUAGES BOX
  70. let languagesBox = $("#languages_selectbox");
  71. languagesBox.html(generateLanguagesOptions(
  72. languages.getLanguages(),
  73. APP.translation.getCurrentLanguage()
  74. ));
  75. APP.translation.translateElement(languagesBox);
  76. languagesBox.change(function () {
  77. emitter.emit(UIEvents.LANG_CHANGED, languagesBox.val());
  78. });
  79. UIUtil.showElement("languages_selectbox");
  80. }
  81. if (UIUtil.isSettingEnabled('moderator')) {
  82. // START MUTED
  83. $("#startMutedOptions").change(function () {
  84. let startAudioMuted = $("#startAudioMuted").is(":checked");
  85. let startVideoMuted = $("#startVideoMuted").is(":checked");
  86. emitter.emit(
  87. UIEvents.START_MUTED_CHANGED,
  88. startAudioMuted,
  89. startVideoMuted
  90. );
  91. });
  92. // FOLLOW ME
  93. $("#followMeOptions").change(function () {
  94. let isFollowMeEnabled = $("#followMeCheckBox").is(":checked");
  95. emitter.emit(
  96. UIEvents.FOLLOW_ME_ENABLED,
  97. isFollowMeEnabled
  98. );
  99. });
  100. }
  101. },
  102. _initializeDeviceSelectionSettings(emitter) {
  103. this.changeDevicesList([]);
  104. $('#selectCamera').change(function () {
  105. let cameraDeviceId = $(this).val();
  106. if (cameraDeviceId !== Settings.getCameraDeviceId()) {
  107. emitter.emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
  108. }
  109. });
  110. $('#selectMic').change(function () {
  111. let micDeviceId = $(this).val();
  112. if (micDeviceId !== Settings.getMicDeviceId()) {
  113. emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
  114. }
  115. });
  116. $('#selectAudioOutput').change(function () {
  117. let audioOutputDeviceId = $(this).val();
  118. if (audioOutputDeviceId !== Settings.getAudioOutputDeviceId()) {
  119. emitter.emit(
  120. UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED, audioOutputDeviceId);
  121. }
  122. });
  123. },
  124. /**
  125. * If start audio muted/start video muted options should be visible or not.
  126. * @param {boolean} show
  127. */
  128. showStartMutedOptions (show) {
  129. if (show && UIUtil.isSettingEnabled('moderator')) {
  130. // Only show the subtitle if this isn't the only setting section.
  131. if (!$("#moderatorOptionsTitle").is(":visible"))
  132. UIUtil.showElement("moderatorOptionsTitle");
  133. UIUtil.showElement("startMutedOptions");
  134. } else {
  135. // Only show the subtitle if this isn't the only setting section.
  136. if ($("#moderatorOptionsTitle").is(":visible"))
  137. UIUtil.hideElement("moderatorOptionsTitle");
  138. UIUtil.hideElement("startMutedOptions");
  139. }
  140. },
  141. updateStartMutedBox (startAudioMuted, startVideoMuted) {
  142. $("#startAudioMuted").attr("checked", startAudioMuted);
  143. $("#startVideoMuted").attr("checked", startVideoMuted);
  144. },
  145. /**
  146. * Shows/hides the follow me options in the settings dialog.
  147. *
  148. * @param {boolean} show {true} to show those options, {false} to hide them
  149. */
  150. showFollowMeOptions (show) {
  151. if (show && UIUtil.isSettingEnabled('moderator')) {
  152. UIUtil.showElement("followMeOptions");
  153. } else {
  154. UIUtil.hideElement("followMeOptions");
  155. }
  156. },
  157. /**
  158. * Check if settings menu is visible or not.
  159. * @returns {boolean}
  160. */
  161. isVisible () {
  162. return UIUtil.isVisible(document.getElementById("settings_container"));
  163. },
  164. /**
  165. * Sets microphone's <select> element to select microphone ID from settings.
  166. */
  167. setSelectedMicFromSettings () {
  168. $('#selectMic').val(Settings.getMicDeviceId());
  169. },
  170. /**
  171. * Sets camera's <select> element to select camera ID from settings.
  172. */
  173. setSelectedCameraFromSettings () {
  174. $('#selectCamera').val(Settings.getCameraDeviceId());
  175. },
  176. /**
  177. * Sets audio outputs's <select> element to select audio output ID from
  178. * settings.
  179. */
  180. setSelectedAudioOutputFromSettings () {
  181. $('#selectAudioOutput').val(Settings.getAudioOutputDeviceId());
  182. },
  183. /**
  184. * Change available cameras/microphones or hide selects completely if
  185. * no devices available.
  186. * @param {{ deviceId, label, kind }[]} devices list of available devices
  187. */
  188. changeDevicesList (devices) {
  189. let $selectCamera= $('#selectCamera'),
  190. $selectMic = $('#selectMic'),
  191. $selectAudioOutput = $('#selectAudioOutput'),
  192. $selectAudioOutputParent = $selectAudioOutput.parent();
  193. let audio = devices.filter(device => device.kind === 'audioinput'),
  194. video = devices.filter(device => device.kind === 'videoinput'),
  195. audioOutput = devices
  196. .filter(device => device.kind === 'audiooutput'),
  197. selectedAudioDevice = audio.find(
  198. d => d.deviceId === Settings.getMicDeviceId()) || audio[0],
  199. selectedVideoDevice = video.find(
  200. d => d.deviceId === Settings.getCameraDeviceId()) || video[0],
  201. selectedAudioOutputDevice = audioOutput.find(
  202. d => d.deviceId === Settings.getAudioOutputDeviceId()),
  203. videoPermissionGranted =
  204. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('video'),
  205. audioPermissionGranted =
  206. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('audio');
  207. $selectCamera
  208. .html(generateDevicesOptions(
  209. video,
  210. selectedVideoDevice ? selectedVideoDevice.deviceId : '',
  211. videoPermissionGranted))
  212. .prop('disabled', !video.length || !videoPermissionGranted);
  213. $selectMic
  214. .html(generateDevicesOptions(
  215. audio,
  216. selectedAudioDevice ? selectedAudioDevice.deviceId : '',
  217. audioPermissionGranted))
  218. .prop('disabled', !audio.length || !audioPermissionGranted);
  219. if (JitsiMeetJS.mediaDevices.isDeviceChangeAvailable('output')) {
  220. $selectAudioOutput
  221. .html(generateDevicesOptions(
  222. audioOutput,
  223. selectedAudioOutputDevice
  224. ? selectedAudioOutputDevice.deviceId
  225. : 'default',
  226. videoPermissionGranted || audioPermissionGranted))
  227. .prop('disabled', !audioOutput.length ||
  228. (!videoPermissionGranted && !audioPermissionGranted));
  229. $selectAudioOutputParent.show();
  230. } else {
  231. $selectAudioOutputParent.hide();
  232. }
  233. $('#devicesOptions').show();
  234. APP.translation.translateElement($('#settings_container option'));
  235. }
  236. };