51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
|
|
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,
|
|
);
|
|
const res = resp.json() as unknown as string[];
|
|
data = res;
|
|
}
|
|
catch (e) {
|
|
throw e;
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|