mirror of https://github.com/OpenVidu/openvidu.git
ov-components: fixed race condition with onTokenRequested event and participantName
parent
1065f32a3a
commit
8a9e9e0d27
|
@ -1,6 +1,6 @@
|
||||||
import { animate, style, transition, trigger } from '@angular/animations';
|
import { animate, style, transition, trigger } from '@angular/animations';
|
||||||
import { AfterViewInit, Component, ContentChild, EventEmitter, OnDestroy, Output, TemplateRef, ViewChild } from '@angular/core';
|
import { AfterViewInit, Component, ContentChild, EventEmitter, OnDestroy, Output, TemplateRef, ViewChild } from '@angular/core';
|
||||||
import { Subscription, skip } from 'rxjs';
|
import { Subscription, filter, skip, take } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
ActivitiesPanelDirective,
|
ActivitiesPanelDirective,
|
||||||
AdditionalPanelsDirective,
|
AdditionalPanelsDirective,
|
||||||
|
@ -383,6 +383,7 @@ export class VideoconferenceComponent implements OnDestroy, AfterViewInit {
|
||||||
private tokenErrorSub: Subscription;
|
private tokenErrorSub: Subscription;
|
||||||
private participantNameSub: Subscription;
|
private participantNameSub: Subscription;
|
||||||
private log: ILogger;
|
private log: ILogger;
|
||||||
|
private latestParticipantName: string | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
@ -503,7 +504,7 @@ export class VideoconferenceComponent implements OnDestroy, AfterViewInit {
|
||||||
*/
|
*/
|
||||||
_onReadyToJoin() {
|
_onReadyToJoin() {
|
||||||
this.openviduService.initRoom();
|
this.openviduService.initRoom();
|
||||||
const participantName = this.storageSrv.getParticipantName();
|
const participantName = this.latestParticipantName;
|
||||||
if (participantName) this.onTokenRequested.emit(participantName);
|
if (participantName) this.onTokenRequested.emit(participantName);
|
||||||
// Emits onReadyToJoin event only if prejoin page has been shown
|
// Emits onReadyToJoin event only if prejoin page has been shown
|
||||||
if (this.showPrejoin) this.onReadyToJoin.emit();
|
if (this.showPrejoin) this.onReadyToJoin.emit();
|
||||||
|
@ -548,14 +549,48 @@ export class VideoconferenceComponent implements OnDestroy, AfterViewInit {
|
||||||
this.prejoinSub = this.libService.prejoin$.subscribe((value: boolean) => {
|
this.prejoinSub = this.libService.prejoin$.subscribe((value: boolean) => {
|
||||||
this.showPrejoin = value;
|
this.showPrejoin = value;
|
||||||
if (!this.showPrejoin) {
|
if (!this.showPrejoin) {
|
||||||
// Emit token ready if the prejoin page won't be shown
|
// Ensure we have a participant name before proceeding with the join
|
||||||
this._onReadyToJoin();
|
this.log.d('Prejoin page is hidden, checking participant name');
|
||||||
|
// Check if we have a participant name already
|
||||||
|
if (this.latestParticipantName) {
|
||||||
|
// We have a name, proceed immediately
|
||||||
|
this._onReadyToJoin();
|
||||||
|
} else {
|
||||||
|
// Try to get it from storage first
|
||||||
|
const storedName = this.storageSrv.getParticipantName();
|
||||||
|
if (storedName) {
|
||||||
|
this.latestParticipantName = storedName;
|
||||||
|
this._onReadyToJoin();
|
||||||
|
} else {
|
||||||
|
// No name yet - set up a one-time subscription to wait for it
|
||||||
|
const waitForNameSub = this.libService.participantName$
|
||||||
|
.pipe(
|
||||||
|
filter((name) => !!name),
|
||||||
|
take(1)
|
||||||
|
)
|
||||||
|
.subscribe(() => {
|
||||||
|
// Now we have the name in latestParticipantName
|
||||||
|
this._onReadyToJoin();
|
||||||
|
});
|
||||||
|
// Add safety timeout in case name never arrives
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!this.latestParticipantName) {
|
||||||
|
this.log.w('No participant name received after timeout, proceeding anyway');
|
||||||
|
waitForNameSub.unsubscribe();
|
||||||
|
this._onReadyToJoin();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// this.cd.markForCheck();
|
// this.cd.markForCheck();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.participantNameSub = this.libService.participantName$.subscribe((name: string) => {
|
this.participantNameSub = this.libService.participantName$.subscribe((name: string) => {
|
||||||
if (name) this.storageSrv.setParticipantName(name);
|
if (name) {
|
||||||
|
this.latestParticipantName = name;
|
||||||
|
this.storageSrv.setParticipantName(name);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue