From 43522eff50f3e7c6d46eb92df27eea7793679570 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 3 Jul 2024 08:40:27 -0300 Subject: [PATCH] fix: retrieve user list from store to validade if room has host --- src/components/video/index.test.ts | 2 +- src/components/video/index.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/video/index.test.ts b/src/components/video/index.test.ts index b398a6c1..cb174d09 100644 --- a/src/components/video/index.test.ts +++ b/src/components/video/index.test.ts @@ -235,7 +235,7 @@ describe('VideoConference', () => { VideoConferenceInstance['onRealtimeParticipantsDidChange'](secondList); - expect(VideoConferenceInstance['roomState'].setHost).toHaveBeenCalledTimes(1); + expect(VideoConferenceInstance['roomState'].setHost).toHaveBeenCalledTimes(0); }); test('should not set host if the participant is not me', () => { diff --git a/src/components/video/index.ts b/src/components/video/index.ts index 6061541b..75e81f46 100644 --- a/src/components/video/index.ts +++ b/src/components/video/index.ts @@ -814,9 +814,15 @@ export class VideoConference extends BaseComponent { if (!this.roomState) return; const { hostId } = this.useStore(StoreType.VIDEO); + const { participants } = this.useStore(StoreType.GLOBAL); + const participantsList = Object.values(participants.value); - const participantsCanBeHost = this.participantsOnMeeting.filter((participant) => { - return participant.type === ParticipantType.HOST; + // list with all participants that have the type host and are in the meeting + const participantsCanBeHost = participantsList.filter((participant) => { + return ( + participant.type === ParticipantType.HOST && + this.participantsOnMeeting.some((p) => p.id === participant.id) + ); }); if ( @@ -848,7 +854,7 @@ export class VideoConference extends BaseComponent { this.onHostAvailabilityChange(!!participantsCanBeHost.length); - const hostAlreadyInRoom = participantsCanBeHost.find( + const hostAlreadyInRoom = participantsList.find( (participant) => participant?.id === hostId?.value, );