frontend: enhance participant role update handling with token refresh and error management
This commit is contained in:
parent
26b1750377
commit
134b2592e4
@ -323,24 +323,47 @@ 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) {
|
||||||
|
case MeetSignalType.MEET_ROOM_PREFERENCES_UPDATED: {
|
||||||
|
// Update room preferences
|
||||||
const { preferences } = event as MeetRoomPreferencesUpdatedPayload;
|
const { preferences } = event as MeetRoomPreferencesUpdatedPayload;
|
||||||
this.featureConfService.setRoomPreferences(preferences);
|
this.featureConfService.setRoomPreferences(preferences);
|
||||||
} else if (topic === MeetSignalType.MEET_PARTICIPANT_ROLE_UPDATED) {
|
break;
|
||||||
|
}
|
||||||
|
case MeetSignalType.MEET_PARTICIPANT_ROLE_UPDATED: {
|
||||||
|
// Update participant role
|
||||||
const { participantIdentity, newRole, secret } = event as MeetParticipantRoleUpdatedPayload;
|
const { participantIdentity, newRole, secret } = event as MeetParticipantRoleUpdatedPayload;
|
||||||
|
|
||||||
if (participantIdentity === this.localParticipant!.name) {
|
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.localParticipant!.meetRole = newRole;
|
||||||
// TODO: Request for new token with the new role
|
this.notificationService.showSnackbar(`You have been assigned the role of ${newRole}.`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error refreshing participant token to update role:', error);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const participant = this.remoteParticipants.find((p) => p.identity === participantIdentity);
|
const participant = this.remoteParticipants.find((p) => p.identity === participantIdentity);
|
||||||
if (participant) {
|
if (participant) {
|
||||||
participant.meetRole = newRole;
|
participant.meetRole = newRole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user