Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/hooks/useParticipantIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type SortParticipants =
| 'user_id'
| 'user_name'
| SortParticipantsFunction;
type IdType = 'user' | 'session';

const defaultFilter: FilterParticipants = Boolean;
const defaultSort: SortParticipants = () => 0;
Expand All @@ -45,10 +46,11 @@ interface UseParticipantIdsArgs {
onParticipantLeft?(ev: DailyEventObjectParticipantLeft): void;
onParticipantUpdated?(ev: DailyEventObjectParticipant): void;
sort?: SortParticipants;
idType?: IdType;
}

/**
* Returns a list of participant ids (= session_id).
* Returns a list of participant ids (default = session_id).
* The list can optionally be filtered and sorted, using the filter and sort options.
*/
export const useParticipantIds = (
Expand All @@ -59,6 +61,7 @@ export const useParticipantIds = (
onParticipantLeft,
onParticipantUpdated,
sort = defaultSort,
idType = 'session',
}: UseParticipantIdsArgs = {
filter: defaultFilter,
sort: defaultSort,
Expand Down Expand Up @@ -121,13 +124,14 @@ export const useParticipantIds = (
return sortFn;
}, [sort]);

const idKey = idType === 'user' ? 'user_id' : 'session_id';
const sortedIds = useMemo(() => {
return allParticipants
.filter(filterFn)
.sort(sortFn)
.map((p) => p.session_id)
.map((p) => p[idKey])
.filter(Boolean);
}, [allParticipants, filterFn, sortFn]);
}, [allParticipants, filterFn, sortFn, idKey]);

useThrottledDailyEvent(
[
Expand Down