-
Notifications
You must be signed in to change notification settings - Fork 64
/
ParticipantView.js
65 lines (58 loc) · 1.55 KB
/
ParticipantView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, { useMemo } from "react";
import { useMeeting } from "@videosdk.live/react-sdk";
import { MemoizedParticipantGrid } from "../../components/ParticipantGrid";
function ParticipantsViewer({ isPresenting }) {
const {
participants,
pinnedParticipants,
activeSpeakerId,
localParticipant,
localScreenShareOn,
presenterId,
} = useMeeting();
const participantIds = useMemo(() => {
const pinnedParticipantId = [...pinnedParticipants.keys()].filter(
(participantId) => {
return participantId !== localParticipant.id;
}
);
const regularParticipantIds = [...participants.keys()].filter(
(participantId) => {
return (
![...pinnedParticipants.keys()].includes(participantId) &&
localParticipant.id !== participantId
);
}
);
const ids = [
localParticipant.id,
...pinnedParticipantId,
...regularParticipantIds,
].slice(0, isPresenting ? 6 : 16);
if (activeSpeakerId) {
if (!ids.includes(activeSpeakerId)) {
ids[ids.length - 1] = activeSpeakerId;
}
}
return ids;
}, [
participants,
activeSpeakerId,
pinnedParticipants,
presenterId,
localScreenShareOn,
]);
return (
<MemoizedParticipantGrid
participantIds={participantIds}
isPresenting={isPresenting}
/>
);
}
const MemorizedParticipantView = React.memo(
ParticipantsViewer,
(prevProps, nextProps) => {
return prevProps.isPresenting === nextProps.isPresenting;
}
);
export default MemorizedParticipantView;