ov-components: optimize participant name subscription with filter and tap operators

master
Carlos Santos 2025-07-29 15:46:05 +02:00
parent 76c957903f
commit 7bf0e0036c
1 changed files with 8 additions and 7 deletions

View File

@ -9,7 +9,7 @@ import {
OnInit, OnInit,
Output Output
} from '@angular/core'; } from '@angular/core';
import { Subject, takeUntil } from 'rxjs'; import { filter, Subject, takeUntil, tap } from 'rxjs';
import { ILogger } from '../../models/logger.model'; import { ILogger } from '../../models/logger.model';
import { CdkOverlayService } from '../../services/cdk-overlay/cdk-overlay.service'; import { CdkOverlayService } from '../../services/cdk-overlay/cdk-overlay.service';
import { OpenViduComponentsConfigService } from '../../services/config/directive-config.service'; import { OpenViduComponentsConfigService } from '../../services/config/directive-config.service';
@ -138,12 +138,13 @@ export class PreJoinComponent implements OnInit, OnDestroy {
// Wait for the next tick to ensure the participant name propagates // Wait for the next tick to ensure the participant name propagates
// through the observable before emitting onReadyToJoin // through the observable before emitting onReadyToJoin
const sub = this.libService.participantName$.pipe(takeUntil(this.destroy$)).subscribe((name) => { this.libService.participantName$
if (name === this.participantName) { .pipe(
this.onReadyToJoin.emit(); takeUntil(this.destroy$),
sub.unsubscribe(); filter((name) => name === this.participantName),
} tap(() => this.onReadyToJoin.emit())
}); )
.subscribe();
} else { } else {
// No participant name to set, emit immediately // No participant name to set, emit immediately
this.onReadyToJoin.emit(); this.onReadyToJoin.emit();