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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * @returns {Function}
  16. */
  17. export function submitDeviceSelectionTab(newState) {
  18. return (dispatch, getState) => {
  19. const currentState = getDeviceSelectionDialogProps(getState());
  20. if (newState.selectedVideoInputId
  21. && newState.selectedVideoInputId
  22. !== currentState.selectedVideoInputId) {
  23. dispatch(updateSettings({
  24. userSelectedCameraDeviceId: newState.selectedVideoInputId,
  25. userSelectedCameraDeviceLabel:
  26. getDeviceLabelById(getState(), newState.selectedVideoInputId, 'videoInput')
  27. }));
  28. dispatch(
  29. setVideoInputDevice(newState.selectedVideoInputId));
  30. }
  31. if (newState.selectedAudioInputId
  32. && newState.selectedAudioInputId
  33. !== currentState.selectedAudioInputId) {
  34. dispatch(updateSettings({
  35. userSelectedMicDeviceId: newState.selectedAudioInputId,
  36. userSelectedMicDeviceLabel:
  37. getDeviceLabelById(getState(), newState.selectedAudioInputId, 'audioInput')
  38. }));
  39. dispatch(
  40. setAudioInputDevice(newState.selectedAudioInputId));
  41. }
  42. if (newState.selectedAudioOutputId
  43. && newState.selectedAudioOutputId
  44. !== currentState.selectedAudioOutputId) {
  45. sendAnalytics(createDeviceChangedEvent('audio', 'output'));
  46. setAudioOutputDeviceId(
  47. newState.selectedAudioOutputId,
  48. dispatch,
  49. true,
  50. getDeviceLabelById(getState(), newState.selectedAudioOutputId, 'audioOutput'))
  51. .then(() => logger.log('changed audio output device'))
  52. .catch(err => {
  53. logger.warn(
  54. 'Failed to change audio output device.',
  55. 'Default or previously set audio output device will',
  56. ' be used instead.',
  57. err);
  58. });
  59. }
  60. };
  61. }