2022-10-13 08:26:28 +00:00
|
|
|
import { createDeviceChangedEvent } from '../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../analytics/functions';
|
|
|
|
import { IStore } from '../app/types';
|
2018-04-12 19:58:20 +00:00
|
|
|
import {
|
2017-06-04 03:12:04 +00:00
|
|
|
setAudioInputDevice,
|
|
|
|
setVideoInputDevice
|
2022-10-13 08:26:28 +00:00
|
|
|
} from '../base/devices/actions';
|
|
|
|
import { getDeviceLabelById, setAudioOutputDeviceId } from '../base/devices/functions';
|
|
|
|
import { updateSettings } from '../base/settings/actions';
|
2023-03-06 13:14:52 +00:00
|
|
|
import { toggleNoiseSuppression } from '../noise-suppression/actions';
|
|
|
|
import { setScreenshareFramerate } from '../screen-share/actions';
|
2017-04-09 21:20:37 +00:00
|
|
|
|
2023-03-06 13:14:52 +00:00
|
|
|
import { getAudioDeviceSelectionDialogProps, getVideoDeviceSelectionDialogProps } from './functions';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
2018-08-06 15:24:59 +00:00
|
|
|
|
2018-06-20 20:19:53 +00:00
|
|
|
/**
|
2023-03-06 13:14:52 +00:00
|
|
|
* Submits the settings related to audio device selection.
|
2018-06-20 20:19:53 +00:00
|
|
|
*
|
|
|
|
* @param {Object} newState - The new settings.
|
2022-05-24 19:04:21 +00:00
|
|
|
* @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
|
|
|
|
* welcome page or not.
|
2018-06-20 20:19:53 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2023-03-06 13:14:52 +00:00
|
|
|
export function submitAudioDeviceSelectionTab(newState: any, isDisplayedOnWelcomePage: boolean) {
|
2022-10-13 08:26:28 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2023-03-06 13:14:52 +00:00
|
|
|
const currentState = getAudioDeviceSelectionDialogProps(getState(), isDisplayedOnWelcomePage);
|
2018-06-20 20:19:53 +00:00
|
|
|
|
2022-05-23 18:47:07 +00:00
|
|
|
if (newState.selectedAudioInputId && newState.selectedAudioInputId !== currentState.selectedAudioInputId) {
|
2018-08-06 15:24:59 +00:00
|
|
|
dispatch(updateSettings({
|
2019-05-07 08:53:01 +00:00
|
|
|
userSelectedMicDeviceId: newState.selectedAudioInputId,
|
|
|
|
userSelectedMicDeviceLabel:
|
|
|
|
getDeviceLabelById(getState(), newState.selectedAudioInputId, 'audioInput')
|
2018-08-06 15:24:59 +00:00
|
|
|
}));
|
|
|
|
|
2022-04-25 19:01:10 +00:00
|
|
|
dispatch(setAudioInputDevice(newState.selectedAudioInputId));
|
2018-06-20 20:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newState.selectedAudioOutputId
|
2023-03-06 13:14:52 +00:00
|
|
|
&& newState.selectedAudioOutputId
|
|
|
|
!== currentState.selectedAudioOutputId) {
|
2018-08-06 15:24:59 +00:00
|
|
|
sendAnalytics(createDeviceChangedEvent('audio', 'output'));
|
|
|
|
|
|
|
|
setAudioOutputDeviceId(
|
|
|
|
newState.selectedAudioOutputId,
|
2019-05-01 14:13:25 +00:00
|
|
|
dispatch,
|
2019-05-07 08:53:01 +00:00
|
|
|
true,
|
|
|
|
getDeviceLabelById(getState(), newState.selectedAudioOutputId, 'audioOutput'))
|
2018-08-06 15:24:59 +00:00
|
|
|
.then(() => logger.log('changed audio output device'))
|
|
|
|
.catch(err => {
|
|
|
|
logger.warn(
|
|
|
|
'Failed to change audio output device.',
|
|
|
|
'Default or previously set audio output device will',
|
|
|
|
' be used instead.',
|
|
|
|
err);
|
|
|
|
});
|
2018-06-20 20:19:53 +00:00
|
|
|
}
|
2023-03-06 13:14:52 +00:00
|
|
|
|
|
|
|
if (newState.noiseSuppressionEnabled !== currentState.noiseSuppressionEnabled) {
|
|
|
|
dispatch(toggleNoiseSuppression());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submits the settings related to device selection.
|
|
|
|
*
|
|
|
|
* @param {Object} newState - The new settings.
|
|
|
|
* @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
|
|
|
|
* welcome page or not.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function submitVideoDeviceSelectionTab(newState: any, isDisplayedOnWelcomePage: boolean) {
|
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
|
|
|
const currentState = getVideoDeviceSelectionDialogProps(getState(), isDisplayedOnWelcomePage);
|
|
|
|
|
|
|
|
if (newState.selectedVideoInputId && (newState.selectedVideoInputId !== currentState.selectedVideoInputId)) {
|
|
|
|
dispatch(updateSettings({
|
|
|
|
userSelectedCameraDeviceId: newState.selectedVideoInputId,
|
|
|
|
userSelectedCameraDeviceLabel:
|
|
|
|
getDeviceLabelById(getState(), newState.selectedVideoInputId, 'videoInput')
|
|
|
|
}));
|
|
|
|
|
|
|
|
dispatch(setVideoInputDevice(newState.selectedVideoInputId));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newState.localFlipX !== currentState.localFlipX) {
|
|
|
|
dispatch(updateSettings({
|
|
|
|
localFlipX: newState.localFlipX
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newState.currentFramerate !== currentState.currentFramerate) {
|
|
|
|
const frameRate = parseInt(newState.currentFramerate, 10);
|
|
|
|
|
|
|
|
dispatch(setScreenshareFramerate(frameRate));
|
|
|
|
}
|
2018-06-20 20:19:53 +00:00
|
|
|
};
|
|
|
|
}
|