mirror of https://github.com/OpenVidu/openvidu.git
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.master
parent
465403f8cb
commit
6cfa44c4f1
|
|
@ -286,21 +286,37 @@ export class OpenViduService {
|
||||||
*/
|
*/
|
||||||
async switchBackgroundMode(options: SwitchBackgroundProcessorOptions): Promise<void> {
|
async switchBackgroundMode(options: SwitchBackgroundProcessorOptions): Promise<void> {
|
||||||
// For Firefox, attach processor only when an effect is activated
|
// For Firefox, attach processor only when an effect is activated
|
||||||
if (this.platformService.isFirefox() && options.mode !== 'disabled') {
|
if (this.platformService.isFirefox()) {
|
||||||
const videoTrack = await this.getVideoTrack();
|
await this.handleFirefoxProcessor(options.mode);
|
||||||
if (videoTrack) {
|
|
||||||
const hasProcessor = videoTrack.getProcessor();
|
|
||||||
if (!hasProcessor) {
|
|
||||||
this.log.d('Firefox: Attaching processor on effect activation');
|
|
||||||
await videoTrack.setProcessor(this.backgroundProcessor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.backgroundProcessor.switchTo(options);
|
await this.backgroundProcessor.switchTo(options);
|
||||||
this.log.d('Background mode switched:', options);
|
this.log.d('Background mode switched:', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the background processor handling for Firefox browser.
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
private async handleFirefoxProcessor(mode: SwitchBackgroundProcessorOptions['mode']): Promise<void> {
|
||||||
|
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
|
* @internal
|
||||||
**/
|
**/
|
||||||
|
|
@ -377,7 +393,7 @@ export class OpenViduService {
|
||||||
// For Firefox: skip processor attachment to avoid performance issues (applied only when effect is activated)
|
// For Firefox: skip processor attachment to avoid performance issues (applied only when effect is activated)
|
||||||
// For other browsers: attach processor for smooth transitions
|
// For other browsers: attach processor for smooth transitions
|
||||||
const videoTrack = newLocalTracks.find((t) => t.kind === Track.Kind.Video) as LocalVideoTrack | undefined;
|
const videoTrack = newLocalTracks.find((t) => t.kind === Track.Kind.Video) as LocalVideoTrack | undefined;
|
||||||
debugger
|
debugger;
|
||||||
if (videoTrack && !this.platformService.isFirefox()) {
|
if (videoTrack && !this.platformService.isFirefox()) {
|
||||||
await videoTrack.setProcessor(this.backgroundProcessor);
|
await videoTrack.setProcessor(this.backgroundProcessor);
|
||||||
this.log.d('Background processor applied to newly created video track');
|
this.log.d('Background processor applied to newly created video track');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue