VIDEO-6368 | wait to load image before removing processor#570
VIDEO-6368 | wait to load image before removing processor#570gabriel-jt merged 2 commits intofeature/virtualbackgroundfrom
Conversation
charliesantos
left a comment
There was a problem hiding this comment.
Your changes works! However, it's not immediately obvious what the code is trying to do. What do you think of my suggestion below? Basically, I created addProcessor and removeProcessor helper functions and just use those. It reduces the nested if statements, and also prevents removing and adding processors if the processor hasn't changed.
Helper functions outside of your useEffect hook
const removeProcessor = () => {
if (videoTrack && videoTrack.processor) {
videoTrack.removeProcessor(videoTrack.processor);
}
};
const addProcessor = (processor: GaussianBlurBackgroundProcessor | VirtualBackgroundProcessor) => {
if (!videoTrack || videoTrack.processor === processor) {
return;
}
removeProcessor();
videoTrack.addProcessor(processor);
};Handler now looks like this
const handleProcessorChange = async () => {
if (!blurProcessor) {
blurProcessor = new GaussianBlurBackgroundProcessor({
assetsPath: virtualBackgroundAssets,
});
await blurProcessor.loadModel();
}
if (!virtualBackgroundProcessor) {
virtualBackgroundProcessor = new VirtualBackgroundProcessor({
assetsPath: virtualBackgroundAssets,
backgroundImage: await getImage(0),
fitType: ImageFit.Cover,
});
await virtualBackgroundProcessor.loadModel();
}
if (!room?.localParticipant) {
return;
}
if (backgroundSettings.type === 'blur') {
addProcessor(blurProcessor);
} else if (backgroundSettings.type === 'image' && typeof backgroundSettings.index === 'number') {
virtualBackgroundProcessor.backgroundImage = await getImage(backgroundSettings.index);
addProcessor(virtualBackgroundProcessor);
} else {
removeProcessor();
}
};
Thanks for the suggestions @charliesantos ! I wrapped the helper functions inside a |
timmydoza
left a comment
There was a problem hiding this comment.
Nice work! I used Chrome's dev tools to throttle my network connection so the background images loaded slowly, and the changes here worked well. 👍
* Moved more menu to the center of the menu bar * VIDEO-5731 | Added background option to More Menu, selection dialog, and unit tests (#6) Added background option to More Menu, selection dialog, and unit tests Co-authored-by: Gabe Espinosa <gespinosa@twilio.com> * VIDEO-5733 | Added npm script to copy video processor sdk assets to public folder (#8) * Added npm script to copy video processor sdk assets to public folder * added postinstall npm script Co-authored-by: Gabe Espinosa <gespinosa@twilio.com> * added rimraf and copyfiles dependency to package.json * VIDEO-5732 | Added background selection UI (#7) Added background selection UI Co-authored-by: Gabe Espinosa <gespinosa@twilio.com> Co-authored-by: timmydoza <tmendoza@twilio.com> * VIDEO-5734/blur background feature (#550) Implemented blur background feature (useBackgroundSettings hook and tests) Co-authored-by: Gabe Espinosa <gespinosa@twilio.com> * VIDEO-5735/Add virtual background feature (#557) Added virtual background feature and unit tests Co-authored-by: Gabe Espinosa <gespinosa@twilio.com> * VIDEO-5735 | Add isSupported check and unit test (#560) add isSupported check and unit test Co-authored-by: Gabe Espinosa <gespinosa@twilio.com> * VIDEO-6368 | wait to load image before removing processor (#570) * wait to load image before removing processor Co-authored-by: Gabe Espinosa <gespinosa@twilio.com> * updated twilio-video sdk * fixed breaking tests * update package.json version and changelog * update change log, package.json, and revisions * Update CHANGELOG.md Co-authored-by: Gabe Espinosa <gespinosa@twilio.com> Co-authored-by: timmydoza <tmendoza@twilio.com>
Contributing to Twilio
Pull Request Details
JIRA link(s):
Description
Wait to load images for virtual background before removing the processor
Burndown
Before review
npm testBefore merge