From 031505600ca07f713b61fb54711e4a67b6e7037c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Tue, 5 Dec 2023 02:22:30 +0100 Subject: [PATCH] Add info enpoint to api --- src/js/api.ts | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/js/api.ts b/src/js/api.ts index 518ce0b..137675c 100644 --- a/src/js/api.ts +++ b/src/js/api.ts @@ -1,4 +1,8 @@ +export interface SiteInfo { + siteName: string +} + export class MinistreamApiClient { ENV: string @@ -21,14 +25,22 @@ export class MinistreamApiClient { const resp = await fetch( url, ); - const res = resp.json() as unknown as string[]; - data = res; + data = await resp.json() as unknown as string[]; } catch (e) { throw e; } - return data; + const sortedStreams = data.sort((a, b) => { + if (a > b) { + return -1 + } else if (a < b) { + return 1 + } + return 0 + }) + + return sortedStreams; } async postOffer(streamKey: string, offer_sdp: RTCSessionDescription): Promise { @@ -43,8 +55,23 @@ export class MinistreamApiClient { body: offer_sdp.sdp }) const body = await resp.text() - const answer = new RTCSessionDescription({type: "answer", sdp: body}) + const answer = new RTCSessionDescription({ type: "answer", sdp: body }) return answer } + + async siteInfo(): Promise { + var url = "/api/info" + if (this.ENV !== "production") { + url = "http://localhost:8080/api/info" + } + + const resp = await fetch(url, + { + method: "GET", + }) + const data = resp.json() + + return data as unknown as SiteInfo + } }