Skip to content

Commit

Permalink
fix: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed May 22, 2024
1 parent ef67d76 commit 417ae9d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 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 @@ -140,15 +142,17 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin {
};
this.effects.clear();
const { height, width } = stream.getVideoTracks()[0].getSettings();
const canvas = document.createElement('canvas');
canvas.width = width!;
canvas.height = height!;
this.canvas.width = width!;
this.canvas.height = height!;
this.effects.useStream(stream);
this.effects.toCanvas(canvas);
return canvas.captureStream(30) || stream;
this.effects.toCanvas(this.canvas);
return this.canvas.captureStream(30) || stream;
}

stop() {
if (this.canvas && this.canvas.parentNode) {
this.canvas.parentNode.removeChild(this.canvas);
}
this.removeEffects();
this.executeAfterInit(() => {
this.effects.stop();
Expand Down

0 comments on commit 417ae9d

Please sign in to comment.