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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. // AVATAR URL CHANGED
  71. function updateAvatarUrl () {
  72. emitter.emit(UIEvents.AVATAR_URL_CHANGED, $('#setAvatarUrl').val());
  73. }
  74. $('#setEmail')
  75. .val(Settings.getEmail())
  76. .keyup(function (event) {
  77. if (event.keyCode === 13) { // enter
  78. updateEmail();
  79. }
  80. }).focusout(updateEmail);
  81. $('#setAvatarUrl')
  82. .val(Settings.getAvatarUrl())
  83. .keyup(function (event) {
  84. if (event.keyCode === 13) { // enter
  85. updateAvatarUrl();
  86. }
  87. }).focusout(updateAvatarUrl);
  88. // START MUTED
  89. $("#startMutedOptions").change(function () {
  90. let startAudioMuted = $("#startAudioMuted").is(":checked");
  91. let startVideoMuted = $("#startVideoMuted").is(":checked");
  92. emitter.emit(
  93. UIEvents.START_MUTED_CHANGED,
  94. startAudioMuted,
  95. startVideoMuted
  96. );
  97. });
  98. // FOLLOW ME
  99. $("#followMeOptions").change(function () {
  100. let isFollowMeEnabled = $("#followMeCheckBox").is(":checked");
  101. emitter.emit(
  102. UIEvents.FOLLOW_ME_ENABLED,
  103. isFollowMeEnabled
  104. );
  105. });
  106. // LANGUAGES BOX
  107. let languagesBox = $("#languages_selectbox");
  108. languagesBox.html(generateLanguagesOptions(
  109. languages.getLanguages(),
  110. APP.translation.getCurrentLanguage()
  111. ));
  112. APP.translation.translateElement(languagesBox);
  113. languagesBox.change(function () {
  114. emitter.emit(UIEvents.LANG_CHANGED, languagesBox.val());
  115. });
  116. // DEVICES LIST
  117. if (JitsiMeetJS.mediaDevices.isDeviceListAvailable() &&
  118. JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
  119. this.changeDevicesList([]);
  120. $('#selectCamera').change(function () {
  121. let cameraDeviceId = $(this).val();
  122. if (cameraDeviceId !== Settings.getCameraDeviceId()) {
  123. emitter.emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
  124. }
  125. });
  126. $('#selectMic').change(function () {
  127. let micDeviceId = $(this).val();
  128. if (micDeviceId !== Settings.getMicDeviceId()) {
  129. emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
  130. }
  131. });
  132. $('#selectAudioOutput').change(function () {
  133. let audioOutputDeviceId = $(this).val();
  134. if (audioOutputDeviceId !== Settings.getAudioOutputDeviceId()) {
  135. emitter.emit(UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
  136. audioOutputDeviceId);
  137. }
  138. });
  139. }
  140. },
  141. /**
  142. * If start audio muted/start video muted options should be visible or not.
  143. * @param {boolean} show
  144. */
  145. showStartMutedOptions (show) {
  146. if (show) {
  147. $("#startMutedOptions").css("display", "block");
  148. } else {
  149. $("#startMutedOptions").css("display", "none");
  150. }
  151. },
  152. updateStartMutedBox (startAudioMuted, startVideoMuted) {
  153. $("#startAudioMuted").attr("checked", startAudioMuted);
  154. $("#startVideoMuted").attr("checked", startVideoMuted);
  155. },
  156. /**
  157. * Shows/hides the follow me options in the settings dialog.
  158. *
  159. * @param {boolean} show {true} to show those options, {false} to hide them
  160. */
  161. showFollowMeOptions (show) {
  162. if (show) {
  163. $("#followMeOptions").css("display", "block");
  164. } else {
  165. $("#followMeOptions").css("display", "none");
  166. }
  167. },
  168. /**
  169. * Check if settings menu is visible or not.
  170. * @returns {boolean}
  171. */
  172. isVisible () {
  173. return UIUtil.isVisible(document.getElementById("settingsmenu"));
  174. },
  175. /**
  176. * Change user display name in the settings menu.
  177. * @param {string} newDisplayName
  178. */
  179. changeDisplayName (newDisplayName) {
  180. $('#setDisplayName').val(newDisplayName);
  181. },
  182. /**
  183. * Change user avatar in the settings menu.
  184. * @param {string} avatarUrl url of the new avatar
  185. */
  186. changeAvatar (avatarUrl) {
  187. $('#avatar').attr('src', avatarUrl);
  188. },
  189. /**
  190. * Sets microphone's <select> element to select microphone ID from settings.
  191. */
  192. setSelectedMicFromSettings () {
  193. $('#selectMic').val(Settings.getMicDeviceId());
  194. },
  195. /**
  196. * Sets camera's <select> element to select camera ID from settings.
  197. */
  198. setSelectedCameraFromSettings () {
  199. $('#selectCamera').val(Settings.getCameraDeviceId());
  200. },
  201. /**
  202. * Sets audio outputs's <select> element to select audio output ID from
  203. * settings.
  204. */
  205. setSelectedAudioOutputFromSettings () {
  206. $('#selectAudioOutput').val(Settings.getAudioOutputDeviceId());
  207. },
  208. /**
  209. * Change available cameras/microphones or hide selects completely if
  210. * no devices available.
  211. * @param {{ deviceId, label, kind }[]} devices list of available devices
  212. */
  213. changeDevicesList (devices) {
  214. let $selectCamera= $('#selectCamera'),
  215. $selectMic = $('#selectMic'),
  216. $selectAudioOutput = $('#selectAudioOutput'),
  217. $selectAudioOutputParent = $selectAudioOutput.parent();
  218. let audio = devices.filter(device => device.kind === 'audioinput'),
  219. video = devices.filter(device => device.kind === 'videoinput'),
  220. audioOutput = devices
  221. .filter(device => device.kind === 'audiooutput'),
  222. selectedAudioDevice = audio.find(
  223. d => d.deviceId === Settings.getMicDeviceId()) || audio[0],
  224. selectedVideoDevice = video.find(
  225. d => d.deviceId === Settings.getCameraDeviceId()) || video[0],
  226. selectedAudioOutputDevice = audioOutput.find(
  227. d => d.deviceId === Settings.getAudioOutputDeviceId()),
  228. videoPermissionGranted =
  229. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('video'),
  230. audioPermissionGranted =
  231. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('audio');
  232. $selectCamera
  233. .html(generateDevicesOptions(
  234. video,
  235. selectedVideoDevice ? selectedVideoDevice.deviceId : '',
  236. videoPermissionGranted))
  237. .prop('disabled', !video.length || !videoPermissionGranted);
  238. $selectMic
  239. .html(generateDevicesOptions(
  240. audio,
  241. selectedAudioDevice ? selectedAudioDevice.deviceId : '',
  242. audioPermissionGranted))
  243. .prop('disabled', !audio.length || !audioPermissionGranted);
  244. if (JitsiMeetJS.mediaDevices.isDeviceChangeAvailable('output')) {
  245. $selectAudioOutput
  246. .html(generateDevicesOptions(
  247. audioOutput,
  248. selectedAudioOutputDevice
  249. ? selectedAudioOutputDevice.deviceId
  250. : 'default',
  251. videoPermissionGranted || audioPermissionGranted))
  252. .prop('disabled', !audioOutput.length ||
  253. (!videoPermissionGranted && !audioPermissionGranted));
  254. $selectAudioOutputParent.show();
  255. } else {
  256. $selectAudioOutputParent.hide();
  257. }
  258. $('#devicesOptions').show();
  259. APP.translation.translateElement($('#settingsmenu option'));
  260. }
  261. };