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

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