Skip to content

armgit / meet

Public Imported from GitHub
0

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

✨(frontend) add client for the update participant role endpoint

lebaudantoinebfb02b224277
diff --git a/src/frontend/src/features/participants/api/updateParticipantRole.ts b/src/frontend/src/features/participants/api/updateParticipantRole.ts
new file mode 100644
index 00000000..8fc4eb53
--- /dev/null
+++ b/src/frontend/src/features/participants/api/updateParticipantRole.ts
@@ -0,0 +1,31 @@
+import { fetchApi } from '@/api/fetchApi'
+import { useRoomData } from '@/features/rooms/livekit/hooks/useRoomData'
+import { AssignableParticipantRole } from '@/features/rooms/api/ApiRoom'
+
+export const useParticipantRole = () => {
+ const data = useRoomData()
+
+ const updateParticipantRole = async (
+ identity: string,
+ role: AssignableParticipantRole
+ ) => {
+ if (!data?.id) {
+ throw new Error('Room id is not available')
+ }
+
+ try {
+ return fetchApi(`rooms/${data.id}/update-participant-role/`, {
+ method: 'POST',
+ body: JSON.stringify({
+ participant_identity: identity,
+ role: role,
+ }),
+ })
+ } catch (error) {
+ console.error(
+ `Failed to update participant's role ${identity}: ${error instanceof Error ? error.message : 'Unknown error'}`
+ )
+ }
+ }
+ return { updateParticipantRole }
+}
diff --git a/src/frontend/src/features/rooms/api/ApiRoom.ts b/src/frontend/src/features/rooms/api/ApiRoom.ts
index 4e00bc3b..7c8fde65 100644
--- a/src/frontend/src/features/rooms/api/ApiRoom.ts
+++ b/src/frontend/src/features/rooms/api/ApiRoom.ts
@@ -30,3 +30,4 @@ export type ApiRoom = {
}
export type ParticipantRole = 'member' | 'administrator' | 'owner'
+export type AssignableParticipantRole = Exclude<ParticipantRole, 'owner'>