Add info enpoint to api
This commit is contained in:
parent
03a5fb5497
commit
031505600c
@ -1,4 +1,8 @@
|
|||||||
|
|
||||||
|
export interface SiteInfo {
|
||||||
|
siteName: string
|
||||||
|
}
|
||||||
|
|
||||||
export class MinistreamApiClient {
|
export class MinistreamApiClient {
|
||||||
ENV: string
|
ENV: string
|
||||||
|
|
||||||
@ -21,14 +25,22 @@ export class MinistreamApiClient {
|
|||||||
const resp = await fetch(
|
const resp = await fetch(
|
||||||
url,
|
url,
|
||||||
);
|
);
|
||||||
const res = resp.json() as unknown as string[];
|
data = await resp.json() as unknown as string[];
|
||||||
data = res;
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
throw 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<RTCSessionDescription> {
|
async postOffer(streamKey: string, offer_sdp: RTCSessionDescription): Promise<RTCSessionDescription> {
|
||||||
@ -43,8 +55,23 @@ export class MinistreamApiClient {
|
|||||||
body: offer_sdp.sdp
|
body: offer_sdp.sdp
|
||||||
})
|
})
|
||||||
const body = await resp.text()
|
const body = await resp.text()
|
||||||
const answer = new RTCSessionDescription({type: "answer", sdp: body})
|
const answer = new RTCSessionDescription({ type: "answer", sdp: body })
|
||||||
|
|
||||||
return answer
|
return answer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async siteInfo(): Promise<SiteInfo> {
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user