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.

actions.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { createDeviceChangedEvent, sendAnalytics } from '../analytics';
  2. import {
  3. getDeviceLabelById,
  4. setAudioInputDevice,
  5. setAudioOutputDeviceId,
  6. setVideoInputDevice
  7. } from '../base/devices';
  8. import { isIosMobileBrowser } from '../base/environment/utils';
  9. import { browser } from '../base/lib-jitsi-meet';
  10. import { updateSettings } from '../base/settings';
  11. import { getDeviceSelectionDialogProps } from './functions';
  12. import logger from './logger';
  13. /**
  14. * Submits the settings related to device selection.
  15. *
  16. * @param {Object} newState - The new settings.
  17. * @returns {Function}
  18. */
  19. export function submitDeviceSelectionTab(newState) {
  20. // Always use the new track for mobile Safari because of https://bugs.webkit.org/show_bug.cgi?id=179363#c30. The
  21. // old track is stopped by the browser when a new track is created for preview so it needs to be replaced even if
  22. // the device selection doesn't change.
  23. const replaceTrackAlways = isIosMobileBrowser() && browser.isVersionGreaterThan('15.3');
  24. return (dispatch, getState) => {
  25. const currentState = getDeviceSelectionDialogProps(getState());
  26. if ((newState.selectedVideoInputId && (newState.selectedVideoInputId !== currentState.selectedVideoInputId))
  27. || replaceTrackAlways) {
  28. dispatch(updateSettings({
  29. userSelectedCameraDeviceId: newState.selectedVideoInputId,
  30. userSelectedCameraDeviceLabel:
  31. getDeviceLabelById(getState(), newState.selectedVideoInputId, 'videoInput')
  32. }));
  33. dispatch(setVideoInputDevice(newState.selectedVideoInputId));
  34. }
  35. if ((newState.selectedAudioInputId && newState.selectedAudioInputId !== currentState.selectedAudioInputId)
  36. || replaceTrackAlways) {
  37. dispatch(updateSettings({
  38. userSelectedMicDeviceId: newState.selectedAudioInputId,
  39. userSelectedMicDeviceLabel:
  40. getDeviceLabelById(getState(), newState.selectedAudioInputId, 'audioInput')
  41. }));
  42. dispatch(setAudioInputDevice(newState.selectedAudioInputId));
  43. }
  44. if (newState.selectedAudioOutputId
  45. && newState.selectedAudioOutputId
  46. !== currentState.selectedAudioOutputId) {
  47. sendAnalytics(createDeviceChangedEvent('audio', 'output'));
  48. setAudioOutputDeviceId(
  49. newState.selectedAudioOutputId,
  50. dispatch,
  51. true,
  52. getDeviceLabelById(getState(), newState.selectedAudioOutputId, 'audioOutput'))
  53. .then(() => logger.log('changed audio output device'))
  54. .catch(err => {
  55. logger.warn(
  56. 'Failed to change audio output device.',
  57. 'Default or previously set audio output device will',
  58. ' be used instead.',
  59. err);
  60. });
  61. }
  62. };
  63. }