Skip to content

Commit

Permalink
fix: add optimisations for HMSEffectsPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed Jan 27, 2025
1 parent 09377a5 commit 1823e5b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/hms-virtual-background/src/HMSEffectsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin {
if (this.effects) {
this.initialised = true;
this.onInit?.();
this.effects.run();
this.effects.setBackgroundFitMode('fill');
this.effects.setSegmentationPreset(this.preset);
this.applyEffect();
if (
this.background !== HMSVirtualBackgroundTypes.NONE &&
this.backgroundType !== HMSVirtualBackgroundTypes.NONE
) {
this.effects.run();
this.effects.setBackgroundFitMode('fill');
this.effects.setSegmentationPreset(this.preset);
this.applyEffect();
}
}
};
}
Expand Down Expand Up @@ -95,6 +100,7 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin {
this.backgroundType = HMSVirtualBackgroundTypes.BLUR;
this.removeBackground();
this.executeAfterInit(() => {
this.effects.run();
this.effects.setBlur(this.blurAmount);
});
}
Expand Down Expand Up @@ -123,13 +129,17 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin {
this.backgroundType = HMSVirtualBackgroundTypes.NONE;
this.removeBackground();
this.removeBlur();
this.executeAfterInit(() => {
this.effects.stop();
});
}

setBackground(url: HMSEffectsBackground) {
this.background = url;
this.backgroundType = HMSVirtualBackgroundTypes.IMAGE;
this.removeBlur();
this.executeAfterInit(() => {
this.effects.run();
this.effects.setBackground(this.background);
});
}
Expand Down Expand Up @@ -164,9 +174,6 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin {

stop() {
this.removeEffects();
this.executeAfterInit(() => {
this.effects.stop();
});
}

private applyEffect() {
Expand Down

0 comments on commit 1823e5b

Please sign in to comment.