From aaf470a1cde07b20f2a30c3063a8c01105bf8fc8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 12 Oct 2021 09:04:47 -0500 Subject: add options broadcast to ApplicationHub --- src/slskd/Core/API/Hubs/ApplicationHub.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/slskd/Core/API') diff --git a/src/slskd/Core/API/Hubs/ApplicationHub.cs b/src/slskd/Core/API/Hubs/ApplicationHub.cs index c02f625f..46a1fef9 100644 --- a/src/slskd/Core/API/Hubs/ApplicationHub.cs +++ b/src/slskd/Core/API/Hubs/ApplicationHub.cs @@ -15,6 +15,8 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // +using Microsoft.Extensions.Options; + namespace slskd.Core.API { using System.Threading.Tasks; @@ -24,6 +26,7 @@ namespace slskd.Core.API public static class ApplicationHubMethods { public static readonly string State = "STATE"; + public static readonly string Options = "OPTIONS"; } /// @@ -41,6 +44,17 @@ namespace slskd.Core.API { return hub.Clients.All.SendAsync(ApplicationHubMethods.State, state); } + + /// + /// Broadcast the present application options. + /// + /// The hub. + /// The options to broadcast. + /// The operation context. + public static Task BroadcastOptionsAsync(this IHubContext hub, Options options) + { + return hub.Clients.All.SendAsync(ApplicationHubMethods.Options, options); + } } /// @@ -49,16 +63,21 @@ namespace slskd.Core.API [Authorize] public class ApplicationHub : Hub { - public ApplicationHub(IStateMonitor stateMonitor) + public ApplicationHub( + IStateMonitor stateMonitor, + IOptionsMonitor optionsMonitor) { StateMonitor = stateMonitor; + OptionsMonitor = optionsMonitor; } IStateMonitor StateMonitor { get; } + IOptionsMonitor OptionsMonitor { get; } public override async Task OnConnectedAsync() { await Clients.Caller.SendAsync(ApplicationHubMethods.State, StateMonitor.CurrentValue); + await Clients.Caller.SendAsync(ApplicationHubMethods.Options, OptionsMonitor.CurrentValue); } } } \ No newline at end of file -- cgit v1.2.3