diff --git a/src/lib/cards/LivestreamCard/LivestreamCard.svelte b/src/lib/cards/LivestreamCard/LivestreamCard.svelte index a7fb600..80541aa 100644 --- a/src/lib/cards/LivestreamCard/LivestreamCard.svelte +++ b/src/lib/cards/LivestreamCard/LivestreamCard.svelte @@ -7,6 +7,8 @@ import type { ContentComponentProps } from '../types'; import { getImageBlobUrl } from '$lib/website/utils'; import { RelativeTime } from '@foxui/time'; + import { online } from 'svelte/reactivity/window'; + import { Badge } from '@foxui/core'; let { item = $bindable() }: ContentComponentProps = $props(); @@ -22,6 +24,7 @@ title: string; thumb?: string; href: string; + online?: boolean; } | undefined = $state(); @@ -38,10 +41,31 @@ createdAt: latest.value.createdAt, title: latest.value.title as string, thumb: getImageBlobUrl({ link: latest.value.thumb?.ref.$link, did }), - href: latest.value.canonicalUrl || latest.value.url + href: latest.value.canonicalUrl || latest.value.url, + online: undefined }; } + if (latestLivestream) { + try { + const segmentsResponse = await fetch( + 'https://stream.place/xrpc/place.stream.live.getSegments?userDID=' + + encodeURIComponent(did) + ); + const segments = await segmentsResponse.json(); + + const lastSegment = segments.segments[0]; + const startTime = new Date(lastSegment.record.startTime).getTime(); + + const FIVE_MINUTES = 5 * 60 * 1000; + const now = Date.now(); + + latestLivestream.online = now - startTime <= FIVE_MINUTES; + } catch (error) { + console.error(error); + } + } + isLoaded = true; }); @@ -55,8 +79,23 @@