-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: webinar presentation layout update (#131)
* refactor: update variable name * refactor: webinar presentation layout
- Loading branch information
1 parent
8a447ae
commit 1ede017
Showing
10 changed files
with
229 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
app/_features/room/components/conference-presentation-layout.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
app/_features/room/components/webinar-presentation-layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
'use client'; | ||
|
||
import { useMemo } from 'react'; | ||
import ConferenceScreen from '@/_features/room/components/conference-screen'; | ||
import ConferenceScreenHidden from './conference-screen-hidden'; | ||
import { useMetadataContext } from '@/_features/room/contexts/metadata-context'; | ||
import { type ParticipantStream } from '@/_features/room/contexts/participant-context'; | ||
import '../styles/webinar-presentation-layout.css'; | ||
|
||
export default function WebinarPresentationLayout({ | ||
streams, | ||
}: { | ||
streams: ParticipantStream[]; | ||
}) { | ||
const { moderatorClientIDs, speakerClientIDs } = useMetadataContext(); | ||
const MAX_VISIBLE_PARTICIPANTS = 6; | ||
|
||
const { speakers, participants } = useMemo(() => { | ||
return streams.reduce( | ||
(accumulator, currentStream) => { | ||
if ( | ||
moderatorClientIDs.includes(currentStream.clientId) || | ||
speakerClientIDs.includes(currentStream.clientId) | ||
) { | ||
return { | ||
...accumulator, | ||
speakers: [...accumulator.speakers, currentStream], | ||
}; | ||
} else { | ||
return { | ||
...accumulator, | ||
participants: [...accumulator.participants, currentStream], | ||
}; | ||
} | ||
}, | ||
{ | ||
speakers: [] as ParticipantStream[], | ||
participants: [] as ParticipantStream[], | ||
} | ||
); | ||
}, [streams, moderatorClientIDs, speakerClientIDs]); | ||
|
||
const { speakerMedias, speakerScreens } = useMemo(() => { | ||
return speakers.reduce( | ||
(accumulator, currentValue) => { | ||
if (currentValue.source === 'screen') { | ||
return { | ||
...accumulator, | ||
speakerScreens: [...accumulator.speakerScreens, currentValue], | ||
}; | ||
} else { | ||
return { | ||
...accumulator, | ||
speakerMedias: [...accumulator.speakerMedias, currentValue], | ||
}; | ||
} | ||
}, | ||
{ | ||
speakerScreens: [] as ParticipantStream[], | ||
speakerMedias: [] as ParticipantStream[], | ||
} | ||
); | ||
}, [speakers]); | ||
|
||
const spotlightScreen = speakerScreens.pop(); | ||
const visibleSpeakerScreens = speakerScreens.slice( | ||
0, | ||
MAX_VISIBLE_PARTICIPANTS | ||
); | ||
const hiddenSpeakerScreens = speakerScreens.slice(MAX_VISIBLE_PARTICIPANTS); | ||
|
||
const visibleSpeakers = | ||
visibleSpeakerScreens.length < MAX_VISIBLE_PARTICIPANTS | ||
? speakerMedias.slice( | ||
0, | ||
MAX_VISIBLE_PARTICIPANTS - visibleSpeakerScreens.length | ||
) | ||
: []; | ||
|
||
const hiddenSpeakers = speakerMedias.slice(visibleSpeakers.length); | ||
|
||
const visibleStreams = [...visibleSpeakerScreens, ...visibleSpeakers]; | ||
const hiddenStreams = [ | ||
...hiddenSpeakerScreens, | ||
...hiddenSpeakers, | ||
...participants, | ||
]; | ||
|
||
const maxColumns = Math.ceil(Math.sqrt(visibleStreams.length)); | ||
|
||
return ( | ||
<div className="webinar-presentation-layout"> | ||
<div className="presentation-container"> | ||
<div className="relative h-full w-full"> | ||
{spotlightScreen && <ConferenceScreen stream={spotlightScreen} />} | ||
</div> | ||
</div> | ||
<div className="participant-container"> | ||
<div | ||
className={`participant-grid grid gap-3`} | ||
style={{ | ||
gridTemplateColumns: `repeat(${maxColumns}, minmax(auto, 180px))`, | ||
}} | ||
> | ||
{visibleStreams.map((stream) => { | ||
return ( | ||
<div | ||
className="participant-item" | ||
key={`visible-stream-${stream.id}`} | ||
> | ||
<ConferenceScreen stream={stream} /> | ||
</div> | ||
); | ||
})} | ||
{hiddenStreams.map((stream) => { | ||
return ( | ||
<ConferenceScreenHidden | ||
key={`hidden-screen-${stream.id}`} | ||
stream={stream} | ||
/> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.