cobalt/src/modules/stream/stream.js

31 lines
1 KiB
JavaScript
Raw Normal View History

2022-07-17 12:21:51 +01:00
import { apiJSON } from "../sub/utils.js";
2022-07-08 19:17:56 +01:00
import { verifyStream } from "./manage.js";
import { streamAudioOnly, streamDefault, streamLiveRender, streamVideoOnly } from "./types.js";
2022-07-08 19:17:56 +01:00
export default function(res, ip, id, hmac, exp) {
2022-07-08 19:17:56 +01:00
try {
let streamInfo = verifyStream(ip, id, hmac, exp);
if (streamInfo.error) {
2022-07-08 19:17:56 +01:00
res.status(streamInfo.status).json(apiJSON(0, { t: streamInfo.error }).body);
return;
}
if (streamInfo.isAudioOnly && streamInfo.type !== "bridge") {
streamAudioOnly(streamInfo, res);
return;
}
switch (streamInfo.type) {
case "render":
streamLiveRender(streamInfo, res);
break;
case "mute":
streamVideoOnly(streamInfo, res);
break;
default:
streamDefault(streamInfo, res);
break;
2022-07-08 19:17:56 +01:00
}
} catch (e) {
2022-09-01 14:51:18 +01:00
res.status(500).json({ status: "error", text: "Internal Server Error" });
2022-07-08 19:17:56 +01:00
}
}