openvidu-components: Fixed race condition with session initialization

When prejoin component is disabled, the Session component was initialized before the videoconference component initialization had finished
pull/743/head
csantosm 2022-07-06 00:02:48 +02:00
parent 25972260ac
commit 95e5e977da
2 changed files with 8 additions and 8 deletions

View File

@ -15,7 +15,7 @@
</div> </div>
<div [@inOutAnimation] id="session-container" *ngIf="showVideoconference || (!showPrejoin && !loading && !error)"> <div [@inOutAnimation] id="session-container" *ngIf="showVideoconference || (!showPrejoin && !loading && !error)">
<ov-session (onSessionCreated)="_onSessionCreated($event)"> <ov-session (onSessionCreated)="_onSessionCreated($event)" *ngIf="isSessionInitialized">
<ng-template #toolbar> <ng-template #toolbar>
<ng-container *ngIf="openviduAngularToolbarTemplate"> <ng-container *ngIf="openviduAngularToolbarTemplate">
<ng-container *ngTemplateOutlet="openviduAngularToolbarTemplate"></ng-container> <ng-container *ngTemplateOutlet="openviduAngularToolbarTemplate"></ng-container>

View File

@ -401,6 +401,11 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni
*/ */
showPrejoin: boolean = true; showPrejoin: boolean = true;
/**
* @internal
*/
isSessionInitialized: boolean = false;
/** /**
* @internal * @internal
*/ */
@ -431,17 +436,12 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni
this.subscribeToVideconferenceDirectives(); this.subscribeToVideconferenceDirectives();
await this.deviceSrv.forceInitDevices(); await this.deviceSrv.forceInitDevices();
const nickname = this.externalParticipantName || this.storageSrv.getNickname() || `OpenVidu_User${Math.floor(Math.random() * 100)}`; const nickname = this.externalParticipantName || this.storageSrv.getNickname() || `OpenVidu_User${Math.floor(Math.random() * 100)}`;
const props: ParticipantProperties = { this.participantService.initLocalParticipant({local: true, nickname});
local: true,
nickname
};
this.participantService.initLocalParticipant(props);
this.openviduService.initialize(); this.openviduService.initialize();
if (this.deviceSrv.hasVideoDeviceAvailable() || this.deviceSrv.hasAudioDeviceAvailable()) { if (this.deviceSrv.hasVideoDeviceAvailable() || this.deviceSrv.hasAudioDeviceAvailable()) {
await this.initwebcamPublisher(); await this.initwebcamPublisher();
} }
this.isSessionInitialized = true;
this.onParticipantCreated.emit(this.participantService.getLocalParticipant()); this.onParticipantCreated.emit(this.participantService.getLocalParticipant());
} }