mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-11 11:17:27 +00:00
b309f91095
We should use participant attributes, rather than metadata, to store hand status (raised/lowered). However, the useParticipantInfo hook is currently not suited for this, as it does not refresh when attributes change.
24 lines
794 B
TypeScript
24 lines
794 B
TypeScript
import { LocalParticipant, Participant } from 'livekit-client'
|
|
import { useParticipantInfo } from '@livekit/components-react'
|
|
import { isLocal } from '@/utils/livekit'
|
|
|
|
type useRaisedHandProps = {
|
|
participant: Participant
|
|
}
|
|
|
|
export function useRaisedHand({ participant }: useRaisedHandProps) {
|
|
// fixme - refactor this part to rely on attributes
|
|
const { metadata } = useParticipantInfo({ participant })
|
|
const parsedMetadata = JSON.parse(metadata || '{}')
|
|
|
|
const toggleRaisedHand = () => {
|
|
if (isLocal(participant)) {
|
|
parsedMetadata.raised = !parsedMetadata.raised
|
|
const localParticipant = participant as LocalParticipant
|
|
localParticipant.setMetadata(JSON.stringify(parsedMetadata))
|
|
}
|
|
}
|
|
|
|
return { isHandRaised: parsedMetadata.raised, toggleRaisedHand }
|
|
}
|