1+ import { useEffect , useRef } from 'react' ;
12import {
3+ CallTypes ,
4+ combineComparators ,
25 DefaultParticipantViewUI ,
6+ defaultSortPreset ,
7+ dominantSpeaker ,
38 ParticipantsAudio ,
49 ParticipantView ,
10+ pinned ,
11+ publishingAudio ,
12+ publishingVideo ,
13+ reactionType ,
14+ screenSharing ,
515 SfuModels ,
16+ speaking ,
17+ StreamVideoParticipant ,
618 useCall ,
719 useCallStateHooks ,
820} from '@stream-io/video-react-sdk' ;
@@ -13,8 +25,9 @@ import { useEgressReadyWhenAnyParticipantMounts } from '../egressReady';
1325import './DominantSpeaker.scss' ;
1426
1527export const DominantSpeaker = ( ) => {
16- const activeCall = useCall ( ) ;
28+ const call = useCall ( ) ;
1729 const speakerInSpotlight = useSpotlightParticipant ( ) ;
30+ const lastSpeakerInSpotlight = useRef < StreamVideoParticipant | null > ( null ) ;
1831 const { useRemoteParticipants } = useCallStateHooks ( ) ;
1932 const remoteParticipants = useRemoteParticipants ( ) ;
2033 const { setVideoElement, setVideoPlaceholderElement } =
@@ -23,7 +36,39 @@ export const DominantSpeaker = () => {
2336 SfuModels . TrackType . VIDEO ,
2437 ) ;
2538
26- if ( ! activeCall ) return < h2 > No active call</ h2 > ;
39+ useEffect ( ( ) => {
40+ if ( ! call ) return ;
41+ const comparator = combineComparators (
42+ screenSharing ,
43+ pinned ,
44+ dominantSpeaker ,
45+ speaking ,
46+ reactionType ( 'raised-hand' ) ,
47+ publishingVideo ,
48+ publishingAudio ,
49+ ) ;
50+ call . setSortParticipantsBy ( comparator ) ;
51+ return ( ) => {
52+ // reset the sorting to the default for the call type
53+ const callConfig = CallTypes . get ( call . type ) ;
54+ const preset = callConfig . options . sortParticipantsBy || defaultSortPreset ;
55+ call . setSortParticipantsBy ( preset ) ;
56+ } ;
57+ } , [ call ] ) ;
58+
59+ useEffect ( ( ) => {
60+ if ( ! call || ! speakerInSpotlight ) return ;
61+
62+ const sessionId = lastSpeakerInSpotlight . current ?. sessionId ;
63+ if ( speakerInSpotlight . sessionId === sessionId ) return ;
64+
65+ const tag = 'recorder.dominant_speaker_layout.spotlight_speaker_changed' ;
66+ call . tracer . trace ( tag , speakerInSpotlight ) ;
67+
68+ lastSpeakerInSpotlight . current = speakerInSpotlight ;
69+ } , [ call , speakerInSpotlight ] ) ;
70+
71+ if ( ! call ) return < h2 > No active call</ h2 > ;
2772 return (
2873 < div
2974 className = "eca__dominant-speaker__container"
0 commit comments