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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. // DISPLAY NAME
  55. function updateDisplayName () {
  56. emitter.emit(UIEvents.NICKNAME_CHANGED, $('#setDisplayName').val());
  57. }
  58. $('#setDisplayName')
  59. .val(Settings.getDisplayName())
  60. .keyup(function (event) {
  61. if (event.keyCode === 13) { // enter
  62. updateDisplayName();
  63. }
  64. })
  65. .focusout(updateDisplayName);
  66. // EMAIL
  67. function updateEmail () {
  68. emitter.emit(UIEvents.EMAIL_CHANGED, $('#setEmail').val());
  69. }
  70. $('#setEmail')
  71. .val(Settings.getEmail())
  72. .keyup(function (event) {
  73. if (event.keyCode === 13) { // enter
  74. updateEmail();
  75. }
  76. }).focusout(updateEmail);
  77. // START MUTED
  78. $("#startMutedOptions").change(function () {
  79. let startAudioMuted = $("#startAudioMuted").is(":checked");
  80. let startVideoMuted = $("#startVideoMuted").is(":checked");
  81. emitter.emit(
  82. UIEvents.START_MUTED_CHANGED,
  83. startAudioMuted,
  84. startVideoMuted
  85. );
  86. });
  87. // FOLLOW ME
  88. $("#followMeOptions").change(function () {
  89. let isFollowMeEnabled = $("#followMeCheckBox").is(":checked");
  90. emitter.emit(
  91. UIEvents.FOLLOW_ME_ENABLED,
  92. isFollowMeEnabled
  93. );
  94. });
  95. // LANGUAGES BOX
  96. let languagesBox = $("#languages_selectbox");
  97. languagesBox.html(generateLanguagesOptions(
  98. languages.getLanguages(),
  99. APP.translation.getCurrentLanguage()
  100. ));
  101. APP.translation.translateElement(languagesBox);
  102. languagesBox.change(function () {
  103. emitter.emit(UIEvents.LANG_CHANGED, languagesBox.val());
  104. });
  105. // DEVICES LIST
  106. if (JitsiMeetJS.mediaDevices.isDeviceListAvailable() &&
  107. JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
  108. this.changeDevicesList([]);
  109. $('#selectCamera').change(function () {
  110. let cameraDeviceId = $(this).val();
  111. if (cameraDeviceId !== Settings.getCameraDeviceId()) {
  112. emitter.emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
  113. }
  114. });
  115. $('#selectMic').change(function () {
  116. let micDeviceId = $(this).val();
  117. if (micDeviceId !== Settings.getMicDeviceId()) {
  118. emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
  119. }
  120. });
  121. $('#selectAudioOutput').change(function () {
  122. let audioOutputDeviceId = $(this).val();
  123. if (audioOutputDeviceId !== Settings.getAudioOutputDeviceId()) {
  124. emitter.emit(UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
  125. audioOutputDeviceId);
  126. }
  127. });
  128. }
  129. },
  130. /**
  131. * If start audio muted/start video muted options should be visible or not.
  132. * @param {boolean} show
  133. */
  134. showStartMutedOptions (show) {
  135. if (show) {
  136. $("#startMutedOptions").css("display", "block");
  137. } else {
  138. $("#startMutedOptions").css("display", "none");
  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) {
  152. $("#followMeOptions").css("display", "block");
  153. } else {
  154. $("#followMeOptions").css("display", "none");
  155. }
  156. },
  157. /**
  158. * Check if settings menu is visible or not.
  159. * @returns {boolean}
  160. */
  161. isVisible () {
  162. return UIUtil.isVisible(document.getElementById("settingsmenu"));
  163. },
  164. /**
  165. * Change user display name in the settings menu.
  166. * @param {string} newDisplayName
  167. */
  168. changeDisplayName (newDisplayName) {
  169. $('#setDisplayName').val(newDisplayName);
  170. },
  171. /**
  172. * Change user avatar in the settings menu.
  173. * @param {string} avatarUrl url of the new avatar
  174. */
  175. changeAvatar (avatarUrl) {
  176. $('#avatar').attr('src', avatarUrl);
  177. },
  178. /**
  179. * Change available cameras/microphones or hide selects completely if
  180. * no devices available.
  181. * @param {{ deviceId, label, kind }[]} devices list of available devices
  182. */
  183. changeDevicesList (devices) {
  184. let $selectCamera= $('#selectCamera'),
  185. $selectMic = $('#selectMic'),
  186. $selectAudioOutput = $('#selectAudioOutput'),
  187. $selectAudioOutputParent = $selectAudioOutput.parent();
  188. let audio = devices.filter(device => device.kind === 'audioinput'),
  189. video = devices.filter(device => device.kind === 'videoinput'),
  190. audioOutput = devices
  191. .filter(device => device.kind === 'audiooutput'),
  192. selectedAudioDevice = audio.find(
  193. d => d.deviceId === Settings.getMicDeviceId()) || audio[0],
  194. selectedVideoDevice = video.find(
  195. d => d.deviceId === Settings.getCameraDeviceId()) || video[0],
  196. selectedAudioOutputDevice = audioOutput.find(
  197. d => d.deviceId === Settings.getAudioOutputDeviceId()),
  198. videoPermissionGranted =
  199. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('video'),
  200. audioPermissionGranted =
  201. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('audio');
  202. $selectCamera
  203. .html(generateDevicesOptions(
  204. video,
  205. selectedVideoDevice ? selectedVideoDevice.deviceId : '',
  206. videoPermissionGranted))
  207. .prop('disabled', !video.length || !videoPermissionGranted);
  208. $selectMic
  209. .html(generateDevicesOptions(
  210. audio,
  211. selectedAudioDevice ? selectedAudioDevice.deviceId : '',
  212. audioPermissionGranted))
  213. .prop('disabled', !audio.length || !audioPermissionGranted);
  214. if (JitsiMeetJS.mediaDevices.isDeviceChangeAvailable('output')) {
  215. $selectAudioOutput
  216. .html(generateDevicesOptions(
  217. audioOutput,
  218. selectedAudioOutputDevice
  219. ? selectedAudioOutputDevice.deviceId
  220. : 'default',
  221. videoPermissionGranted || audioPermissionGranted))
  222. .prop('disabled', !audioOutput.length ||
  223. (!videoPermissionGranted && !audioPermissionGranted));
  224. $selectAudioOutputParent.show();
  225. } else {
  226. $selectAudioOutputParent.hide();
  227. }
  228. $('#devicesOptions').show();
  229. APP.translation.translateElement($('#settingsmenu option'));
  230. }
  231. };