From e1d093264dad0ebfa78d8567d78d09f3d2dd4611 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 2 Oct 2021 22:08:17 -0500 Subject: send client state on connect --- src/slskd/Core/API/Hubs/ApplicationHub.cs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src') 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"; + } + /// /// Extension methods for the application SignalR hub. /// @@ -34,12 +40,7 @@ namespace slskd.Core.API /// The operation context. public static Task BroadcastStateAsync(this IHubContext 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 stateMonitor) + { + StateMonitor = stateMonitor; + } + + IStateMonitor StateMonitor { get; } + + public override async Task OnConnectedAsync() + { + await Clients.Caller.SendAsync(ApplicationHubMethods.State, StateMonitor.CurrentValue); + } } } \ No newline at end of file -- cgit v1.2.3