fix(trackOpQueue):setEffect &_turnScreenSharingOff

This commit is contained in:
Hristo Terezov 2022-12-12 15:53:18 -06:00
parent 1e2f9160b5
commit 61d483ce1a
4 changed files with 81 additions and 62 deletions

View File

@ -1558,45 +1558,48 @@ export default {
const tracks = APP.store.getState()['features/base/tracks'];
const duration = getLocalVideoTrack(tracks)?.jitsiTrack.getDuration() ?? 0;
// If system audio was also shared stop the AudioMixerEffect and dispose of the desktop audio track.
if (this._mixerEffect) {
const localAudio = getLocalJitsiAudioTrack(APP.store.getState());
APP.store.dispatch(executeTrackOperation(TrackOperationType.Audio, async () => {
// If system audio was also shared stop the AudioMixerEffect and dispose of the desktop audio track.
if (this._mixerEffect) {
const localAudio = getLocalJitsiAudioTrack(APP.store.getState());
await localAudio.setEffect(undefined);
await this._desktopAudioStream.dispose();
this._mixerEffect = undefined;
this._desktopAudioStream = undefined;
await localAudio.setEffect(undefined);
await this._desktopAudioStream.dispose();
this._mixerEffect = undefined;
this._desktopAudioStream = undefined;
// In case there was no local audio when screen sharing was started the fact that we set the audio stream to
// null will take care of the desktop audio stream cleanup.
} else if (this._desktopAudioStream) {
await room.replaceTrack(this._desktopAudioStream, null);
this._desktopAudioStream.dispose();
this._desktopAudioStream = undefined;
}
// In case there was no local audio when screen sharing was started the fact that we set the audio stream to
// null will take care of the desktop audio stream cleanup.
} else if (this._desktopAudioStream) {
await room.replaceTrack(this._desktopAudioStream, null);
this._desktopAudioStream.dispose();
this._desktopAudioStream = undefined;
}
APP.store.dispatch(setScreenAudioShareState(false));
let promise;
APP.store.dispatch(setScreenAudioShareState(false));
}));
if (didHaveVideo && !ignoreDidHaveVideo) {
promise = createLocalTracksF({ devices: [ 'video' ] })
.then(([ stream ]) => {
logger.debug(`_turnScreenSharingOff using ${stream} for useVideoStream`);
const promise = APP.store.dispatch(executeTrackOperation(TrackOperationType.Video, () => {
if (didHaveVideo && !ignoreDidHaveVideo) {
return createLocalTracksF({ devices: [ 'video' ] })
.then(([ stream ]) => {
logger.debug(`_turnScreenSharingOff using ${stream} for useVideoStream`);
return this.useVideoStream(stream);
})
.catch(error => {
logger.error('failed to switch back to local video', error);
return this.useVideoStream(stream);
})
.catch(error => {
logger.error('failed to switch back to local video', error);
return this.useVideoStream(null).then(() =>
return this.useVideoStream(null).then(() =>
// Still fail with the original err
Promise.reject(error)
);
});
} else {
promise = this.useVideoStream(null);
}
// Still fail with the original err
Promise.reject(error)
);
});
}
return this.useVideoStream(null);
}));
return promise.then(
() => {

View File

@ -1,5 +1,7 @@
import { IStore } from '../app/types';
import { executeTrackOperation } from '../base/tracks/actions';
import { getLocalJitsiAudioTrack } from '../base/tracks/functions';
import { TrackOperationType } from '../base/tracks/types';
import { showErrorNotification } from '../notifications/actions';
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
import { NoiseSuppressionEffect } from '../stream-effects/noise-suppression/NoiseSuppressionEffect';
@ -48,30 +50,32 @@ export function toggleNoiseSuppression(): any {
*/
export function setNoiseSuppressionEnabled(enabled: boolean): any {
return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
const state = getState();
const localAudio = getLocalJitsiAudioTrack(state);
const noiseSuppressionEnabled = isNoiseSuppressionEnabled(state);
logger.info(`Attempting to set noise suppression enabled state: ${enabled}`);
try {
if (enabled && !noiseSuppressionEnabled) {
if (!canEnableNoiseSuppression(state, dispatch, localAudio)) {
return;
await dispatch(executeTrackOperation(TrackOperationType.Audio, async () => {
const state = getState();
const localAudio = getLocalJitsiAudioTrack(state);
const noiseSuppressionEnabled = isNoiseSuppressionEnabled(state);
if (enabled && !noiseSuppressionEnabled) {
if (!canEnableNoiseSuppression(state, dispatch, localAudio)) {
return;
}
await localAudio.setEffect(new NoiseSuppressionEffect());
dispatch(setNoiseSuppressionEnabledState(true));
logger.info('Noise suppression enabled.');
} else if (!enabled && noiseSuppressionEnabled) {
await localAudio.setEffect(undefined);
dispatch(setNoiseSuppressionEnabledState(false));
logger.info('Noise suppression disabled.');
} else {
logger.warn(`Noise suppression enabled state already: ${enabled}`);
}
await localAudio.setEffect(new NoiseSuppressionEffect());
dispatch(setNoiseSuppressionEnabledState(true));
logger.info('Noise suppression enabled.');
} else if (!enabled && noiseSuppressionEnabled) {
await localAudio.setEffect(undefined);
dispatch(setNoiseSuppressionEnabledState(false));
logger.info('Noise suppression disabled.');
} else {
logger.warn(`Noise suppression enabled state already: ${enabled}`);
}
}));
} catch (error) {
logger.error(
`Failed to set noise suppression enabled to: ${enabled}`,

View File

@ -1,4 +1,7 @@
import { IStore } from '../app/types';
import { executeTrackOperation } from '../base/tracks/actions';
import { getLocalJitsiVideoTrack } from '../base/tracks/functions.any';
import { TrackOperationType } from '../base/tracks/types';
// eslint-disable-next-line lines-around-comment
// @ts-ignore
import { createVirtualBackgroundEffect } from '../stream-effects/virtual-background';
@ -37,6 +40,23 @@ export function toggleBackgroundEffect(options: IVirtualBackgroundOptions, jitsi
};
}
/**
* Adds a track operation to enable/disable the virtual background for the local video.
*
* @param {Object} options - Represents the virtual background set options.
* @returns {Function}
*/
export function toggleBackgroundEffectForTheLocalTrack(options: IVirtualBackgroundOptions) {
return function(dispatch: IStore['dispatch'], getState: IStore['getState']) {
return dispatch(executeTrackOperation(TrackOperationType.Video, () => {
const localVideo = getLocalJitsiVideoTrack(getState());
return dispatch(toggleBackgroundEffect(options, localVideo));
}));
};
}
/**
* Sets the selected virtual background image object.
*

View File

@ -18,9 +18,8 @@ import { connect } from '../../base/redux/functions';
import { updateSettings } from '../../base/settings/actions';
// @ts-ignore
import { Tooltip } from '../../base/tooltip';
import { getLocalVideoTrack } from '../../base/tracks/functions';
import Dialog from '../../base/ui/components/web/Dialog';
import { toggleBackgroundEffect } from '../actions';
import { toggleBackgroundEffectForTheLocalTrack } from '../actions';
import { BACKGROUNDS_LIMIT, IMAGES, type Image, VIRTUAL_BACKGROUND_TYPE } from '../constants';
import { toDataURL } from '../functions';
import logger from '../logger';
@ -36,11 +35,6 @@ interface IProps extends WithTranslation {
*/
_images: Array<Image>;
/**
* Returns the jitsi track that will have backgraund effect applied.
*/
_jitsiTrack: Object;
/**
* The current local flip x status.
*/
@ -104,7 +98,6 @@ function _mapStateToProps(state: IReduxState): Object {
_virtualBackground: state['features/virtual-background'],
_selectedThumbnail: state['features/virtual-background'].selectedThumbnail,
_showUploadButton: !(hasBrandingImages || state['features/base/config'].disableAddingBackgroundImages),
_jitsiTrack: getLocalVideoTrack(state['features/base/tracks'])?.jitsiTrack,
_multiStreamModeEnabled: getMultipleVideoSendingSupportFeatureFlag(state)
};
}
@ -272,7 +265,6 @@ const useStyles = makeStyles()(theme => {
*/
function VirtualBackground({
_images,
_jitsiTrack,
_localFlipX,
_selectedThumbnail,
_showUploadButton,
@ -422,7 +414,7 @@ function VirtualBackground({
const applyVirtualBackground = useCallback(async () => {
setLoading(true);
await dispatch(toggleBackgroundEffect(options, _jitsiTrack));
await dispatch(toggleBackgroundEffectForTheLocalTrack(options));
await setLoading(false);
// Set x scale to default value.