Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination system #402

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ca1a2b4
Add pagination into getSubtracks
mustafaboleken Nov 14, 2024
e7e221f
Add updateAllParticipantsPagination function
mustafaboleken Nov 14, 2024
ea88c87
Remove subTrackStreamIds usage
mustafaboleken Nov 14, 2024
cadaa82
Comment adding temp broadcast object
mustafaboleken Nov 14, 2024
24bdc9e
Add extra check for updateAllParticipantsPagination
mustafaboleken Nov 14, 2024
9a296a6
Call getSubtracks after updating the pagination settings
mustafaboleken Nov 14, 2024
05c6bba
Add status info into manually created broadcasts
mustafaboleken Nov 14, 2024
57cd409
Refactor updateAllParticipantsPagination
mustafaboleken Nov 14, 2024
c5cd0d1
Set default value of the total page 1
mustafaboleken Nov 14, 2024
10743bc
Merge branch 'main' into addPaginationMechanism
mustafaboleken Nov 17, 2024
5cfbf27
Add test codes
mustafaboleken Nov 17, 2024
7166559
Add pagination controller
mustafaboleken Nov 17, 2024
800f2f1
Update ParticipantTab.test.js
mustafaboleken Nov 17, 2024
54349e2
Create paginationUpdate
mustafaboleken Nov 18, 2024
96be9c6
Refactor usage of the paged participants
mustafaboleken Nov 20, 2024
71da130
Reset paged participants in case of leave the room
mustafaboleken Nov 20, 2024
71bf0a1
Merge branch 'main' into addPaginationMechanism
mustafaboleken Nov 29, 2024
2ce4c9a
Add unit tests
mustafaboleken Nov 29, 2024
d030a47
Add missing close semi column
mustafaboleken Nov 29, 2024
5748601
Fix test cases
mustafaboleken Nov 29, 2024
6bdc195
Update AntMedia.test.js
mustafaboleken Nov 29, 2024
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
3 changes: 1 addition & 2 deletions react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"homepage": ".",
"dependencies": {
"@antmedia/webrtc_adaptor": "^2.12.0-SNAPSHOT-2024-Oct-19-07-47",
"@antmedia/webrtc_adaptor": "^2.12.0-SNAPSHOT-2024-Nov-29-04-11",
"@charkour/react-reactions": "^0.11.0",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
Expand Down
32 changes: 24 additions & 8 deletions react/src/Components/ParticipantTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import {styled, useTheme} from "@mui/material/styles";
import { SvgIcon } from "./SvgIcon";
import { ConferenceContext } from "pages/AntMedia";
import {CircularProgress} from "@mui/material";
import {CircularProgress, Pagination} from "@mui/material";
import {WebinarRoles} from "../WebinarRoles";

const ParticipantName = styled(Typography)(({ theme }) => ({
Expand All @@ -25,9 +25,13 @@
const conference = React.useContext(ConferenceContext);
const theme = useTheme();

const paginationUpdate = (event, value) => {
conference?.updateAllParticipantsPagination(value);

Check warning on line 29 in react/src/Components/ParticipantTab.js

View check run for this annotation

Codecov / codecov/patch

react/src/Components/ParticipantTab.js#L29

Added line #L29 was not covered by tests
}

const getAdminButtons = (streamId, assignedVideoCardId) => {
let publishStreamId = (streamId === "localVideo") ? conference.publishStreamId : streamId;
let role = conference.allParticipants[publishStreamId]?.role;
let role = conference.pagedParticipants[publishStreamId]?.role;

return (
<div id={'admin-button-group-'+streamId}>
Expand Down Expand Up @@ -97,7 +101,7 @@
</Grid>
<Grid item>
<div style={{display: 'flex'}}>
{(typeof conference.allParticipants[streamId]?.isPinned !== "undefined") && (conference.allParticipants[streamId]?.isPinned === true) ? (
{(typeof conference.pagedParticipants[streamId]?.isPinned !== "undefined") && (conference.pagedParticipants[streamId]?.isPinned === true) ? (
<PinBtn
id={"unpin-" + streamId}
sx={{minWidth: "unset", pt: 1, pb: 1}}
Expand Down Expand Up @@ -139,20 +143,32 @@
variant="body2"
style={{marginLeft: 4, fontWeight: 500}}
>
{Object.keys(conference.allParticipants).length}
{conference?.participantCount}
</ParticipantName>
</Grid>
{conference.isPlayOnly === false ? getParticipantItem(conference.publishStreamId, "You") : ""}
{Object.entries(conference.allParticipants).map(([streamId, broadcastObject]) => {
{Object.entries(conference.pagedParticipants).map(([streamId, broadcastObject]) => {
if (conference.publishStreamId !== streamId) {
var assignedVideoCardId = conference?.videoTrackAssignments?.find(vta => vta.streamId === streamId)?.videoLabel;
let assignedVideoCardId = conference?.videoTrackAssignments?.find(vta => vta.streamId === streamId)?.videoLabel;

Check warning on line 151 in react/src/Components/ParticipantTab.js

View check run for this annotation

Codecov / codecov/patch

react/src/Components/ParticipantTab.js#L151

Added line #L151 was not covered by tests
return getParticipantItem(streamId, broadcastObject.name, assignedVideoCardId);
} else {
return "";
return getParticipantItem(conference.publishStreamId, "You");
}
})}
</Stack>
</Grid>
{/* Pagination Controls */}
<Grid
container
justifyContent="center"
sx={{ mt: 2, mb: 2 }}
>
<Pagination
data-testid="participant-list-pagination"
count={conference.globals.participantListPagination.totalPage}
page={conference.globals.participantListPagination.currentPage}
onChange={paginationUpdate}
/>
</Grid>
</>
);

Expand Down
22 changes: 22 additions & 0 deletions react/src/__tests__/Components/ParticipantTab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,31 @@ const contextValue = {
publishStreamId: 'test-stream-id',
pinVideo: jest.fn(),
makeParticipantPresenter: jest.fn(),
pagedParticipants: {
'test-stream-id': {
role: 'host',
participantID: 'test-participant-id',
streamID: 'test-stream-id',
videoTrack: 'test-video-track',
audioTrack: 'test-audio-track',
videoLabel: 'test-video-label',
}
},
isAdmin: true,
isPlayOnly: false,
videoTrackAssignments: [{streamID: 'test-stream-id', participantID: 'test-participant-id', videoTrack: 'test-video-track', audioTrack: 'test-audio-track', videoLabel: 'test-video-label'}],
globals: {
maxVideoTrackCount: 6,
desiredTileCount: 6,
trackEvents: [],
participantListPagination: {
currentPage: 1,
pageSize: 15,
totalPage: 1,
startIndex: 0,
endIndex: 15
}
}
};

// Mock the useContext hook
Expand Down
138 changes: 138 additions & 0 deletions react/src/__tests__/pages/AntMedia.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2875,4 +2875,142 @@ describe('AntMedia Component', () => {
});
});

describe('updateAllParticipantsPagination', () => {
it('sets currentPage to 1 if currentPage is less than or equal to 0', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>);


await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

currentConference.updateAllParticipantsPagination(0);
expect(currentConference.globals.participantListPagination.currentPage).toBe(1);
});

it('calculates totalPage correctly', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>);


await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

await act(async () => {
currentConference.setParticipantCount(25);
});
currentConference.globals.participantListPagination.pageSize = 10;
currentConference.updateAllParticipantsPagination(1);
expect(currentConference.globals.participantListPagination.totalPage).toBe(3);
});

it('sets currentPage to totalPage if currentPage is greater than totalPage', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>);


await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

await act(async () => {
currentConference.setParticipantCount(25);
});
await waitFor(() => {
expect(currentConference.participantCount).toBe(25);
});
currentConference.globals.participantListPagination.pageSize = 10;
currentConference.updateAllParticipantsPagination(5);
expect(currentConference.globals.participantListPagination.currentPage).toBe(3);
});

it('calculates startIndex and endIndex correctly', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>);


await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

await act(async () => {
currentConference.setParticipantCount(25);
});
await waitFor(() => {
expect(currentConference.participantCount).toBe(25);
});
currentConference.globals.participantListPagination.pageSize = 10;
currentConference.updateAllParticipantsPagination(2);
});

it('calls getSubtracks with correct parameters', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>);


await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

const mockGetSubtracks = jest.fn();
currentConference.getSubtracks = mockGetSubtracks;

currentConference.roomName = 'testRoom';
await act(async () => {
currentConference.setParticipantCount(25);
});
await waitFor(() => {
expect(currentConference.participantCount).toBe(25);
});
currentConference.globals.participantListPagination.pageSize = 10;
currentConference.updateAllParticipantsPagination(2);
});

it('update participant count, when we receive new subtrack count', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>);


await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

const obj = { count: 12 };

await act(async () => {
webRTCAdaptorConstructor.callback('subtrackCount', obj);
});

await waitFor(() => {
expect(currentConference.participantCount).toBe(12);
});
});
});

});
Loading
Loading