Skip to content

Commit

Permalink
fix: use canvas stream in effects plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 authored May 22, 2024
1 parent a1af640 commit 9605dd9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/hms-virtual-background/src/HMSEffectsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin {
private initialised = false;
private intervalId: NodeJS.Timer | null = null;
private onInit;
private canvas: HTMLCanvasElement;

constructor(effectsSDKKey: string, onInit?: () => void) {
this.effects = new tsvb(effectsSDKKey);
this.onInit = onInit;
this.canvas = document.createElement('canvas');
this.effects.config({
sdk_url: EFFECTS_SDK_ASSETS,
models: {
Expand Down Expand Up @@ -114,6 +116,7 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin {
this.effects.setBackground(this.background);
});
}

getBlurAmount() {
return this.blurAmount;
}
Expand All @@ -138,9 +141,12 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin {
}
};
this.effects.clear();
const { height, width } = stream.getVideoTracks()[0].getSettings();
this.canvas.width = width!;
this.canvas.height = height!;
this.effects.useStream(stream);
// getStream potentially returns null
return this.effects.getStream() || stream;
this.effects.toCanvas(this.canvas);
return this.canvas.captureStream(30) || stream;
}

stop() {
Expand Down

0 comments on commit 9605dd9

Please sign in to comment.