Skip to content

Commit

Permalink
Track visibility in grid layout, adjust sorting preset
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Oct 4, 2023
1 parent d0a9661 commit 35d5f62
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
57 changes: 33 additions & 24 deletions packages/client/src/sorting/__tests__/presets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,50 @@ describe('presets', () => {
},
}));

expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name)).toEqual([
'F',
'B',
'E',
'D',
'A',
'C',
]);
expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name))
.toMatchInlineSnapshot(`
[
"F",
"D",
"A",
"B",
"C",
"E",
]
`);

// server-pin C
ps.at(-1)!.pin = {
isLocalPin: false,
pinnedAt: Date.now(),
};

expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name)).toEqual([
'C',
'F',
'B',
'E',
'D',
'A',
]);
expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name))
.toMatchInlineSnapshot(`
[
"E",
"F",
"D",
"A",
"B",
"C",
]
`);

ps.at(-3)!.publishedTracks = [TrackType.AUDIO]; // E
ps.at(-2)!.isDominantSpeaker = false; // D
ps.at(-1)!.isDominantSpeaker = true; // A

expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name)).toEqual([
'C',
'F',
'B',
'A',
'E',
'D',
]);
expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name))
.toMatchInlineSnapshot(`
[
"E",
"F",
"D",
"C",
"B",
"A",
]
`);
});
});
3 changes: 1 addition & 2 deletions packages/client/src/sorting/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ export const speakerLayoutSortPreset = combineComparators(
*/
export const paginatedLayoutSortPreset = combineComparators(
pinned,
screenSharing,
dominantSpeaker,
ifInvisibleOrUnknownBy(dominantSpeaker),
ifInvisibleOrUnknownBy(speaking),
ifInvisibleOrUnknownBy(reactionType('raised-hand')),
ifInvisibleOrUnknownBy(publishingVideo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export const PaginatedGridLayout = ({
ParticipantViewUI = DefaultParticipantViewUI,
}: PaginatedGridLayoutProps) => {
const [page, setPage] = useState(0);
const [
paginatedGridLayoutWrapperElement,
setPaginatedGridLayoutWrapperElement,
] = useState<HTMLDivElement | null>(null);

const call = useCall();
const { useParticipants, useRemoteParticipants } = useCallStateHooks();
Expand All @@ -88,6 +92,14 @@ export const PaginatedGridLayout = ({

usePaginatedLayoutSortPreset(call);

useEffect(() => {
if (!paginatedGridLayoutWrapperElement || !call) return;

const cleanup = call.setViewport(paginatedGridLayoutWrapperElement);

return () => cleanup();
}, [paginatedGridLayoutWrapperElement, call]);

// only used to render video elements
const participantGroups = useMemo(
() =>
Expand All @@ -112,7 +124,10 @@ export const PaginatedGridLayout = ({
if (!call) return null;

return (
<div className="str-video__paginated-grid-layout__wrapper">
<div
className="str-video__paginated-grid-layout__wrapper"
ref={setPaginatedGridLayoutWrapperElement}
>
<ParticipantsAudio participants={remoteParticipants} />
<div className="str-video__paginated-grid-layout">
{pageArrowsVisible && pageCount > 1 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const SpeakerLayout = ({
if (!participantsBarWrapperElement || !call) return;

const cleanup = call.setViewport(participantsBarWrapperElement);

return () => cleanup();
}, [participantsBarWrapperElement, call]);

Expand Down

0 comments on commit 35d5f62

Please sign in to comment.