Add separate viewing section to stream list

This commit is contained in:
Max Goodhart
2025-06-15 04:16:06 +00:00
parent a0083ae093
commit 9eb315c53c

View File

@@ -89,21 +89,24 @@ export const GlobalStyle = createGlobalStyle`
` `
const normalStreamKinds = new Set(['video', 'audio', 'web']) const normalStreamKinds = new Set(['video', 'audio', 'web'])
function filterStreams(streams: StreamData[]) { function filterStreams(streams: StreamData[], wallStreamIds: Set<string>) {
const wallStreams = []
const liveStreams = [] const liveStreams = []
const otherStreams = [] const otherStreams = []
for (const stream of streams) { for (const stream of streams) {
const { kind, status } = stream const { _id, kind, status } = stream
if (kind && !normalStreamKinds.has(kind)) { if (kind && !normalStreamKinds.has(kind)) {
continue continue
} }
if ((kind && kind !== 'video') || status === 'Live') { if (wallStreamIds.has(_id)) {
wallStreams.push(stream)
} else if ((kind && kind !== 'video') || status === 'Live') {
liveStreams.push(stream) liveStreams.push(stream)
} else { } else {
otherStreams.push(stream) otherStreams.push(stream)
} }
} }
return [liveStreams, otherStreams] return [wallStreams, liveStreams, otherStreams]
} }
export function useYDoc<T>(keys: string[]): { export function useYDoc<T>(keys: string[]): {
@@ -591,7 +594,19 @@ export function ControlUI({
[handleSwapView, focusedInputIdx], [handleSwapView, focusedInputIdx],
) )
const [liveStreams, otherStreams] = filterStreams(streams) const wallStreamIds = useMemo(
() =>
new Set(
Object.values(sharedState?.views ?? {})
.map(({ streamId }) => streamId)
.filter((x) => x !== undefined),
),
[sharedState],
)
const [wallStreams, liveStreams, otherStreams] = filterStreams(
streams,
wallStreamIds,
)
function StreamList({ rows }: { rows: StreamData[] }) { function StreamList({ rows }: { rows: StreamData[] }) {
return rows.map((row) => ( return rows.map((row) => (
<StreamLine <StreamLine
@@ -761,6 +776,8 @@ export function ControlUI({
<StyledDataContainer isConnected={isConnected}> <StyledDataContainer isConnected={isConnected}>
{isConnected ? ( {isConnected ? (
<div> <div>
<h3>Viewing</h3>
<StreamList rows={wallStreams} />
<h3>Live</h3> <h3>Live</h3>
<StreamList rows={liveStreams} /> <StreamList rows={liveStreams} />
<h3>Offline / Unknown</h3> <h3>Offline / Unknown</h3>