Implemented power state and task streaming over signalr
This commit is contained in:
22
MoonlightServers.Daemon/Helpers/AccessTokenHelper.cs
Normal file
22
MoonlightServers.Daemon/Helpers/AccessTokenHelper.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Text.Json;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.Helpers;
|
||||
using MoonlightServers.Daemon.Configuration;
|
||||
|
||||
namespace MoonlightServers.Daemon.Helpers;
|
||||
|
||||
[Singleton]
|
||||
public class AccessTokenHelper
|
||||
{
|
||||
private readonly AppConfiguration Configuration;
|
||||
|
||||
public AccessTokenHelper(AppConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public bool Process(string accessToken, out Dictionary<string, JsonElement> data)
|
||||
{
|
||||
return JwtHelper.TryVerifyAndDecodePayload(Configuration.Security.Token, accessToken, out data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MoonlightServers.Daemon.Helpers;
|
||||
|
||||
public class ServerConsoleConnection
|
||||
{
|
||||
public DateTime AuthenticatedUntil { get; set; }
|
||||
public int ServerId { get; set; }
|
||||
}
|
||||
44
MoonlightServers.Daemon/Helpers/ServerConsoleMonitor.cs
Normal file
44
MoonlightServers.Daemon/Helpers/ServerConsoleMonitor.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using MoonlightServers.Daemon.Models;
|
||||
using MoonlightServers.DaemonShared.Enums;
|
||||
|
||||
namespace MoonlightServers.Daemon.Helpers;
|
||||
|
||||
public class ServerConsoleMonitor
|
||||
{
|
||||
private readonly Server Server;
|
||||
private readonly IHubClients Clients;
|
||||
|
||||
public ServerConsoleMonitor(Server server, IHubClients clients)
|
||||
{
|
||||
Server = server;
|
||||
Clients = clients;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Server.StateMachine.OnTransitioned += OnPowerStateChanged;
|
||||
Server.OnTaskAdded += OnTaskNotify;
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
Server.StateMachine.OnTransitioned -= OnPowerStateChanged;
|
||||
}
|
||||
|
||||
private async Task OnTaskNotify(string task)
|
||||
{
|
||||
await Clients.Group($"server-{Server.Configuration.Id}").SendAsync(
|
||||
"TaskNotify",
|
||||
task
|
||||
);
|
||||
}
|
||||
|
||||
private async Task OnPowerStateChanged(ServerState serverState)
|
||||
{
|
||||
await Clients.Group($"server-{Server.Configuration.Id}").SendAsync(
|
||||
"PowerStateChanged",
|
||||
serverState.ToString()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user