♻️(frontend) refactor useParticipants to streamline updatesOnlyOn logic
Simplified the logic to avoid redundancy. Removed unnecessary duplication of eventGroups, as it's already exported from the core. My bad for the initial complication — code is now cleaner.
This commit is contained in:
committed by
aleb_the_flash
parent
021e52d9eb
commit
9d0767ccfe
@@ -1,13 +1,14 @@
|
|||||||
import { css } from '@/styled-system/css'
|
import { css } from '@/styled-system/css'
|
||||||
|
import { allParticipantRoomEvents } from '@livekit/components-core'
|
||||||
import { useParticipants } from '@livekit/components-react'
|
import { useParticipants } from '@livekit/components-react'
|
||||||
|
|
||||||
import { Div, H } from '@/primitives'
|
import { Div, H } from '@/primitives'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { allParticipantRoomEvents } from '@/features/rooms/livekit/constants/events'
|
|
||||||
import { ParticipantListItem } from '../../controls/Participants/ParticipantListItem'
|
import { ParticipantListItem } from '../../controls/Participants/ParticipantListItem'
|
||||||
import { ParticipantsCollapsableList } from '../../controls/Participants/ParticipantsCollapsableList'
|
import { ParticipantsCollapsableList } from '../../controls/Participants/ParticipantsCollapsableList'
|
||||||
import { HandRaisedListItem } from '../../controls/Participants/HandRaisedListItem'
|
import { HandRaisedListItem } from '../../controls/Participants/HandRaisedListItem'
|
||||||
import { LowerAllHandsButton } from '../../controls/Participants/LowerAllHandsButton'
|
import { LowerAllHandsButton } from '../../controls/Participants/LowerAllHandsButton'
|
||||||
|
import { RoomEvent } from 'livekit-client'
|
||||||
|
|
||||||
// TODO: Optimize rendering performance, especially for longer participant lists, even though they are generally short.
|
// TODO: Optimize rendering performance, especially for longer participant lists, even though they are generally short.
|
||||||
export const ParticipantsList = () => {
|
export const ParticipantsList = () => {
|
||||||
@@ -17,7 +18,10 @@ export const ParticipantsList = () => {
|
|||||||
// because the 'useLocalParticipant' hook does not update the participant's information when their
|
// because the 'useLocalParticipant' hook does not update the participant's information when their
|
||||||
// metadata/name changes. The LiveKit team has marked this as a TODO item in the code.
|
// metadata/name changes. The LiveKit team has marked this as a TODO item in the code.
|
||||||
const participants = useParticipants({
|
const participants = useParticipants({
|
||||||
updateOnlyOn: allParticipantRoomEvents,
|
updateOnlyOn: [
|
||||||
|
RoomEvent.ParticipantNameChanged,
|
||||||
|
...allParticipantRoomEvents,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
const sortedRemoteParticipants = participants
|
const sortedRemoteParticipants = participants
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
import { RoomEvent } from 'livekit-client'
|
|
||||||
|
|
||||||
// Issue: 'allRemoteParticipantRoomEvents' is not exposed or importable. One event is missing
|
|
||||||
// to trigger the real-time update of participants when they change their name.
|
|
||||||
// This code is duplicated from LiveKit.
|
|
||||||
export const allRemoteParticipantRoomEvents = [
|
|
||||||
RoomEvent.ConnectionStateChanged,
|
|
||||||
RoomEvent.RoomMetadataChanged,
|
|
||||||
|
|
||||||
RoomEvent.ActiveSpeakersChanged,
|
|
||||||
RoomEvent.ConnectionQualityChanged,
|
|
||||||
|
|
||||||
RoomEvent.ParticipantConnected,
|
|
||||||
RoomEvent.ParticipantDisconnected,
|
|
||||||
RoomEvent.ParticipantPermissionsChanged,
|
|
||||||
RoomEvent.ParticipantMetadataChanged,
|
|
||||||
RoomEvent.ParticipantNameChanged, // This element is missing in LiveKit and causes problems
|
|
||||||
|
|
||||||
RoomEvent.TrackMuted,
|
|
||||||
RoomEvent.TrackUnmuted,
|
|
||||||
RoomEvent.TrackPublished,
|
|
||||||
RoomEvent.TrackUnpublished,
|
|
||||||
RoomEvent.TrackStreamStateChanged,
|
|
||||||
RoomEvent.TrackSubscriptionFailed,
|
|
||||||
RoomEvent.TrackSubscriptionPermissionChanged,
|
|
||||||
RoomEvent.TrackSubscriptionStatusChanged,
|
|
||||||
]
|
|
||||||
|
|
||||||
export const allParticipantRoomEvents = [
|
|
||||||
...allRemoteParticipantRoomEvents,
|
|
||||||
RoomEvent.LocalTrackPublished,
|
|
||||||
RoomEvent.LocalTrackUnpublished,
|
|
||||||
]
|
|
||||||
Reference in New Issue
Block a user