frontend: enhance participant role update handling with token refresh and error management

This commit is contained in:
juancarmore 2025-08-13 20:25:32 +02:00
parent 26b1750377
commit 134b2592e4

View File

@ -323,23 +323,46 @@ export class MeetingComponent implements OnInit {
onRoomCreated(room: Room) { onRoomCreated(room: Room) {
room.on( room.on(
RoomEvent.DataReceived, 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)); const event = JSON.parse(new TextDecoder().decode(payload));
if (topic === MeetSignalType.MEET_ROOM_PREFERENCES_UPDATED) { switch (topic) {
const { preferences } = event as MeetRoomPreferencesUpdatedPayload; case MeetSignalType.MEET_ROOM_PREFERENCES_UPDATED: {
this.featureConfService.setRoomPreferences(preferences); // Update room preferences
} else if (topic === MeetSignalType.MEET_PARTICIPANT_ROLE_UPDATED) { const { preferences } = event as MeetRoomPreferencesUpdatedPayload;
const { participantIdentity, newRole, secret } = event as MeetParticipantRoleUpdatedPayload; 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) { if (participantIdentity === this.localParticipant!.name) {
this.localParticipant!.meetRole = newRole; if (!secret) return;
// TODO: Request for new token with the new role
} else { this.roomSecret = secret;
const participant = this.remoteParticipants.find((p) => p.identity === participantIdentity); this.roomService.setRoomSecret(secret);
if (participant) {
participant.meetRole = newRole; 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;
} }
} }
} }