(frontend) allow unauthenticated participants to mute via LiveKit token

Pass the LiveKit token when calling the mute-participant endpoint
to authenticate the request.

This enables non-authenticated participants to mute others through
the API while preserving proper authorization checks.
This commit is contained in:
lebaudantoine
2026-03-24 19:07:55 +01:00
committed by aleb_the_flash
parent 288562cc0e
commit 388b7d172d
@@ -6,14 +6,15 @@ import {
NotificationType, NotificationType,
} from '@/features/notifications' } from '@/features/notifications'
import { fetchApi } from '@/api/fetchApi' import { fetchApi } from '@/api/fetchApi'
import { useIsAdminOrOwner } from '../livekit/hooks/useIsAdminOrOwner'
export const useMuteParticipant = () => { export const useMuteParticipant = () => {
const data = useRoomData() const apiRoomData = useRoomData()
const { notifyParticipants } = useNotifyParticipants() const { notifyParticipants } = useNotifyParticipants()
const isAdminOrOwner = useIsAdminOrOwner()
const muteParticipant = async (participant: Participant) => { const muteParticipant = async (participant: Participant) => {
if (!data?.id) { if (!apiRoomData?.livekit?.room) {
throw new Error('Room id is not available') throw new Error('Room id is not available')
} }
const trackSid = participant.getTrackPublication( const trackSid = participant.getTrackPublication(
@@ -24,25 +25,41 @@ export const useMuteParticipant = () => {
return return
} }
const headers = !isAdminOrOwner
? {
Authorization: `Bearer ${apiRoomData?.livekit?.token}`,
}
: undefined
try { try {
const response = await fetchApi(`rooms/${data.id}/mute-participant/`, { const response = fetchApi(
method: 'POST', `rooms/${apiRoomData?.livekit?.room}/mute-participant/`,
body: JSON.stringify({ {
participant_identity: participant.identity, method: 'POST',
track_sid: trackSid, headers,
}), body: JSON.stringify({
}) participant_identity: participant.identity,
track_sid: trackSid,
await notifyParticipants({ }),
type: NotificationType.ParticipantMuted, }
destinationIdentities: [participant.identity], )
})
return response return response
} catch (error) { } catch (error) {
console.error( console.error(
`Failed to mute participant ${participant.identity}: ${error instanceof Error ? error.message : 'Unknown error'}` `Failed to mute participant ${participant.identity}: ${error instanceof Error ? error.message : 'Unknown error'}`
) )
return
}
try {
await notifyParticipants({
type: NotificationType.ParticipantMuted,
destinationIdentities: [participant.identity],
})
} catch (e) {
console.error(
`Failed to notify muted participant ${participant.identity}: ${e}`
)
} }
} }
return { muteParticipant } return { muteParticipant }