Parametrize list of protocols

This commit is contained in:
Ingo Oppermann 2022-07-21 13:55:08 +02:00
parent 0ee4e42360
commit dae3452a3f
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E
2 changed files with 11 additions and 55 deletions

View File

@ -1334,74 +1334,30 @@ class Restreamer {
// Sessions
async CurrentSessions() {
async CurrentSessions(protocols) {
const sessions = {
sessions: 0,
bitrate_kbit: 0,
};
const [val, err] = await this._call(this.api.ActiveSessions, ['ffmpeg', 'hls', 'rtmp', 'srt']);
const [val, err] = await this._call(this.api.ActiveSessions, protocols);
if (err !== null) {
return sessions;
}
// HLS sessions
if (!val.hls) {
val.hls = [];
}
for (let i = 0; i < val.hls.length; i++) {
if (!val.hls[i].reference.startsWith(this.channel.channelid)) {
for (let p of protocols) {
if (!(p in val)) {
continue;
}
sessions.sessions++;
sessions.bitrate_kbit += val.hls[i].bandwidth_tx_kbit;
}
for (let s of val[p]) {
if (!s.reference.startsWith(this.channel.channelid)) {
continue;
}
// ffmpeg sessions
if (!val.ffmpeg) {
val.ffmpeg = [];
}
for (let i = 0; i < val.ffmpeg.length; i++) {
if (!val.ffmpeg[i].reference.startsWith(this.channel.channelid)) {
continue;
sessions.sessions++;
sessions.bitrate_kbit += s.bandwidth_tx_kbit;
}
sessions.bitrate_kbit += val.ffmpeg[i].bandwidth_tx_kbit;
}
// RTMP sessions
if (!val.rtmp) {
val.rtmp = [];
}
for (let i = 0; i < val.rtmp.length; i++) {
if (!val.rtmp[i].reference.startsWith(this.channel.channelid)) {
continue;
}
sessions.sessions++;
sessions.bitrate_kbit += val.rtmp[i].bandwidth_tx_kbit;
}
// SRT sessions
if (!val.srt) {
val.srt = [];
}
for (let i = 0; i < val.srt.length; i++) {
if (!val.srt[i].reference.startsWith(this.channel.channelid)) {
continue;
}
sessions.sessions++;
sessions.bitrate_kbit += val.srt[i].bandwidth_tx_kbit;
}
return sessions;

View File

@ -89,7 +89,7 @@ export default function Publication(props) {
};
const sessions = async () => {
const current = await props.restreamer.CurrentSessions();
const current = await props.restreamer.CurrentSessions(['ffmpeg', 'hls', 'rtmp', 'srt']);
setSession({
viewer: current.sessions,