diff --git a/conference.js b/conference.js index 4af2765d6c202..65b540ff792f3 100644 --- a/conference.js +++ b/conference.js @@ -165,6 +165,7 @@ import { AudioMixerEffect } from './react/features/stream-effects/audio-mixer/Au import { createRnnoiseProcessor } from './react/features/stream-effects/rnnoise'; import { handleToggleVideoMuted } from './react/features/toolbox/actions.any'; import { muteLocal } from './react/features/video-menu/actions.any'; +import { toggleBlurredBackgroundEffect } from './react/features/virtual-background/actions'; const logger = Logger.getLogger(__filename); let room; @@ -874,6 +875,18 @@ export default { APP.store.dispatch(handleToggleVideoMuted(mute, showUI, ensureTrack)); }, + /** + * Simulates blurred background selection/removal on video background. Used by API only. + * @param {string} [blurType] Blur type to apply. Accepted values are 'slight-blur', 'blur' or 'none' + */ + setBlurredBackground(blurType) { + const tracks = APP.store.getState()['features/base/tracks']; + const videoTrack = getLocalVideoTrack(tracks)?.jitsiTrack; + const muted = this.isLocalVideoMuted(); + + APP.store.dispatch(toggleBlurredBackgroundEffect(videoTrack, blurType, muted)); + }, + /** * Retrieve list of ids of conference participants (without local user). * @returns {string[]} diff --git a/modules/API/API.js b/modules/API/API.js index 10a7c8a1fd14a..4efe8b9d24464 100644 --- a/modules/API/API.js +++ b/modules/API/API.js @@ -322,6 +322,9 @@ function initCommands() { APP.store.dispatch(setAssumedBandwidthBps(value)); }, + 'set-blurred-background': blurType => { + APP.conference.setBlurredBackground(blurType); + }, 'set-follow-me': value => { if (value) { diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js index 01f4631356e06..5f1dc8127a33e 100644 --- a/modules/API/external/external_api.js +++ b/modules/API/external/external_api.js @@ -60,6 +60,7 @@ const commands = { sendParticipantToRoom: 'send-participant-to-room', sendTones: 'send-tones', setAssumedBandwidthBps: 'set-assumed-bandwidth-bps', + setBlurredBackground: 'set-blurred-background', setFollowMe: 'set-follow-me', setLargeVideoParticipant: 'set-large-video-participant', setMediaEncryptionKey: 'set-media-encryption-key', diff --git a/react/features/virtual-background/actions.ts b/react/features/virtual-background/actions.ts index 1a671a263f5db..de8b48d073786 100644 --- a/react/features/virtual-background/actions.ts +++ b/react/features/virtual-background/actions.ts @@ -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)); + } + }; +}