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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* global APP, $, JitsiMeetJS, interfaceConfig, AJS */
  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('');
  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. function initSelect2($el, onSelectedCb) {
  55. $el.auiSelect2({
  56. minimumResultsForSearch: Infinity,
  57. dropdownCssClass: 'dropdown-dark',
  58. containerCssClass: 'input-container-dark',
  59. });
  60. if (typeof onSelectedCb === 'function'){
  61. $el.change(onSelectedCb);
  62. }
  63. }
  64. export default {
  65. init (emitter) {
  66. //LANGUAGES BOX
  67. if (UIUtil.isSettingEnabled('language')) {
  68. const wrapperId = 'languagesSelectWrapper';
  69. const selectId = 'languagesSelect';
  70. const selectEl = AJS.$(`#${selectId}`);
  71. let selectInput;
  72. selectEl.html(generateLanguagesOptions(
  73. languages.getLanguages(),
  74. APP.translation.getCurrentLanguage()
  75. ));
  76. initSelect2(selectEl, () => {
  77. const val = selectEl.val();
  78. selectInput[0].dataset.i18n = `languages:${val}`;
  79. APP.translation.translateElement(selectInput);
  80. emitter.emit(UIEvents.LANG_CHANGED, val);
  81. });
  82. //find new selectInput element
  83. selectInput = $(`#s2id_${selectId} .select2-chosen`);
  84. //first select fix for languages options
  85. selectInput[0].dataset.i18n =
  86. `languages:${APP.translation.getCurrentLanguage()}`;
  87. APP.translation.translateElement(selectEl);
  88. UIUtil.showElement(wrapperId);
  89. }
  90. // DEVICES LIST
  91. if (UIUtil.isSettingEnabled('devices')) {
  92. const wrapperId = 'deviceOptionsWrapper';
  93. JitsiMeetJS.mediaDevices.isDeviceListAvailable()
  94. .then((isDeviceListAvailable) => {
  95. if (isDeviceListAvailable &&
  96. JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
  97. this._initializeDeviceSelectionSettings(emitter);
  98. }
  99. });
  100. // Only show the subtitle if this isn't the only setting section.
  101. if (interfaceConfig.SETTINGS_SECTIONS.length > 1)
  102. UIUtil.showElement("deviceOptionsTitle");
  103. UIUtil.showElement(wrapperId);
  104. }
  105. // MODERATOR
  106. if (UIUtil.isSettingEnabled('moderator')) {
  107. const wrapperId = 'moderatorOptionsWrapper';
  108. // START MUTED
  109. $("#startMutedOptions").change(function () {
  110. let startAudioMuted = $("#startAudioMuted").is(":checked");
  111. let startVideoMuted = $("#startVideoMuted").is(":checked");
  112. emitter.emit(
  113. UIEvents.START_MUTED_CHANGED,
  114. startAudioMuted,
  115. startVideoMuted
  116. );
  117. });
  118. // FOLLOW ME
  119. let followMeToggle = document.getElementById('followMeCheckBox');
  120. followMeToggle.addEventListener('change', function() {
  121. let isFollowMeEnabled = followMeToggle.checked;
  122. emitter.emit(
  123. UIEvents.FOLLOW_ME_ENABLED,
  124. isFollowMeEnabled
  125. );
  126. });
  127. UIUtil.showElement(wrapperId);
  128. }
  129. },
  130. _initializeDeviceSelectionSettings(emitter) {
  131. this.changeDevicesList([]);
  132. $('#selectCamera').change(function () {
  133. let cameraDeviceId = $(this).val();
  134. if (cameraDeviceId !== Settings.getCameraDeviceId()) {
  135. emitter.emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
  136. }
  137. });
  138. $('#selectMic').change(function () {
  139. let micDeviceId = $(this).val();
  140. if (micDeviceId !== Settings.getMicDeviceId()) {
  141. emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
  142. }
  143. });
  144. $('#selectAudioOutput').change(function () {
  145. let audioOutputDeviceId = $(this).val();
  146. if (audioOutputDeviceId !== Settings.getAudioOutputDeviceId()) {
  147. emitter.emit(
  148. UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED, audioOutputDeviceId);
  149. }
  150. });
  151. },
  152. /**
  153. * If start audio muted/start video muted options should be visible or not.
  154. * @param {boolean} show
  155. */
  156. showStartMutedOptions (show) {
  157. if (show && UIUtil.isSettingEnabled('moderator')) {
  158. // Only show the subtitle if this isn't the only setting section.
  159. if (!$("#moderatorOptionsTitle").is(":visible")
  160. && interfaceConfig.SETTINGS_SECTIONS.length > 1)
  161. UIUtil.showElement("moderatorOptionsTitle");
  162. UIUtil.showElement("startMutedOptions");
  163. } else {
  164. // Only show the subtitle if this isn't the only setting section.
  165. if ($("#moderatorOptionsTitle").is(":visible"))
  166. UIUtil.hideElement("moderatorOptionsTitle");
  167. UIUtil.hideElement("startMutedOptions");
  168. }
  169. },
  170. updateStartMutedBox (startAudioMuted, startVideoMuted) {
  171. $("#startAudioMuted").attr("checked", startAudioMuted);
  172. $("#startVideoMuted").attr("checked", startVideoMuted);
  173. },
  174. /**
  175. * Shows/hides the follow me options in the settings dialog.
  176. *
  177. * @param {boolean} show {true} to show those options, {false} to hide them
  178. */
  179. showFollowMeOptions (show) {
  180. if (show && UIUtil.isSettingEnabled('moderator')) {
  181. UIUtil.showElement("followMeOptions");
  182. } else {
  183. UIUtil.hideElement("followMeOptions");
  184. }
  185. },
  186. /**
  187. * Check if settings menu is visible or not.
  188. * @returns {boolean}
  189. */
  190. isVisible () {
  191. return UIUtil.isVisible(document.getElementById("settings_container"));
  192. },
  193. /**
  194. * Sets microphone's <select> element to select microphone ID from settings.
  195. */
  196. setSelectedMicFromSettings () {
  197. $('#selectMic').val(Settings.getMicDeviceId());
  198. },
  199. /**
  200. * Sets camera's <select> element to select camera ID from settings.
  201. */
  202. setSelectedCameraFromSettings () {
  203. $('#selectCamera').val(Settings.getCameraDeviceId());
  204. },
  205. /**
  206. * Sets audio outputs's <select> element to select audio output ID from
  207. * settings.
  208. */
  209. setSelectedAudioOutputFromSettings () {
  210. $('#selectAudioOutput').val(Settings.getAudioOutputDeviceId());
  211. },
  212. /**
  213. * Change available cameras/microphones or hide selects completely if
  214. * no devices available.
  215. * @param {{ deviceId, label, kind }[]} devices list of available devices
  216. */
  217. changeDevicesList (devices) {
  218. let $selectCamera= AJS.$('#selectCamera'),
  219. $selectMic = AJS.$('#selectMic'),
  220. $selectAudioOutput = AJS.$('#selectAudioOutput'),
  221. $selectAudioOutputParent = $selectAudioOutput.parent();
  222. let audio = devices.filter(device => device.kind === 'audioinput'),
  223. video = devices.filter(device => device.kind === 'videoinput'),
  224. audioOutput = devices
  225. .filter(device => device.kind === 'audiooutput'),
  226. selectedAudioDevice = audio.find(
  227. d => d.deviceId === Settings.getMicDeviceId()) || audio[0],
  228. selectedVideoDevice = video.find(
  229. d => d.deviceId === Settings.getCameraDeviceId()) || video[0],
  230. selectedAudioOutputDevice = audioOutput.find(
  231. d => d.deviceId === Settings.getAudioOutputDeviceId()),
  232. videoPermissionGranted =
  233. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('video'),
  234. audioPermissionGranted =
  235. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('audio');
  236. $selectCamera
  237. .html(generateDevicesOptions(
  238. video,
  239. selectedVideoDevice ? selectedVideoDevice.deviceId : '',
  240. videoPermissionGranted))
  241. .prop('disabled', !video.length || !videoPermissionGranted);
  242. initSelect2($selectCamera);
  243. $selectMic
  244. .html(generateDevicesOptions(
  245. audio,
  246. selectedAudioDevice ? selectedAudioDevice.deviceId : '',
  247. audioPermissionGranted))
  248. .prop('disabled', !audio.length || !audioPermissionGranted);
  249. initSelect2($selectMic);
  250. if (JitsiMeetJS.mediaDevices.isDeviceChangeAvailable('output')) {
  251. $selectAudioOutput
  252. .html(generateDevicesOptions(
  253. audioOutput,
  254. selectedAudioOutputDevice
  255. ? selectedAudioOutputDevice.deviceId
  256. : 'default',
  257. videoPermissionGranted || audioPermissionGranted))
  258. .prop('disabled', !audioOutput.length ||
  259. (!videoPermissionGranted && !audioPermissionGranted));
  260. initSelect2($selectAudioOutput);
  261. $selectAudioOutputParent.show();
  262. } else {
  263. $selectAudioOutputParent.hide();
  264. }
  265. APP.translation.translateElement($('#settings_container option'));
  266. }
  267. };