From 15ac0cacb31b4c132988806e81fcc6ea3c46f8ba Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 22 Jun 2023 20:47:21 +0100 Subject: [PATCH] Show only recent streams --- src/element/live-video-player.tsx | 37 ++++++++++++++++++------------- src/pages/root.tsx | 6 +++-- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/element/live-video-player.tsx b/src/element/live-video-player.tsx index 6b3df9b..c3964d7 100644 --- a/src/element/live-video-player.tsx +++ b/src/element/live-video-player.tsx @@ -13,22 +13,27 @@ export function LiveVideoPlayer(props: HTMLProps & { stream?: useEffect(() => { if (streamCached && video.current && !video.current.src && Hls.isSupported()) { - const hls = new Hls(); - hls.loadSource(streamCached); - hls.attachMedia(video.current); - hls.on(Hls.Events.ERROR, (event, data) => { - console.debug(event, data); - const errorType = data.type; - if (errorType === Hls.ErrorTypes.NETWORK_ERROR) { - hls.stopLoad(); - hls.detachMedia(); - setStatus(VideoStatus.Offline); - } - }) - hls.on(Hls.Events.MANIFEST_PARSED, () => { - setStatus(VideoStatus.Online); - }) - return () => hls.destroy(); + try { + const hls = new Hls(); + hls.loadSource(streamCached); + hls.attachMedia(video.current); + hls.on(Hls.Events.ERROR, (event, data) => { + console.debug(event, data); + const errorType = data.type; + if (errorType === Hls.ErrorTypes.NETWORK_ERROR) { + hls.stopLoad(); + hls.detachMedia(); + setStatus(VideoStatus.Offline); + } + }) + hls.on(Hls.Events.MANIFEST_PARSED, () => { + setStatus(VideoStatus.Online); + }) + return () => hls.destroy(); + } catch (e) { + console.error(e); + setStatus(VideoStatus.Offline); + } } }, [video, streamCached]); return ( diff --git a/src/pages/root.tsx b/src/pages/root.tsx index 28f042a..53624ef 100644 --- a/src/pages/root.tsx +++ b/src/pages/root.tsx @@ -1,16 +1,18 @@ import "./root.css"; import { useMemo } from "react"; +import { unixNow } from "@snort/shared"; import { EventKind, ParameterizedReplaceableNoteStore, RequestBuilder } from "@snort/system"; import { useRequestBuilder } from "@snort/system-react"; import { System } from ".."; import { VideoTile } from "../element/video-tile"; import { findTag } from "utils"; -export function RootPage() { +export function RootPage() { const rb = new RequestBuilder("root"); rb.withFilter() - .kinds([30_311 as EventKind]); + .kinds([30_311 as EventKind]) + .since(unixNow() - 86400); const feed = useRequestBuilder(System, ParameterizedReplaceableNoteStore, rb); const feedSorted = useMemo(() => {