mirror of
https://github.com/streamwall/streamwall.git
synced 2025-12-06 01:45:37 -05:00
Add stream list filter
This commit is contained in:
@@ -89,15 +89,27 @@ export const GlobalStyle = createGlobalStyle`
|
|||||||
`
|
`
|
||||||
|
|
||||||
const normalStreamKinds = new Set(['video', 'audio', 'web'])
|
const normalStreamKinds = new Set(['video', 'audio', 'web'])
|
||||||
function filterStreams(streams: StreamData[], wallStreamIds: Set<string>) {
|
function filterStreams(
|
||||||
|
streams: StreamData[],
|
||||||
|
wallStreamIds: Set<string>,
|
||||||
|
filter: string,
|
||||||
|
) {
|
||||||
const wallStreams = []
|
const wallStreams = []
|
||||||
const liveStreams = []
|
const liveStreams = []
|
||||||
const otherStreams = []
|
const otherStreams = []
|
||||||
for (const stream of streams) {
|
for (const stream of streams) {
|
||||||
const { _id, kind, status } = stream
|
const { _id, kind, status, label, source, state, city } = stream
|
||||||
if (kind && !normalStreamKinds.has(kind)) {
|
if (kind && !normalStreamKinds.has(kind)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
filter !== '' &&
|
||||||
|
!`${label}${source}${state}${city}`
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(filter.toLowerCase())
|
||||||
|
) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (wallStreamIds.has(_id)) {
|
if (wallStreamIds.has(_id)) {
|
||||||
wallStreams.push(stream)
|
wallStreams.push(stream)
|
||||||
} else if ((kind && kind !== 'video') || status === 'Live') {
|
} else if ((kind && kind !== 'video') || status === 'Live') {
|
||||||
@@ -547,6 +559,13 @@ export function ControlUI({
|
|||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const [streamFilter, setStreamFilter] = useState('')
|
||||||
|
const handleStreamFilterChange = useCallback<
|
||||||
|
JSX.InputEventHandler<HTMLInputElement>
|
||||||
|
>((ev) => {
|
||||||
|
setStreamFilter(ev.currentTarget?.value)
|
||||||
|
}, [])
|
||||||
|
|
||||||
// Set up keyboard shortcuts.
|
// Set up keyboard shortcuts.
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
hotkeyTriggers.map((k) => `alt+${k}`).join(','),
|
hotkeyTriggers.map((k) => `alt+${k}`).join(','),
|
||||||
@@ -603,9 +622,9 @@ export function ControlUI({
|
|||||||
),
|
),
|
||||||
[sharedState],
|
[sharedState],
|
||||||
)
|
)
|
||||||
const [wallStreams, liveStreams, otherStreams] = filterStreams(
|
const [wallStreams, liveStreams, otherStreams] = useMemo(
|
||||||
streams,
|
() => filterStreams(streams, wallStreamIds, streamFilter),
|
||||||
wallStreamIds,
|
[streams, wallStreamIds, streamFilter],
|
||||||
)
|
)
|
||||||
function StreamList({ rows }: { rows: StreamData[] }) {
|
function StreamList({ rows }: { rows: StreamData[] }) {
|
||||||
return rows.map((row) => (
|
return rows.map((row) => (
|
||||||
@@ -776,6 +795,11 @@ export function ControlUI({
|
|||||||
<StyledDataContainer isConnected={isConnected}>
|
<StyledDataContainer isConnected={isConnected}>
|
||||||
{isConnected ? (
|
{isConnected ? (
|
||||||
<div>
|
<div>
|
||||||
|
<input
|
||||||
|
onChange={handleStreamFilterChange}
|
||||||
|
value={streamFilter}
|
||||||
|
placeholder="filter"
|
||||||
|
/>
|
||||||
<h3>Viewing</h3>
|
<h3>Viewing</h3>
|
||||||
<StreamList rows={wallStreams} />
|
<StreamList rows={wallStreams} />
|
||||||
<h3>Live</h3>
|
<h3>Live</h3>
|
||||||
|
|||||||
Reference in New Issue
Block a user