From 134b2592e4d268879a30acaeb6fa9b9ba3e0cef2 Mon Sep 17 00:00:00 2001 From: juancarmore Date: Wed, 13 Aug 2025 20:25:32 +0200 Subject: [PATCH] frontend: enhance participant role update handling with token refresh and error management --- .../lib/pages/meeting/meeting.component.ts | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/frontend/projects/shared-meet-components/src/lib/pages/meeting/meeting.component.ts b/frontend/projects/shared-meet-components/src/lib/pages/meeting/meeting.component.ts index 8817e61..d2af9b2 100644 --- a/frontend/projects/shared-meet-components/src/lib/pages/meeting/meeting.component.ts +++ b/frontend/projects/shared-meet-components/src/lib/pages/meeting/meeting.component.ts @@ -323,23 +323,46 @@ export class MeetingComponent implements OnInit { onRoomCreated(room: Room) { room.on( RoomEvent.DataReceived, - (payload: Uint8Array, _participant?: RemoteParticipant, _kind?: DataPacket_Kind, topic?: string) => { + async (payload: Uint8Array, _participant?: RemoteParticipant, _kind?: DataPacket_Kind, topic?: string) => { const event = JSON.parse(new TextDecoder().decode(payload)); - if (topic === MeetSignalType.MEET_ROOM_PREFERENCES_UPDATED) { - const { preferences } = event as MeetRoomPreferencesUpdatedPayload; - this.featureConfService.setRoomPreferences(preferences); - } else if (topic === MeetSignalType.MEET_PARTICIPANT_ROLE_UPDATED) { - const { participantIdentity, newRole, secret } = event as MeetParticipantRoleUpdatedPayload; + switch (topic) { + case MeetSignalType.MEET_ROOM_PREFERENCES_UPDATED: { + // Update room preferences + const { preferences } = event as MeetRoomPreferencesUpdatedPayload; + this.featureConfService.setRoomPreferences(preferences); + break; + } + case MeetSignalType.MEET_PARTICIPANT_ROLE_UPDATED: { + // Update participant role + const { participantIdentity, newRole, secret } = event as MeetParticipantRoleUpdatedPayload; - if (participantIdentity === this.localParticipant!.name) { - this.localParticipant!.meetRole = newRole; - // TODO: Request for new token with the new role - } else { - const participant = this.remoteParticipants.find((p) => p.identity === participantIdentity); - if (participant) { - participant.meetRole = newRole; + if (participantIdentity === this.localParticipant!.name) { + if (!secret) return; + + this.roomSecret = secret; + this.roomService.setRoomSecret(secret); + + try { + await this.participantService.refreshParticipantToken({ + roomId: this.roomId, + secret, + participantName: this.participantName + }); + + this.localParticipant!.meetRole = newRole; + this.notificationService.showSnackbar(`You have been assigned the role of ${newRole}.`); + } catch (error) { + console.error('Error refreshing participant token to update role:', error); + } + } else { + const participant = this.remoteParticipants.find((p) => p.identity === participantIdentity); + if (participant) { + participant.meetRole = newRole; + } } + + break; } } }