Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

actions.web.ts 4.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 { toggleNoiseSuppression } from '../noise-suppression/actions';
  11. import { setScreenshareFramerate } from '../screen-share/actions';
  12. import { getAudioDeviceSelectionDialogProps, getVideoDeviceSelectionDialogProps } from './functions';
  13. import logger from './logger';
  14. /**
  15. * Submits the settings related to audio device selection.
  16. *
  17. * @param {Object} newState - The new settings.
  18. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
  19. * welcome page or not.
  20. * @returns {Function}
  21. */
  22. export function submitAudioDeviceSelectionTab(newState: any, isDisplayedOnWelcomePage: boolean) {
  23. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  24. const currentState = getAudioDeviceSelectionDialogProps(getState(), isDisplayedOnWelcomePage);
  25. if (newState.selectedAudioInputId && newState.selectedAudioInputId !== currentState.selectedAudioInputId) {
  26. dispatch(updateSettings({
  27. userSelectedMicDeviceId: newState.selectedAudioInputId,
  28. userSelectedMicDeviceLabel:
  29. getDeviceLabelById(getState(), newState.selectedAudioInputId, 'audioInput')
  30. }));
  31. dispatch(setAudioInputDevice(newState.selectedAudioInputId));
  32. }
  33. if (newState.selectedAudioOutputId
  34. && newState.selectedAudioOutputId
  35. !== currentState.selectedAudioOutputId) {
  36. sendAnalytics(createDeviceChangedEvent('audio', 'output'));
  37. setAudioOutputDeviceId(
  38. newState.selectedAudioOutputId,
  39. dispatch,
  40. true,
  41. getDeviceLabelById(getState(), newState.selectedAudioOutputId, 'audioOutput'))
  42. .then(() => logger.log('changed audio output device'))
  43. .catch(err => {
  44. logger.warn(
  45. 'Failed to change audio output device.',
  46. 'Default or previously set audio output device will',
  47. ' be used instead.',
  48. err);
  49. });
  50. }
  51. if (newState.noiseSuppressionEnabled !== currentState.noiseSuppressionEnabled) {
  52. dispatch(toggleNoiseSuppression());
  53. }
  54. };
  55. }
  56. /**
  57. * Submits the settings related to device selection.
  58. *
  59. * @param {Object} newState - The new settings.
  60. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
  61. * welcome page or not.
  62. * @returns {Function}
  63. */
  64. export function submitVideoDeviceSelectionTab(newState: any, isDisplayedOnWelcomePage: boolean) {
  65. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  66. const currentState = getVideoDeviceSelectionDialogProps(getState(), isDisplayedOnWelcomePage);
  67. if (newState.selectedVideoInputId && (newState.selectedVideoInputId !== currentState.selectedVideoInputId)) {
  68. dispatch(updateSettings({
  69. userSelectedCameraDeviceId: newState.selectedVideoInputId,
  70. userSelectedCameraDeviceLabel:
  71. getDeviceLabelById(getState(), newState.selectedVideoInputId, 'videoInput')
  72. }));
  73. dispatch(setVideoInputDevice(newState.selectedVideoInputId));
  74. }
  75. if (newState.localFlipX !== currentState.localFlipX) {
  76. dispatch(updateSettings({
  77. localFlipX: newState.localFlipX
  78. }));
  79. }
  80. if (newState.currentFramerate !== currentState.currentFramerate) {
  81. const frameRate = parseInt(newState.currentFramerate, 10);
  82. dispatch(setScreenshareFramerate(frameRate));
  83. }
  84. };
  85. }