feat(external-api): Set blurred background from external api. (#15131)

Add setBlurredBackground command to external api.

Co-authored-by: Axel Prola <axel.prola@equasens.com>
This commit is contained in:
Axel Prola
2024-09-20 15:08:16 +02:00
committed by GitHub
parent 7bb2f1eaad
commit 97930bfef2
3 changed files with 47 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ import { IStore } from '../app/types';
import { createVirtualBackgroundEffect } from '../stream-effects/virtual-background';
import { BACKGROUND_ENABLED, SET_VIRTUAL_BACKGROUND } from './actionTypes';
import { VIRTUAL_BACKGROUND_TYPE } from './constants';
import logger from './logger';
import { IVirtualBackground } from './reducer';
@@ -71,3 +72,34 @@ export function backgroundEnabled(backgroundEffectEnabled?: boolean) {
backgroundEffectEnabled
};
}
/**
* Simulates blurred background selection/removal on video background. Used by API only.
*
* @param {JitsiLocalTrack} videoTrack - The targeted video track.
* @param {string} [blurType] - Blur type to apply. Accepted values are 'slight-blur', 'blur' or 'none'.
* @param {boolean} muted - Muted state of the video track.
* @returns {Promise}
*/
export function toggleBlurredBackgroundEffect(videoTrack: any, blurType: 'slight-blur' | 'blur' | 'none',
muted: boolean) {
return async function(dispatch: IStore['dispatch'], _getState: IStore['getState']) {
if (muted || !videoTrack || !blurType) {
return;
}
if (blurType === 'none') {
dispatch(toggleBackgroundEffect({
backgroundEffectEnabled: false,
selectedThumbnail: blurType
}, videoTrack));
} else {
dispatch(toggleBackgroundEffect({
backgroundEffectEnabled: true,
backgroundType: VIRTUAL_BACKGROUND_TYPE.BLUR,
blurValue: blurType === 'blur' ? 25 : 8,
selectedThumbnail: blurType
}, videoTrack));
}
};
}