refactor: update sendParticipantRoleUpdatedSignal to send signal with needed secret only to the participant whose role has been updated, and broadcast the role update to all other participants without the secret

This commit is contained in:
juancarmore 2025-08-13 17:22:46 +02:00
parent 94b98600ba
commit cd48a77f31

View File

@ -89,28 +89,47 @@ export class FrontendEventService {
}
}
/**
* Sends a signal to notify participants in a room about updated participant roles.
*/
async sendParticipantRoleUpdatedSignal(
roomId: string,
participantName: string,
participantIdentity: string,
newRole: ParticipantRole,
secret: string
): Promise<void> {
this.logger.debug(
`Sending participant role updated signal for participant ${participantName} in room ${roomId}`
`Sending participant role updated signal for participant '${participantIdentity}' in room '${roomId}'`
);
const payload: MeetParticipantRoleUpdatedPayload = {
participantName,
const basePayload: MeetParticipantRoleUpdatedPayload = {
roomId,
participantIdentity,
newRole,
secret,
timestamp: Date.now()
};
const options: SendDataOptions = {
const baseOptions: SendDataOptions = {
topic: MeetSignalType.MEET_PARTICIPANT_ROLE_UPDATED
};
await this.sendSignal(roomId, payload, options);
// Send signal with secret to the participant whose role has been updated
await this.sendSignal(
roomId,
{ ...basePayload, secret },
{ ...baseOptions, destinationIdentities: [participantIdentity] }
);
// Broadcast the role update to all other participants without the secret
const participants = await this.livekitService.listRoomParticipants(roomId);
const otherParticipantIdentities = participants
.filter((p) => p.identity !== participantIdentity)
.map((p) => p.identity);
await this.sendSignal(roomId, basePayload, {
...baseOptions,
destinationIdentities: otherParticipantIdentities
});
}
/**