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>
}
@ -186,4 +186,4 @@ function prepareDeleteUserModal(target) {
</form>
</div>
</div>
</div>
</div>

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>
}
@ -268,4 +268,4 @@ else {
$.ajax({method: 'POST', data: {action: action, target: target, value: value, '__RequestVerificationToken' : '@tokenSet.RequestToken'}, success: function () { location.reload() }})
}
</script>
}
}

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)
@ -139,4 +151,4 @@ namespace RTMPDash {
[XmlElement(ElementName = "channels", IsNullable = true)] public string Channels { get; set; }
[XmlElement(ElementName = "sample_rate", IsNullable = true)] public string SampleRate { get; set; }
}
}
}