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.6KB

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