78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
|
|
export interface SiteInfo {
|
|
siteName: string
|
|
}
|
|
|
|
export class MinistreamApiClient {
|
|
ENV: string
|
|
|
|
constructor() {
|
|
if (process.env.NODE_ENV) {
|
|
this.ENV = process.env.NODE_ENV
|
|
} else {
|
|
this.ENV = "production"
|
|
}
|
|
}
|
|
|
|
async listStreams(): Promise<string[]> {
|
|
var data: string[] = [];
|
|
var url = "/whip"
|
|
if (this.ENV !== "production") {
|
|
url = "http://localhost:8080/whip"
|
|
}
|
|
|
|
try {
|
|
const resp = await fetch(
|
|
url,
|
|
);
|
|
data = await resp.json() as unknown as string[];
|
|
}
|
|
catch (e) {
|
|
throw e;
|
|
}
|
|
|
|
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> {
|
|
var url = "/whip/" + streamKey
|
|
if (this.ENV !== "production") {
|
|
url = "http://localhost:8080/whip/" + streamKey
|
|
}
|
|
|
|
const resp = await fetch(url,
|
|
{
|
|
method: "POST",
|
|
body: offer_sdp.sdp
|
|
})
|
|
const body = await resp.text()
|
|
const answer = new RTCSessionDescription({ type: "answer", sdp: body })
|
|
|
|
return answer
|
|
}
|
|
|
|
async siteInfo(): Promise<SiteInfo> {
|
|
var url = "/api/siteinfo"
|
|
if (this.ENV !== "production") {
|
|
url = "http://localhost:8080/api/siteinfo"
|
|
}
|
|
|
|
const resp = await fetch(url,
|
|
{
|
|
method: "GET",
|
|
})
|
|
const data = resp.json()
|
|
|
|
return data as unknown as SiteInfo
|
|
}
|
|
}
|