Add stream uptime to Dashboard.cshtml and Admin.cshtml

This commit is contained in:
Laura Hausmann 2021-01-27 22:24:25 +01:00
parent 311651860b
commit 5a7248c101
Signed by: zotan
GPG key ID: 5EC1D38FFC321311
3 changed files with 16 additions and 1 deletions

View file

@ -13,6 +13,7 @@
Response.Redirect("/");
return;
}
var stats = StreamUtils.GetStatsObject();
}
<h2>Users</h2>
@ -21,7 +22,7 @@
<tr>
<th scope="col">Username</th>
<th scope="col">Stream status</th>
<th scope="col">Actions</th>
c <th scope="col">Actions</th>
</tr>
</thead>
<tbody>
@ -30,6 +31,9 @@
<th scope="row">@user.Username</th>
<td>
@if (StreamUtils.IsLive(user.Username)) {
var uptimestr = stats.Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.First(p => p.Name == user.Username).Time;
var uptime = TimeSpan.FromMilliseconds(long.Parse(uptimestr)).StripMilliseconds();
if (user.AllowRestream && !string.IsNullOrWhiteSpace(user.RestreamTargets)) {
var restreams = StreamUtils.CountLiveRestreams(user.Username);
if (restreams > 0) {
@ -42,6 +46,7 @@
else {
<button class="btn btn-success" role="button" style="width:18ch" disabled>Live</button>
}
<button class="btn btn-dark" role="button" disabled>@uptime.ToString("g")</button>
}
else {
<button class="btn btn-danger" role="button" style="width:18ch" disabled>No data</button>

View file

@ -61,6 +61,9 @@ else {
<input type="text" class="form-control" id="input-streamurl" value="@Program.IngressDomain/ingress/@user.StreamKey" disabled>
<div class="input-group-append">
@if (StreamUtils.IsLive(user.Username)) {
var stats = StreamUtils.GetStatsObject();
var uptimestr = stats.Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.First(p => p.Name == user.Username).Time;
var uptime = TimeSpan.FromMilliseconds(long.Parse(uptimestr)).StripMilliseconds();
if (user.AllowRestream && !string.IsNullOrWhiteSpace(user.RestreamTargets)) {
if (StreamUtils.GetClientTime(user.Username) > 5000) {
var restreams = StreamUtils.CountLiveRestreams(user.Username);
@ -78,6 +81,7 @@ else {
else {
<button class="btn btn-success" role="button" style="width:13ch" disabled>Live</button>
}
<button class="btn btn-dark" role="button" disabled>@uptime.ToString("g")</button>
}
else {
<button class="btn btn-danger" role="button" style="width:13ch" disabled>No data</button>

View file

@ -1,3 +1,4 @@
using System;
using LinqToDB.Data;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
@ -25,4 +26,9 @@ namespace RTMPDash {
webBuilder.UseStartup<Startup>();
});
}
public static class TimeExtensions {
public static TimeSpan StripMilliseconds(this TimeSpan time) =>
new(time.Days, time.Hours, time.Minutes, time.Seconds);
}
}