Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(external_api) add function to toggle virtual background #15324

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion modules/API/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ import { isAudioMuteButtonDisabled } from '../../react/features/toolbox/function
import { setTileView, toggleTileView } from '../../react/features/video-layout/actions.any';
import { muteAllParticipants } from '../../react/features/video-menu/actions';
import { setVideoQuality } from '../../react/features/video-quality/actions';
import { toggleBlurredBackgroundEffect } from '../../react/features/virtual-background/actions';
import { toggleBackgroundEffect, toggleBlurredBackgroundEffect } from '../../react/features/virtual-background/actions';
import { VIRTUAL_BACKGROUND_TYPE } from '../../react/features/virtual-background/constants';
import { toggleWhiteboard } from '../../react/features/whiteboard/actions.web';
import { getJitsiMeetTransport } from '../transport';

Expand Down Expand Up @@ -871,6 +872,16 @@ function initCommands() {
},
'toggle-whiteboard': () => {
APP.store.dispatch(toggleWhiteboard());
},
'set-virtual-background': (enabled, backgroundImage) => {
const tracks = APP.store.getState()['features/base/tracks'];
const jitsiTrack = getLocalVideoTrack(tracks)?.jitsiTrack;

APP.store.dispatch(toggleBackgroundEffect({
backgroundEffectEnabled: enabled,
backgroundType: VIRTUAL_BACKGROUND_TYPE.IMAGE,
virtualSource: backgroundImage
}, jitsiTrack));
}
};
transport.on('event', ({ data, name }) => {
Expand Down
12 changes: 12 additions & 0 deletions modules/API/external/external_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const commands = {
setSubtitles: 'set-subtitles',
setTileView: 'set-tile-view',
setVideoQuality: 'set-video-quality',
setVirtualBackground: 'set-virtual-background',
showNotification: 'show-notification',
startRecording: 'start-recording',
startShareVideo: 'start-share-video',
Expand Down Expand Up @@ -1500,4 +1501,15 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
index }));
}
}

/**
* Enable or disable the virtual background with a custom base64 image.
*
* @param {boolean} enabled - The boolean value to enable or disable.
* @param {string} backgroundImage - The base64 image.
* @returns {void}
*/
setVirtualBackground(enabled, backgroundImage) {
this.executeCommand('setVirtualBackground', enabled, backgroundImage);
}
}