Fix restreams on private streams

This commit is contained in:
Laura Hausmann 2022-02-09 22:31:13 +01:00
parent c097947164
commit a5f66216c9
Signed by: zotan
GPG key ID: D044E84C5BE01605
3 changed files with 18 additions and 6 deletions

View file

@ -51,7 +51,7 @@
var uptime = TimeSpan.FromMilliseconds(StreamUtils.GetClientTime(user.PrivateAccessKey, stats)).StripMilliseconds();
if (user.AllowRestream && !string.IsNullOrWhiteSpace(user.RestreamTargets)) {
var restreams = StreamUtils.CountLiveRestreams(user.PrivateAccessKey, stats);
var restreams = StreamUtils.CountLiveRestreams(user.Username, user.PrivateAccessKey, stats);
if (restreams > 0) {
<button class="btn btn-dark" role="button" style="width:18ch" disabled>Restreaming (@restreams)</button>
}

View file

@ -117,8 +117,8 @@ else {
else if (user.IsPrivate && StreamUtils.IsLive(user.PrivateAccessKey, stats)) {
var uptime = TimeSpan.FromMilliseconds(StreamUtils.GetClientTime(user.PrivateAccessKey, stats)).StripMilliseconds();
if (user.AllowRestream && !string.IsNullOrWhiteSpace(user.RestreamTargets)) {
if (StreamUtils.GetClientTime(user.Username, stats) > 5000) {
var restreams = StreamUtils.CountLiveRestreams(user.PrivateAccessKey, stats);
if (StreamUtils.GetClientTime(user.PrivateAccessKey, stats) > 5000) {
var restreams = StreamUtils.CountLiveRestreams(user.Username, user.PrivateAccessKey, stats);
if (restreams > 0) {
<button class="btn btn-success" role="button" style="width:20ch" disabled>Live & restreaming</button>
}

View file

@ -33,6 +33,18 @@ namespace RTMPDash {
== target.Replace("rtmp://", ""))));
}
public static int CountLiveRestreams(string user, string privateAccesskey, StatsObject stats) {
var db = new AppDb.DbConn();
var dbUser = db.Users.First(p => p.Username == user);
return dbUser.RestreamTargets.Split(",")
.Count(target => stats.Server.Applications.First(p => p.Name == "ingress")
.MethodLive.Streams
.Any(p => p.Name == privateAccesskey
&& p.Clients.Any(c => c.Address
== target.Replace("rtmp://", ""))));
}
public static List<string> ListLiveUsers() => GetStatsObject()
.Server.Applications.First(p => p.Name == "ingress")
.MethodLive.Streams.Select(p => p.Name)