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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { createDeviceChangedEvent } from '../analytics/AnalyticsEvents';
  2. import { sendAnalytics } from '../analytics/functions';
  3. import { IStore } from '../app/types';
  4. import {
  5. setAudioInputDevice,
  6. setVideoInputDevice
  7. } from '../base/devices/actions';
  8. import { getDeviceLabelById, setAudioOutputDeviceId } from '../base/devices/functions';
  9. import { updateSettings } from '../base/settings/actions';
  10. import { getDeviceSelectionDialogProps } from './functions';
  11. import logger from './logger';
  12. /**
  13. * Submits the settings related to device selection.
  14. *
  15. * @param {Object} newState - The new settings.
  16. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
  17. * welcome page or not.
  18. * @returns {Function}
  19. */
  20. export function submitDeviceSelectionTab(newState: any, isDisplayedOnWelcomePage: boolean) {
  21. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  22. const currentState = getDeviceSelectionDialogProps(getState(), isDisplayedOnWelcomePage);
  23. if (newState.selectedVideoInputId && (newState.selectedVideoInputId !== currentState.selectedVideoInputId)) {
  24. dispatch(updateSettings({
  25. userSelectedCameraDeviceId: newState.selectedVideoInputId,
  26. userSelectedCameraDeviceLabel:
  27. getDeviceLabelById(getState(), newState.selectedVideoInputId, 'videoInput')
  28. }));
  29. dispatch(setVideoInputDevice(newState.selectedVideoInputId));
  30. }
  31. if (newState.selectedAudioInputId && newState.selectedAudioInputId !== currentState.selectedAudioInputId) {
  32. dispatch(updateSettings({
  33. userSelectedMicDeviceId: newState.selectedAudioInputId,
  34. userSelectedMicDeviceLabel:
  35. getDeviceLabelById(getState(), newState.selectedAudioInputId, 'audioInput')
  36. }));
  37. dispatch(setAudioInputDevice(newState.selectedAudioInputId));
  38. }
  39. if (newState.selectedAudioOutputId
  40. && newState.selectedAudioOutputId
  41. !== currentState.selectedAudioOutputId) {
  42. sendAnalytics(createDeviceChangedEvent('audio', 'output'));
  43. setAudioOutputDeviceId(
  44. newState.selectedAudioOutputId,
  45. dispatch,
  46. true,
  47. getDeviceLabelById(getState(), newState.selectedAudioOutputId, 'audioOutput'))
  48. .then(() => logger.log('changed audio output device'))
  49. .catch(err => {
  50. logger.warn(
  51. 'Failed to change audio output device.',
  52. 'Default or previously set audio output device will',
  53. ' be used instead.',
  54. err);
  55. });
  56. }
  57. };
  58. }