Add restream info to Dashboard.cshtml
This commit is contained in:
parent
0d8fa18664
commit
48e07f3fda
|
@ -61,15 +61,23 @@ 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)) {
|
||||
/*if (StreamUtils.IsLive(user.Username, "1080")) {
|
||||
<button class="btn btn-dark" role="button" style="width:13ch" disabled>Restreaming</button>
|
||||
}
|
||||
else {*/
|
||||
<button class="btn btn-success" role="button" style="width:13ch" disabled>Live</button>
|
||||
//}
|
||||
|
||||
//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) {
|
||||
<button class="btn btn-success" role="button" style="width:20ch" disabled>Live & restreaming</button>
|
||||
}
|
||||
else {
|
||||
<button class="btn btn-warning" role="button" style="width:22ch" disabled>Live & restream down</button>
|
||||
}
|
||||
}
|
||||
else {
|
||||
<button class="btn btn-dark" role="button" style="width:13ch" disabled>Starting...</button>
|
||||
}
|
||||
}
|
||||
else {
|
||||
<button class="btn btn-success" role="button" style="width:13ch" disabled>Live</button>
|
||||
}
|
||||
}
|
||||
else {
|
||||
<button class="btn btn-danger" role="button" style="width:13ch" disabled>No data</button>
|
||||
|
@ -113,6 +121,18 @@ else {
|
|||
<input type="hidden" value="restream_targets_set" name="action">
|
||||
<input type="text" class="form-control" name="value" placeholder="rtmp://live-ber.twitch.tv/app/streamkey,rtmp://a.rtmp.youtube.com/live2/streamkey" value="@user.RestreamTargets">
|
||||
<div class="input-group-append">
|
||||
@if (!string.IsNullOrWhiteSpace(user.RestreamTargets) && StreamUtils.IsLive(user.Username) && StreamUtils.GetClientTime(user.Username) > 5000) {
|
||||
var restreams = StreamUtils.CountLiveRestreams(user.Username);
|
||||
if (restreams == 1) {
|
||||
<button class="btn btn-dark" role="button" style="width:19ch" disabled>@restreams Restream active</button>
|
||||
}
|
||||
else if (restreams > 1) {
|
||||
<button class="btn btn-dark" role="button" style="width:20ch" disabled>@restreams Restreams active</button>
|
||||
}
|
||||
else {
|
||||
<button class="btn btn-danger" role="button" style="width:13ch" disabled>Down</button>
|
||||
}
|
||||
}
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<string> ListLiveUsers() => GetStatsObject()
|
||||
.Server.Applications.First(p => p.Name == "ingress")
|
||||
.MethodLive.Streams.Select(p => p.Name)
|
||||
|
|
Loading…
Reference in New Issue