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

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