mirror of
https://github.com/suitenumerique/meet.git
synced 2026-07-26 11:58:53 +00:00
bf6f7430e7
Mark JS imports as type-only when applicable so they are stripped at build time and ignored during chunk splitting, ensuring we take full advantage of Rollup's code-splitting optimizations.
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import type { Participant } from 'livekit-client'
|
|
import {
|
|
useParticipantAttribute,
|
|
useParticipants,
|
|
} from '@livekit/components-react'
|
|
import { isLocal } from '@/utils/livekit'
|
|
import { useMemo } from 'react'
|
|
import { useRaiseHand } from '@/features/rooms/api/updateRaiseHand'
|
|
|
|
type useRaisedHandProps = {
|
|
participant: Participant
|
|
}
|
|
|
|
export function useRaisedHandPosition({ participant }: useRaisedHandProps) {
|
|
const { isHandRaised } = useRaisedHand({ participant })
|
|
|
|
const participants = useParticipants()
|
|
|
|
const positionInQueue = useMemo(() => {
|
|
if (!isHandRaised) return
|
|
|
|
return (
|
|
participants
|
|
.filter((p) => !!p.attributes.handRaisedAt)
|
|
.sort((a, b) => {
|
|
const dateA = new Date(a.attributes.handRaisedAt)
|
|
const dateB = new Date(b.attributes.handRaisedAt)
|
|
return dateA.getTime() - dateB.getTime()
|
|
})
|
|
.findIndex((p) => p.identity === participant.identity) + 1
|
|
)
|
|
}, [participants, participant, isHandRaised])
|
|
|
|
return {
|
|
positionInQueue,
|
|
firstInQueue: positionInQueue == 1,
|
|
}
|
|
}
|
|
|
|
export function useRaisedHand({ participant }: useRaisedHandProps) {
|
|
const handRaisedAtAttribute = useParticipantAttribute('handRaisedAt', {
|
|
participant,
|
|
})
|
|
const { raiseHand } = useRaiseHand()
|
|
|
|
const isHandRaised = !!handRaisedAtAttribute
|
|
|
|
const toggleRaisedHand = async () => {
|
|
if (!isLocal(participant)) return
|
|
try {
|
|
await raiseHand(!isHandRaised)
|
|
} catch (e) {
|
|
console.error(
|
|
`Failed to toggle hand: ${e instanceof Error ? e.message : 'Unknown error'}`
|
|
)
|
|
}
|
|
}
|
|
|
|
return { isHandRaised, toggleRaisedHand }
|
|
}
|