2022-10-13 11:26:28 +03:00
|
|
|
import { createDeviceChangedEvent } from '../analytics/AnalyticsEvents';
|
|
|
|
|
import { sendAnalytics } from '../analytics/functions';
|
|
|
|
|
import { IStore } from '../app/types';
|
2018-04-12 21:58:20 +02:00
|
|
|
import {
|
2017-06-03 22:12:04 -05:00
|
|
|
setAudioInputDevice,
|
|
|
|
|
setVideoInputDevice
|
2022-10-13 11:26:28 +03:00
|
|
|
} from '../base/devices/actions';
|
|
|
|
|
import { getDeviceLabelById, setAudioOutputDeviceId } from '../base/devices/functions';
|
|
|
|
|
import { updateSettings } from '../base/settings/actions';
|
2017-04-09 14:20:37 -07:00
|
|
|
|
2021-02-02 13:41:04 -06:00
|
|
|
import { getDeviceSelectionDialogProps } from './functions';
|
2019-08-21 16:50:00 +02:00
|
|
|
import logger from './logger';
|
2018-08-06 08:24:59 -07:00
|
|
|
|
2018-06-20 15:19:53 -05:00
|
|
|
/**
|
|
|
|
|
* Submits the settings related to device selection.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} newState - The new settings.
|
2022-05-24 14:04:21 -05:00
|
|
|
* @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
|
|
|
|
|
* welcome page or not.
|
2018-06-20 15:19:53 -05:00
|
|
|
* @returns {Function}
|
|
|
|
|
*/
|
2022-10-13 11:26:28 +03:00
|
|
|
export function submitDeviceSelectionTab(newState: any, isDisplayedOnWelcomePage: boolean) {
|
|
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2022-05-24 14:04:21 -05:00
|
|
|
const currentState = getDeviceSelectionDialogProps(getState(), isDisplayedOnWelcomePage);
|
2018-06-20 15:19:53 -05:00
|
|
|
|
2022-05-23 13:47:07 -05:00
|
|
|
if (newState.selectedVideoInputId && (newState.selectedVideoInputId !== currentState.selectedVideoInputId)) {
|
2018-08-06 08:24:59 -07:00
|
|
|
dispatch(updateSettings({
|
2019-05-07 09:53:01 +01:00
|
|
|
userSelectedCameraDeviceId: newState.selectedVideoInputId,
|
|
|
|
|
userSelectedCameraDeviceLabel:
|
|
|
|
|
getDeviceLabelById(getState(), newState.selectedVideoInputId, 'videoInput')
|
2018-08-06 08:24:59 -07:00
|
|
|
}));
|
|
|
|
|
|
2022-04-25 15:01:10 -04:00
|
|
|
dispatch(setVideoInputDevice(newState.selectedVideoInputId));
|
2018-06-20 15:19:53 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-23 13:47:07 -05:00
|
|
|
if (newState.selectedAudioInputId && newState.selectedAudioInputId !== currentState.selectedAudioInputId) {
|
2018-08-06 08:24:59 -07:00
|
|
|
dispatch(updateSettings({
|
2019-05-07 09:53:01 +01:00
|
|
|
userSelectedMicDeviceId: newState.selectedAudioInputId,
|
|
|
|
|
userSelectedMicDeviceLabel:
|
|
|
|
|
getDeviceLabelById(getState(), newState.selectedAudioInputId, 'audioInput')
|
2018-08-06 08:24:59 -07:00
|
|
|
}));
|
|
|
|
|
|
2022-04-25 15:01:10 -04:00
|
|
|
dispatch(setAudioInputDevice(newState.selectedAudioInputId));
|
2018-06-20 15:19:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newState.selectedAudioOutputId
|
|
|
|
|
&& newState.selectedAudioOutputId
|
|
|
|
|
!== currentState.selectedAudioOutputId) {
|
2018-08-06 08:24:59 -07:00
|
|
|
sendAnalytics(createDeviceChangedEvent('audio', 'output'));
|
|
|
|
|
|
|
|
|
|
setAudioOutputDeviceId(
|
|
|
|
|
newState.selectedAudioOutputId,
|
2019-05-01 15:13:25 +01:00
|
|
|
dispatch,
|
2019-05-07 09:53:01 +01:00
|
|
|
true,
|
|
|
|
|
getDeviceLabelById(getState(), newState.selectedAudioOutputId, 'audioOutput'))
|
2018-08-06 08:24:59 -07: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 15:19:53 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|