feat: dashboard

This commit is contained in:
2023-12-07 15:35:13 +00:00
parent 30907927d1
commit fedf674819
24 changed files with 307 additions and 93 deletions

View File

@ -2,6 +2,7 @@ import { NostrEvent, NostrLink, TaggedNostrEvent } from "@snort/system";
import type { Tags } from "@/types";
import { LIVE_STREAM } from "@/const";
import { StreamState } from ".";
export function toAddress(e: NostrEvent): string {
if (e.kind && e.kind >= 30000 && e.kind <= 40000) {
@ -82,3 +83,43 @@ export function uniqBy<T>(vals: Array<T>, key: (x: T) => string) {
export function getPlaceholder(id: string) {
return `https://robohash.v0l.io/${id}.png`;
}
interface StreamInfo {
title?: string;
summary?: string;
image?: string;
status?: string;
stream?: string;
recording?: string;
contentWarning?: string;
tags?: Array<string>;
goal?: string;
participants?: string;
starts?: string;
ends?: string;
}
export function extractStreamInfo(ev?: NostrEvent) {
const ret = {} as StreamInfo;
const matchTag = (tag: Array<string>, k: string, into: (v: string) => void) => {
if (tag[0] === k) {
into(tag[1]);
}
};
for (const t of ev?.tags ?? []) {
matchTag(t, "title", v => (ret.title = v));
matchTag(t, "summary", v => (ret.summary = v));
matchTag(t, "image", v => (ret.image = v));
matchTag(t, "status", v => (ret.status = v));
matchTag(t, "streaming", v => (ret.stream = v));
matchTag(t, "recording", v => (ret.recording = v));
matchTag(t, "content-warning", v => (ret.contentWarning = v));
matchTag(t, "current_participants", v => (ret.participants = v));
matchTag(t, "goal", v => (ret.goal = v));
matchTag(t, "starts", v => (ret.starts = v));
matchTag(t, "ends", v => (ret.ends = v));
}
ret.tags = ev?.tags.filter(a => a[0] === "t").map(a => a[1]) ?? [];
return ret;
}