aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/API
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-10-03 12:00:57 -0500
committerGitHub <noreply@github.com>2021-10-03 12:00:57 -0500
commit1c790a33ba51598e5d5e9da77cf294c601e702be (patch)
tree82b118a2ee1fc35a012077f9484c29bd59bd1778 /src/slskd/Core/API
parent02d43eb0b04a0164c77349aa03834dc22b65bb29 (diff)
parent32a9a0f21e93cb0e172c00f0864a17b74d3dfa3b (diff)
downloadslskd-1c790a33ba51598e5d5e9da77cf294c601e702be.tar.gz
Merge pull request #206 from slskd/signalr-state
Use SignalR for application state
Diffstat (limited to 'src/slskd/Core/API')
-rw-r--r--src/slskd/Core/API/Hubs/ApplicationHub.cs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/slskd/Core/API/Hubs/ApplicationHub.cs b/src/slskd/Core/API/Hubs/ApplicationHub.cs
index a22fc7df..1900a8d0 100644
--- a/src/slskd/Core/API/Hubs/ApplicationHub.cs
+++ b/src/slskd/Core/API/Hubs/ApplicationHub.cs
@@ -17,10 +17,16 @@
namespace slskd.Core.API
{
+ using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
+ public static class ApplicationHubMethods
+ {
+ public static readonly string State = "STATE";
+ }
+
/// <summary>
/// Extension methods for the application SignalR hub.
/// </summary>
@@ -34,12 +40,7 @@ namespace slskd.Core.API
/// <returns>The operation context.</returns>
public static Task BroadcastStateAsync(this IHubContext<ApplicationHub> hub, State state)
{
- return hub.Clients.All.SendAsync(Methods.State, state);
- }
-
- private static class Methods
- {
- public static readonly string State = "STATE";
+ return hub.Clients.All.SendAsync(ApplicationHubMethods.State, state);
}
}
@@ -49,5 +50,16 @@ namespace slskd.Core.API
[Authorize]
public class ApplicationHub : Hub
{
+ public ApplicationHub(IStateMonitor<State> stateMonitor)
+ {
+ StateMonitor = stateMonitor;
+ }
+
+ IStateMonitor<State> StateMonitor { get; }
+
+ public override async Task OnConnectedAsync()
+ {
+ await Clients.Caller.SendAsync(ApplicationHubMethods.State, StateMonitor.CurrentValue);
+ }
}
} \ No newline at end of file