This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
forked from livekit/egress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeakerLayout.tsx
84 lines (77 loc) · 2.25 KB
/
SpeakerLayout.tsx
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { ParticipantView, ScreenShareView } from '@livekit/react-components';
import {
Participant, RemoteVideoTrack, Track,
} from 'livekit-client';
import { ReactElement } from 'react';
import { LayoutProps } from './common';
import styles from './SpeakerLayout.module.css';
import useDominateSpeaker from './useDominateSpeaker';
const SpeakerLayout = ({ participants }: LayoutProps) => {
const dominantSpeaker = useDominateSpeaker(participants);
// find first participant with screen shared
let screenTrack: RemoteVideoTrack | undefined;
participants.forEach((p) => {
const pub = p.getTrack(Track.Source.ScreenShare);
if (pub && pub.isSubscribed) {
screenTrack = pub.videoTrack as RemoteVideoTrack;
}
});
if (participants.length === 0) {
return <div />;
}
// full screen a single participant
if (participants.length === 1 && !screenTrack) {
return (
<>
<ParticipantView
participant={participants[0]}
width="100%"
height="100%"
orientation="landscape"
speakerClassName=""
/>
</>
);
}
let otherParticipants: Participant[];
let mainView: ReactElement;
if (screenTrack) {
otherParticipants = participants;
mainView = (
<ScreenShareView track={screenTrack} height="100%" width="100%" />
);
} else {
const mainParticipant = dominantSpeaker ?? participants[0];
otherParticipants = participants.filter((p) => p !== mainParticipant);
mainView = (
<ParticipantView
key={mainParticipant.identity}
participant={mainParticipant}
width="100%"
height="100%"
orientation="landscape"
speakerClassName=""
/>
);
}
return (
<div className={styles.stage}>
<div className={styles.stageCenter}>{mainView}</div>
<div className={styles.stageSidebar}>
{otherParticipants.map((participant) => (
<ParticipantView
key={participant.identity}
participant={participant}
width="100%"
height="100%"
aspectWidth={16}
aspectHeight={9}
orientation="landscape"
speakerClassName=""
/>
))}
</div>
</div>
);
};
export default SpeakerLayout;