From 6cfa44c4f1b54615b72fa571dfc11b0ac41cc01e Mon Sep 17 00:00:00 2001 From: CSantosM <4a.santos@gmail.com> Date: Thu, 22 Jan 2026 19:35:22 +0100 Subject: [PATCH] ov-components: Refactors Firefox background processor handling Simplifies the logic for attaching and detaching the background processor in Firefox. Ensures the processor is stopped when background effects are disabled, optimizing performance. --- .../lib/services/openvidu/openvidu.service.ts | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/openvidu/openvidu.service.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/openvidu/openvidu.service.ts index 1a19e3d09..df538b18d 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/openvidu/openvidu.service.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/openvidu/openvidu.service.ts @@ -286,21 +286,37 @@ export class OpenViduService { */ async switchBackgroundMode(options: SwitchBackgroundProcessorOptions): Promise { // For Firefox, attach processor only when an effect is activated - if (this.platformService.isFirefox() && options.mode !== 'disabled') { - const videoTrack = await this.getVideoTrack(); - if (videoTrack) { - const hasProcessor = videoTrack.getProcessor(); - if (!hasProcessor) { - this.log.d('Firefox: Attaching processor on effect activation'); - await videoTrack.setProcessor(this.backgroundProcessor); - } - } + if (this.platformService.isFirefox()) { + await this.handleFirefoxProcessor(options.mode); } await this.backgroundProcessor.switchTo(options); this.log.d('Background mode switched:', options); } + /** + * Applies the background processor handling for Firefox browser. + * @internal + */ + private async handleFirefoxProcessor(mode: SwitchBackgroundProcessorOptions['mode']): Promise { + const videoTrack = await this.getVideoTrack(); + if (!videoTrack) return; + + const hasProcessor = Boolean(videoTrack.getProcessor()); + const isDisabled = mode === 'disabled'; + + if (!isDisabled && !hasProcessor) { + this.log.d('Firefox: Attaching processor on effect activation'); + await videoTrack.setProcessor(this.backgroundProcessor); + return; + } + + if (isDisabled && hasProcessor) { + this.log.d('Firefox: Stopping processor on effect deactivation'); + await videoTrack.stopProcessor(); + } + } + /** * @internal **/ @@ -377,7 +393,7 @@ export class OpenViduService { // For Firefox: skip processor attachment to avoid performance issues (applied only when effect is activated) // For other browsers: attach processor for smooth transitions const videoTrack = newLocalTracks.find((t) => t.kind === Track.Kind.Video) as LocalVideoTrack | undefined; - debugger + debugger; if (videoTrack && !this.platformService.isFirefox()) { await videoTrack.setProcessor(this.backgroundProcessor); this.log.d('Background processor applied to newly created video track');