Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

✨(frontend) allow unauthenticated participants to mute via LiveKit token

lebaudantoine388b7d172d55
diff --git a/src/frontend/src/features/rooms/api/muteParticipant.ts b/src/frontend/src/features/rooms/api/muteParticipant.ts
index fac79584..3b8418d4 100644
--- a/src/frontend/src/features/rooms/api/muteParticipant.ts
+++ b/src/frontend/src/features/rooms/api/muteParticipant.ts
@@ -6,14 +6,15 @@ import {
NotificationType,
} from '@/features/notifications'
import { fetchApi } from '@/api/fetchApi'
+import { useIsAdminOrOwner } from '../livekit/hooks/useIsAdminOrOwner'
export const useMuteParticipant = () => {
- const data = useRoomData()
-
+ const apiRoomData = useRoomData()
const { notifyParticipants } = useNotifyParticipants()
+ const isAdminOrOwner = useIsAdminOrOwner()
const muteParticipant = async (participant: Participant) => {
- if (!data?.id) {
+ if (!apiRoomData?.livekit?.room) {
throw new Error('Room id is not available')
}
const trackSid = participant.getTrackPublication(
@@ -24,24 +25,40 @@ export const useMuteParticipant = () => {
return
}
+ const headers = !isAdminOrOwner
+ ? {
+ Authorization: `Bearer ${apiRoomData?.livekit?.token}`,
+ }
+ : undefined
+
try {
- const response = await fetchApi(`rooms/${data.id}/mute-participant/`, {
- method: 'POST',
- body: JSON.stringify({
- participant_identity: participant.identity,
- track_sid: trackSid,
- }),
- })
+ const response = fetchApi(
+ `rooms/${apiRoomData?.livekit?.room}/mute-participant/`,
+ {
+ method: 'POST',
+ headers,
+ body: JSON.stringify({
+ participant_identity: participant.identity,
+ track_sid: trackSid,
+ }),
+ }
+ )
+ return response
+ } catch (error) {
+ console.error(
+ `Failed to mute participant ${participant.identity}: ${error instanceof Error ? error.message : 'Unknown error'}`
+ )
+ return
+ }
+ try {
await notifyParticipants({
type: NotificationType.ParticipantMuted,
destinationIdentities: [participant.identity],
})
-
- return response
- } catch (error) {
+ } catch (e) {
console.error(
- `Failed to mute participant ${participant.identity}: ${error instanceof Error ? error.message : 'Unknown error'}`
+ `Failed to notify muted participant ${participant.identity}: ${e}`
)
}
}