2018-08-06 15:24:59 +00:00
|
|
|
import { createDeviceChangedEvent, sendAnalytics } from '../analytics';
|
2018-04-12 19:58:20 +00:00
|
|
|
import {
|
2019-05-07 08:53:01 +00:00
|
|
|
getDeviceLabelById,
|
2017-06-04 03:12:04 +00:00
|
|
|
setAudioInputDevice,
|
2018-08-06 15:24:59 +00:00
|
|
|
setAudioOutputDeviceId,
|
2017-06-04 03:12:04 +00:00
|
|
|
setVideoInputDevice
|
|
|
|
} from '../base/devices';
|
2022-04-25 19:01:10 +00:00
|
|
|
import { isIosMobileBrowser } from '../base/environment/utils';
|
|
|
|
import { browser } from '../base/lib-jitsi-meet';
|
2018-08-06 15:24:59 +00:00
|
|
|
import { updateSettings } from '../base/settings';
|
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.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function submitDeviceSelectionTab(newState) {
|
2022-04-25 19:01:10 +00:00
|
|
|
// Always use the new track for mobile Safari because of https://bugs.webkit.org/show_bug.cgi?id=179363#c30. The
|
|
|
|
// old track is stopped by the browser when a new track is created for preview so it needs to be replaced even if
|
|
|
|
// the device selection doesn't change.
|
|
|
|
const replaceTrackAlways = isIosMobileBrowser() && browser.isVersionGreaterThan('15.3');
|
|
|
|
|
2018-06-20 20:19:53 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
const currentState = getDeviceSelectionDialogProps(getState());
|
|
|
|
|
2022-04-25 19:01:10 +00:00
|
|
|
if ((newState.selectedVideoInputId && (newState.selectedVideoInputId !== currentState.selectedVideoInputId))
|
|
|
|
|| replaceTrackAlways) {
|
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-04-25 19:01:10 +00:00
|
|
|
if ((newState.selectedAudioInputId && newState.selectedAudioInputId !== currentState.selectedAudioInputId)
|
|
|
|
|| replaceTrackAlways) {
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|