added PaginatedVideoGrid component

This commit is contained in:
Jon 2021-07-08 16:29:11 +01:00
parent f2bc235cc1
commit 9101cbb7d9
3 changed files with 15 additions and 25 deletions

View File

@ -63,7 +63,7 @@ export const Room = ({ MainComponent = VideoGrid }) => {
}; };
Room.propTypes = { Room.propTypes = {
MainComponent: PropTypes.node, MainComponent: PropTypes.func,
}; };
export default Room; export default Room;

View File

@ -2,8 +2,7 @@ import React from 'react';
import App from '@dailyjs/basic-call/components/App'; import App from '@dailyjs/basic-call/components/App';
import Room from '@dailyjs/basic-call/components/Room'; import Room from '@dailyjs/basic-call/components/Room';
import PaginatedVideoGrid from '../PaginatedVideoGrid';
const Test = () => <div>Hello</div>;
/** /**
* Rather than create an entirely new Room component we'll * Rather than create an entirely new Room component we'll
@ -12,7 +11,7 @@ const Test = () => <div>Hello</div>;
export const AppWithPagination = () => ( export const AppWithPagination = () => (
<App <App
customComponentForState={{ customComponentForState={{
room: () => <Room MainComponent={Test} />, room: () => <Room MainComponent={PaginatedVideoGrid} />,
}} }}
/> />
); );

View File

@ -29,7 +29,7 @@ export const PaginatedVideoGrid = () => {
} = useParticipants(); } = useParticipants();
const activeSpeakerId = useActiveSpeaker(); const activeSpeakerId = useActiveSpeaker();
const { maxCamSubscriptions, updateCamSubscriptions } = useTracks(); const { updateCamSubscriptions } = useTracks();
const displayableParticipantCount = useMemo( const displayableParticipantCount = useMemo(
() => participantCount, () => participantCount,
@ -98,7 +98,7 @@ export const PaginatedVideoGrid = () => {
const n = Math.min(pageSize, displayableParticipantCount); const n = Math.min(pageSize, displayableParticipantCount);
if (n === 0) return [width, height]; if (n === 0) return [width, height];
const dims = []; const dims = [];
for (let i = 1; i <= n; i + 1) { for (let i = 1; i <= n; i += 1) {
let maxWidthPerTile = (width - (i - 1)) / i; let maxWidthPerTile = (width - (i - 1)) / i;
let maxHeightPerTile = maxWidthPerTile / DEFAULT_ASPECT_RATIO; let maxHeightPerTile = maxWidthPerTile / DEFAULT_ASPECT_RATIO;
const rows = Math.ceil(n / i); const rows = Math.ceil(n / i);
@ -131,11 +131,7 @@ export const PaginatedVideoGrid = () => {
* Play / pause tracks based on pagination * Play / pause tracks based on pagination
*/ */
const camSubscriptions = useMemo(() => { const camSubscriptions = useMemo(() => {
const maxSubs = maxCamSubscriptions const maxSubs = 3 * pageSize;
? // avoid subscribing to only a portion of a page
Math.max(maxCamSubscriptions, pageSize)
: // if no maximum is set, subscribe to adjacent pages
3 * pageSize;
// Determine participant ids to subscribe to, based on page. // Determine participant ids to subscribe to, based on page.
let subscribedIds = []; let subscribedIds = [];
@ -163,7 +159,7 @@ export const PaginatedVideoGrid = () => {
break; break;
} }
// Determine subscribed, but invisible (= paused) video tracks. // Determine subscribed, but invisible (= paused) video tracks
const invisibleSubscribedIds = subscribedIds.filter( const invisibleSubscribedIds = subscribedIds.filter(
(id) => id !== 'local' && !visibleParticipants.some((vp) => vp.id === id) (id) => id !== 'local' && !visibleParticipants.some((vp) => vp.id === id)
); );
@ -171,18 +167,13 @@ export const PaginatedVideoGrid = () => {
subscribedIds: subscribedIds.filter((id) => id !== 'local'), subscribedIds: subscribedIds.filter((id) => id !== 'local'),
pausedIds: invisibleSubscribedIds, pausedIds: invisibleSubscribedIds,
}; };
}, [maxCamSubscriptions, page, pageSize, participants, visibleParticipants]); }, [page, pageSize, participants, visibleParticipants]);
useEffect(() => { useEffect(() => {
const timeout = setTimeout(() => { updateCamSubscriptions(
updateCamSubscriptions( camSubscriptions?.subscribedIds,
camSubscriptions?.subscribedIds, camSubscriptions?.pausedIds
camSubscriptions?.pausedIds );
);
}, 50);
return () => {
clearTimeout(timeout);
};
}, [ }, [
camSubscriptions?.subscribedIds, camSubscriptions?.subscribedIds,
camSubscriptions?.pausedIds, camSubscriptions?.pausedIds,
@ -256,6 +247,7 @@ export const PaginatedVideoGrid = () => {
<Tile <Tile
participant={p} participant={p}
mirrored mirrored
key={p.id}
style={{ style={{
maxHeight: tileHeight, maxHeight: tileHeight,
maxWidth: tileWidth, maxWidth: tileWidth,
@ -281,7 +273,7 @@ export const PaginatedVideoGrid = () => {
&laquo; &laquo;
</button> </button>
)} )}
<div>{tiles}</div> <div className="tiles">{tiles}</div>
{pages > 1 && page < pages && ( {pages > 1 && page < pages && (
<button type="button" onClick={handleNextClick}> <button type="button" onClick={handleNextClick}>
&raquo; &raquo;
@ -296,11 +288,10 @@ export const PaginatedVideoGrid = () => {
position: relative; position: relative;
width: 100%; width: 100%;
} }
.tiles { .grid .tiles {
align-items: center; align-items: center;
display: flex; display: flex;
flex-flow: row wrap; flex-flow: row wrap;
gap: 1px;
max-height: 100%; max-height: 100%;
justify-content: center; justify-content: center;
margin: auto; margin: auto;