From 48e07f3fda86f61845b3e5dafe8b32bad5bb724b Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 26 Jan 2021 00:21:02 +0100 Subject: [PATCH] Add restream info to Dashboard.cshtml --- Pages/Dashboard.cshtml | 38 +++++++++++++++++++++++++++++--------- README.md | 2 +- StreamUtils.cs | 26 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/Pages/Dashboard.cshtml b/Pages/Dashboard.cshtml index 3541df0..29c5f31 100644 --- a/Pages/Dashboard.cshtml +++ b/Pages/Dashboard.cshtml @@ -61,15 +61,23 @@ else {
@if (StreamUtils.IsLive(user.Username)) { - /*if (StreamUtils.IsLive(user.Username, "1080")) { - - } - else {*/ - - //} - - //kept around for - //TODO Restreaming & direct stats support + if (user.AllowRestream && !string.IsNullOrWhiteSpace(user.RestreamTargets)) { + if (StreamUtils.GetClientTime(user.Username) > 5000) { + var restreams = StreamUtils.CountLiveRestreams(user.Username); + if (restreams > 0) { + + } + else { + + } + } + else { + + } + } + else { + + } } else { @@ -113,6 +121,18 @@ else {
+ @if (!string.IsNullOrWhiteSpace(user.RestreamTargets) && StreamUtils.IsLive(user.Username) && StreamUtils.GetClientTime(user.Username) > 5000) { + var restreams = StreamUtils.CountLiveRestreams(user.Username); + if (restreams == 1) { + + } + else if (restreams > 1) { + + } + else { + + } + }
diff --git a/README.md b/README.md index 6d1181d..a09619c 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ User=rtmpdash Group=rtmpdash WorkingDirectory=/opt/rtmpdash Environment=ASPNETCORE_URLS='http://*:60001' -Environment=ASPNETCORE_ENVIRONMENT=Production +Environment=ASPNETCORE_ENVIRONMENT=Development ExecStart=/usr/bin/dotnet watch run --no-launch-profile Type=simple TimeoutStopSec=20 diff --git a/StreamUtils.cs b/StreamUtils.cs index d38aa4f..63d9d8d 100644 --- a/StreamUtils.cs +++ b/StreamUtils.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Xml.Serialization; +using RTMPDash.DataModels; namespace RTMPDash { public static class StreamUtils { @@ -11,6 +12,31 @@ namespace RTMPDash { .Server.Applications.First(p => p.Name == "ingress") .MethodLive.Streams.Any(p => p.Name == user); + public static bool IsLive(string user, string target) => GetStatsObject() + .Server.Applications.First(p => p.Name == "ingress") + .MethodLive.Streams + .Any(p => p.Name == user + && p.Clients.Any(c => c.Address + == target + .Replace("rtmp://", ""))); + + public static long GetClientTime(string user) => long.Parse(GetStatsObject() + .Server.Applications.First(p => p.Name == "ingress") + .MethodLive.Streams.First(p => p.Name == user) + .Time); + + public static int CountLiveRestreams(string user) { + var db = new AppDb.DbConn(); + var dbUser = db.Users.First(p => p.Username == user); + var stats = GetStatsObject(); + return dbUser.RestreamTargets.Split(",") + .Count(target => stats.Server.Applications.First(p => p.Name == "ingress") + .MethodLive.Streams + .Any(p => p.Name == user + && p.Clients.Any(c => c.Address + == target.Replace("rtmp://", "")))); + } + public static List ListLiveUsers() => GetStatsObject() .Server.Applications.First(p => p.Name == "ingress") .MethodLive.Streams.Select(p => p.Name)