From ccbc8de04d35c3b1317a1e421538e630bbab1b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Wed, 6 Dec 2023 00:07:39 +0100 Subject: [PATCH] Changed stream list endpoint --- src/css/style.css | 13 ++++++++++++- src/js/api.ts | 15 ++++++++++----- src/js/app.tsx | 7 ++++--- src/js/menu.tsx | 25 ++++++++++++++++++------- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/css/style.css b/src/css/style.css index f57ab03..537c54a 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -90,12 +90,23 @@ a.menu-heading { } .menu-item a { - color: aliceblue; + color: var(--menu-header-text); text-decoration: none; } .menu-item { cursor: pointer; + display: flex; +} +.menu-viewcount { + font-family: 'Prompt', sans-serif; + font-size: larger; + font-weight: 300; + color: var(--menu-header-text); + margin-top: 0; + margin-bottom: 0; + padding-right: 1em; + height: 100%; } li.menu-item { diff --git a/src/js/api.ts b/src/js/api.ts index 3021467..86f7a8d 100644 --- a/src/js/api.ts +++ b/src/js/api.ts @@ -3,6 +3,11 @@ export interface SiteInfo { siteName: string } +export interface StreamInfo { + streamKey: string + viewCount: number +} + export class MinistreamApiClient { ENV: string @@ -14,8 +19,8 @@ export class MinistreamApiClient { } } - async listStreams(): Promise { - var data: string[] = []; + async listStreams(): Promise { + var data: StreamInfo[] = []; var url = "/whip" if (this.ENV !== "production") { url = "http://localhost:8080/whip" @@ -25,16 +30,16 @@ export class MinistreamApiClient { const resp = await fetch( url, ); - data = await resp.json() as unknown as string[]; + data = await resp.json() as unknown as StreamInfo[]; } catch (e) { throw e; } const sortedStreams = data.sort((a, b) => { - if (a > b) { + if (a.streamKey > b.streamKey) { return -1 - } else if (a < b) { + } else if (a.streamKey < b.streamKey) { return 1 } return 0 diff --git a/src/js/app.tsx b/src/js/app.tsx index 69c93e6..a332c3d 100644 --- a/src/js/app.tsx +++ b/src/js/app.tsx @@ -2,7 +2,7 @@ import { createRoot } from "react-dom/client"; import { Menu } from "./menu"; import { createContext, useEffect, useState } from "react"; import { MediaContainer } from "./media"; -import { MinistreamApiClient } from "./api"; +import { MinistreamApiClient, StreamInfo } from "./api"; import React from "react"; interface AppProps { @@ -26,7 +26,7 @@ function setTitle(title: string) { } export function App({ api }: AppProps) { - const [streamList, setStreamList] = useState([]) + const [streamList, setStreamList] = useState([]) const [selectedStream, setSelectedStream] = useState(null) const updateSelect = (item: string | null) => { @@ -38,10 +38,11 @@ export function App({ api }: AppProps) { setStreamList(list) if (list.length != streamList.length) { setStreamList(list) + return } if (!list.every((_, idx) => { - return list[idx] === streamList[idx] + return list[idx].streamKey === streamList[idx].streamKey })) { setStreamList(list) } diff --git a/src/js/menu.tsx b/src/js/menu.tsx index ec8f87f..7a4ce96 100644 --- a/src/js/menu.tsx +++ b/src/js/menu.tsx @@ -1,10 +1,11 @@ import { createRoot } from "react-dom/client"; import React from "react"; +import { StreamInfo } from "./api"; type StreamSelectCallback = (selected: string | null) => void interface MenuProps { - items: string[] + items: StreamInfo[] selectedItem: string | null selectCallback: StreamSelectCallback } @@ -15,12 +16,22 @@ export function Menu({ items, selectedItem, selectCallback }: MenuProps) { return ( <> {items.map((value, idx) => { - if (selectedItem == value) { - return
  • {value}
  • + if (selectedItem == value.streamKey) { + return <> +
  • + {value.streamKey} +

    {value.viewCount}

    +
  • + } else { - return
  • { - selectCallback(value) - }} className="menu-item">{value}
  • + return <> +
  • { + selectCallback(value.streamKey) + }} className="menu-item"> + {value.streamKey} +

    {value.viewCount}

    +
  • + } })} @@ -31,7 +42,7 @@ export function Menu({ items, selectedItem, selectCallback }: MenuProps) {