diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-10-02 22:08:17 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-10-02 22:08:17 -0500 |
| commit | e1d093264dad0ebfa78d8567d78d09f3d2dd4611 (patch) | |
| tree | d24e32aca8c83e143c818d8ae60b46816122ec92 /src/slskd/Core/API/Hubs | |
| parent | 3771d76618fdb17a0578bcb7125367fb43ba119f (diff) | |
| download | slskd-e1d093264dad0ebfa78d8567d78d09f3d2dd4611.tar.gz | |
send client state on connect
Diffstat (limited to 'src/slskd/Core/API/Hubs')
| -rw-r--r-- | src/slskd/Core/API/Hubs/ApplicationHub.cs | 24 |
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 |
