2022-04-29 11:41:43 +02:00
|
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
2022-04-28 13:01:34 +02:00
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { BackgroundEffect, EffectType } from '../../../models/background-effect.model';
|
2022-04-25 16:17:32 +02:00
|
|
|
import { PanelType } from '../../../models/panel.model';
|
|
|
|
import { PanelService } from '../../../services/panel/panel.service';
|
2022-04-28 13:01:34 +02:00
|
|
|
import { VirtualBackgroundService } from '../../../services/virtual-background/virtual-background.service';
|
2022-04-25 16:17:32 +02:00
|
|
|
|
|
|
|
@Component({
|
2022-05-05 18:07:33 +02:00
|
|
|
selector: 'ov-background-effects-panel',
|
|
|
|
templateUrl: './background-effects-panel.component.html',
|
2022-05-12 11:32:36 +02:00
|
|
|
styleUrls: ['../panel.component.css','./background-effects-panel.component.css'],
|
2022-05-05 18:07:33 +02:00
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2022-04-25 16:17:32 +02:00
|
|
|
})
|
|
|
|
export class BackgroundEffectsPanelComponent implements OnInit {
|
|
|
|
|
2022-04-28 13:01:34 +02:00
|
|
|
backgroundSelectedId: string;
|
2022-05-05 18:07:33 +02:00
|
|
|
backgroundImages: BackgroundEffect[] = [];
|
2022-04-28 13:01:34 +02:00
|
|
|
noEffectAndBlurredBackground: BackgroundEffect[] = [];
|
|
|
|
private backgrounds: BackgroundEffect[];
|
|
|
|
private backgroundSubs: Subscription;
|
2022-04-25 16:17:32 +02:00
|
|
|
|
2022-05-05 18:07:33 +02:00
|
|
|
constructor(private panelService: PanelService, private backgroundService: VirtualBackgroundService, private cd: ChangeDetectorRef) { }
|
2022-04-25 16:17:32 +02:00
|
|
|
|
2022-05-05 18:07:33 +02:00
|
|
|
ngOnInit(): void {
|
2022-04-28 13:01:34 +02:00
|
|
|
this.subscribeToBackgroundSelected();
|
|
|
|
this.backgrounds = this.backgroundService.getBackgrounds();
|
|
|
|
this.noEffectAndBlurredBackground = this.backgrounds.filter(f => f.type === EffectType.BLUR || f.type === EffectType.NONE);
|
|
|
|
this.backgroundImages = this.backgrounds.filter(f => f.type === EffectType.IMAGE);
|
2022-04-25 16:17:32 +02:00
|
|
|
}
|
|
|
|
|
2022-04-28 13:01:34 +02:00
|
|
|
ngOnDestroy() {
|
2022-05-05 18:07:33 +02:00
|
|
|
if (this.backgroundSubs) this.backgroundSubs.unsubscribe();
|
2022-04-28 13:01:34 +02:00
|
|
|
}
|
|
|
|
subscribeToBackgroundSelected() {
|
2022-04-29 11:41:43 +02:00
|
|
|
this.backgroundSubs = this.backgroundService.backgroundSelectedObs.subscribe((id) => {
|
|
|
|
this.backgroundSelectedId = id;
|
|
|
|
this.cd.markForCheck();
|
|
|
|
});
|
2022-04-28 13:01:34 +02:00
|
|
|
}
|
|
|
|
|
2022-05-05 18:07:33 +02:00
|
|
|
close() {
|
|
|
|
this.panelService.togglePanel(PanelType.BACKGROUND_EFFECTS);
|
|
|
|
}
|
2022-04-25 16:17:32 +02:00
|
|
|
|
2022-04-28 13:01:34 +02:00
|
|
|
async applyBackground(effect: BackgroundEffect) {
|
2022-05-05 18:07:33 +02:00
|
|
|
if (effect.type === EffectType.NONE) {
|
2022-04-28 13:01:34 +02:00
|
|
|
await this.removeBackground();
|
|
|
|
} else {
|
|
|
|
await this.backgroundService.applyBackground(effect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeBackground() {
|
|
|
|
await this.backgroundService.removeBackground();
|
|
|
|
}
|
2022-04-25 16:17:32 +02:00
|
|
|
}
|