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';
|
2017-04-09 21:20:37 +00:00
|
|
|
|
2021-02-02 19:41:04 +00:00
|
|
|
import { getDeviceSelectionDialogProps } 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
|
|
|
/**
|
|
|
|
* Submits the settings related to device selection.
|
|
|
|
*
|
|
|
|
* @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}
|
|
|
|
*/
|
2022-10-13 08:26:28 +00:00
|
|
|
export function submitDeviceSelectionTab(newState: any, isDisplayedOnWelcomePage: boolean) {
|
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2022-05-24 19:04:21 +00:00
|
|
|
const currentState = getDeviceSelectionDialogProps(getState(), isDisplayedOnWelcomePage);
|
2018-06-20 20:19:53 +00:00
|
|
|
|
2022-05-23 18:47:07 +00:00
|
|
|
if (newState.selectedVideoInputId && (newState.selectedVideoInputId !== currentState.selectedVideoInputId)) {
|
2018-08-06 15:24:59 +00:00
|
|
|
dispatch(updateSettings({
|
2019-05-07 08:53:01 +00:00
|
|
|
userSelectedCameraDeviceId: newState.selectedVideoInputId,
|
|
|
|
userSelectedCameraDeviceLabel:
|
|
|
|
getDeviceLabelById(getState(), newState.selectedVideoInputId, 'videoInput')
|
2018-08-06 15:24:59 +00:00
|
|
|
}));
|
|
|
|
|
2022-04-25 19:01:10 +00:00
|
|
|
dispatch(setVideoInputDevice(newState.selectedVideoInputId));
|
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
|
|
|
|
&& 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
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|