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.

SettingsDialog.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. import mediaDeviceHelper from '../../../devices/mediaDeviceHelper';
  7. const RTCUIUtils = JitsiMeetJS.util.RTCUIHelper;
  8. var constructAudioIndicatorHtml = function() {
  9. return '<span>'
  10. + '<span id="audioLevel0" class="audioLevelDot"></span>'
  11. + '<span id="audioLevel1" class="audioLevelDot"></span>'
  12. + '<span id="audioLevel2" class="audioLevelDot"></span>'
  13. + '<span id="audioLevel3" class="audioLevelDot"></span>'
  14. + '<span id="audioLevel4" class="audioLevelDot"></span>'
  15. + '<span id="audioLevel5" class="audioLevelDot"></span>'
  16. + '<span id="audioLevel6" class="audioLevelDot"></span>'
  17. + '<span id="audioLevel7" class="audioLevelDot"></span>'
  18. + '<span id="audioLevel8" class="audioLevelDot"></span>'
  19. + '<span id="audioLevel9" class="audioLevelDot"></span>'
  20. + '</span>';
  21. };
  22. var constructMediaSettingsHtml = function() {
  23. return '<div class="settingsContent">'
  24. + '<video id="localVideoPreview"></video>'
  25. //+ constructAudioIndicatorHtml()
  26. + '<div class="deviceSelection">'
  27. + '<span class="device">'
  28. + '<select id="selectCamera"></select> '
  29. + '</span>'
  30. + '<span class="device">'
  31. + '<select id="selectMic"></select> '
  32. + '</span>'
  33. + '<span class="device">'
  34. + '<select id="selectAudioOutput"></select> '
  35. + '</span>'
  36. + '</div>'
  37. + '</div>';
  38. };
  39. /**
  40. * The callback function corresponding to the openSettingsWindow parameter.
  41. *
  42. * @type {function}
  43. */
  44. var settingsWindowCallback = null;
  45. /**
  46. * Defines all methods in connection to the Settings dialog.
  47. */
  48. var SettingsDialog = {
  49. init(eventEmitter) {
  50. this.eventEmitter = eventEmitter;
  51. },
  52. /**
  53. * Generate html select options for available physical devices.
  54. * @param {{ deviceId, label }[]} items available devices
  55. * @param {string} [selectedId] id of selected device
  56. * @param {boolean} permissionGranted if permission to use selected device
  57. * type is granted
  58. * @returns {string}
  59. */
  60. _generateDevicesOptions(items, selectedId, permissionGranted) {
  61. if (!permissionGranted && items.length) {
  62. return '<option data-i18n="settings.noPermission"></option>';
  63. }
  64. var options = items.map(function (item) {
  65. let attrs = {
  66. value: item.deviceId
  67. };
  68. if (item.deviceId === selectedId) {
  69. attrs.selected = 'selected';
  70. }
  71. let attrsStr = UIUtil.attrsToString(attrs);
  72. return `<option ${attrsStr}>${item.label}</option>`;
  73. });
  74. if (!items.length) {
  75. options.unshift('<option data-i18n="settings.noDevice"></option>');
  76. }
  77. return options.join('');
  78. },
  79. _onLoadMediaSettings() {
  80. let localVideoPreview = document.getElementById("localVideoPreview");
  81. RTCUIUtils.setAutoPlay(localVideoPreview, true);
  82. RTCUIUtils.setVolume(localVideoPreview, 0);
  83. let localVideo = APP.conference.getVideoStream();
  84. if (localVideo)
  85. localVideoPreview = localVideo.attach(localVideoPreview);
  86. this.eventEmitter.addListener(UIEvents.VIDEO_STREAM_CHANGED,
  87. function(newStream)
  88. {
  89. newStream.attach(localVideoPreview);
  90. });
  91. // DEVICES LIST
  92. JitsiMeetJS.mediaDevices.isDeviceListAvailable()
  93. .then((isDeviceListAvailable) => {
  94. if (isDeviceListAvailable &&
  95. JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
  96. this._initializeDeviceSelectionSettings();
  97. }
  98. });
  99. APP.UI.eventEmitter.addListener(UIEvents.DEVICE_LIST_CHANGED,
  100. (devices) => {
  101. this._changeDevicesList(devices);
  102. });
  103. },
  104. /**
  105. * Initializes the device list with the current available media devices
  106. * and attaches all listeners needed for device change user
  107. * event handling.
  108. */
  109. _initializeDeviceSelectionSettings() {
  110. this._changeDevicesList(mediaDeviceHelper.getCurrentMediaDevices());
  111. $('#selectCamera').change(function () {
  112. let cameraDeviceId = $(this).val();
  113. if (cameraDeviceId !== Settings.getCameraDeviceId()) {
  114. this.eventEmitter
  115. .emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
  116. }
  117. });
  118. $('#selectMic').change(function () {
  119. let micDeviceId = $(this).val();
  120. if (micDeviceId !== Settings.getMicDeviceId()) {
  121. this.eventEmitter
  122. .emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
  123. }
  124. });
  125. $('#selectAudioOutput').change(function () {
  126. let audioOutputDeviceId = $(this).val();
  127. if (audioOutputDeviceId !== Settings.getAudioOutputDeviceId()) {
  128. this.eventEmitter.emit(
  129. UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED, audioOutputDeviceId);
  130. }
  131. });
  132. },
  133. /**
  134. * Sets microphone's <select> element to select microphone ID from settings.
  135. */
  136. setSelectedMicFromSettings () {
  137. $('#selectMic').val(Settings.getMicDeviceId());
  138. },
  139. /**
  140. * Sets camera's <select> element to select camera ID from settings.
  141. */
  142. setSelectedCameraFromSettings () {
  143. $('#selectCamera').val(Settings.getCameraDeviceId());
  144. },
  145. /**
  146. * Sets audio outputs's <select> element to select audio output ID from
  147. * settings.
  148. */
  149. setSelectedAudioOutputFromSettings () {
  150. $('#selectAudioOutput').val(Settings.getAudioOutputDeviceId());
  151. },
  152. /**
  153. * Change available cameras/microphones or hide selects completely if
  154. * no devices available.
  155. * @param {{ deviceId, label, kind }[]} devices list of available devices
  156. */
  157. _changeDevicesList (devices) {
  158. let $selectCamera= $('#selectCamera'),
  159. $selectMic = $('#selectMic'),
  160. $selectAudioOutput = $('#selectAudioOutput'),
  161. $selectAudioOutputParent = $selectAudioOutput.parent();
  162. let audio = devices.audioinput,
  163. video = devices.videoinput,
  164. audioOutput = devices.audiooutput,
  165. selectedAudioDevice = audio.find(
  166. d => d.deviceId === Settings.getMicDeviceId()) || audio[0],
  167. selectedVideoDevice = video.find(
  168. d => d.deviceId === Settings.getCameraDeviceId()) || video[0],
  169. selectedAudioOutputDevice = audioOutput.find(
  170. d => d.deviceId === Settings.getAudioOutputDeviceId()),
  171. videoPermissionGranted =
  172. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('video'),
  173. audioPermissionGranted =
  174. JitsiMeetJS.mediaDevices.isDevicePermissionGranted('audio');
  175. $selectCamera
  176. .html(this._generateDevicesOptions(
  177. video,
  178. selectedVideoDevice ? selectedVideoDevice.deviceId : '',
  179. videoPermissionGranted))
  180. .prop('disabled', !video.length || !videoPermissionGranted);
  181. $selectMic
  182. .html(this._generateDevicesOptions(
  183. audio,
  184. selectedAudioDevice ? selectedAudioDevice.deviceId : '',
  185. audioPermissionGranted))
  186. .prop('disabled', !audio.length || !audioPermissionGranted);
  187. if (JitsiMeetJS.mediaDevices.isDeviceChangeAvailable('output')) {
  188. $selectAudioOutput
  189. .html(this._generateDevicesOptions(
  190. audioOutput,
  191. selectedAudioOutputDevice
  192. ? selectedAudioOutputDevice.deviceId
  193. : 'default',
  194. videoPermissionGranted || audioPermissionGranted))
  195. .prop('disabled', !audioOutput.length ||
  196. (!videoPermissionGranted && !audioPermissionGranted));
  197. $selectAudioOutputParent.show();
  198. } else {
  199. $selectAudioOutputParent.hide();
  200. }
  201. $('#devicesOptions').show();
  202. APP.translation.translateElement($('#settings_container option'));
  203. },
  204. /**
  205. * Opens the feedback window.
  206. */
  207. openSettingsDialog: function (callback) {
  208. settingsWindowCallback = callback;
  209. var htmlString = '<div class="settingsDialog">'
  210. + constructMediaSettingsHtml()
  211. + '</div>';
  212. // Defines the different states of the feedback window.
  213. var states = {
  214. mediaSettings: {
  215. title: APP.translation.translateString("settings.title"),
  216. html: htmlString,
  217. persistent: false,
  218. buttons: {},
  219. closeText: '',
  220. //focus: "div[id='stars']",
  221. position: {width: 600}
  222. }
  223. };
  224. const cancelButton
  225. = APP.translation.generateTranslationHTML("dialog.Cancel");
  226. const saveButton
  227. = APP.translation.generateTranslationHTML("dialog.Save");
  228. // Create the settings dialog.
  229. var settingsDialog
  230. = APP.UI.messageHandler.openDialogWithStates(
  231. states,
  232. {
  233. persistent: false,
  234. buttons: [
  235. {title: cancelButton, value: false},
  236. {title: saveButton, value: true}
  237. ],
  238. closeText: '',
  239. loaded: this._onLoadMediaSettings.bind(this),
  240. position: {width: 500},
  241. submit: function (e, v, m, f) {
  242. e.preventDefault();
  243. if (!v) {
  244. }
  245. }
  246. }, null);
  247. JitsiMeetJS.analytics.sendEvent('settings.open');
  248. }
  249. };
  250. // Exports the SettingsDialog class.
  251. module.exports = SettingsDialog;