aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Search/API
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-12-20 21:12:46 -0600
committerGitHub <noreply@github.com>2021-12-20 21:12:46 -0600
commit146a27e18696f6debbb0d6dfb67e91119a2cca9c (patch)
tree6ed449740a0c352c2d920c6a32a9f1faaff0e181 /src/slskd/Search/API
parentd7617d461cb14eb593641df023c79634befab1c2 (diff)
parent93834bda3051a6edb4aefa495961ee387fe2b87b (diff)
downloadslskd-146a27e18696f6debbb0d6dfb67e91119a2cca9c.tar.gz
Merge branch 'master' into config-file
Diffstat (limited to 'src/slskd/Search/API')
-rw-r--r--src/slskd/Search/API/Hubs/SearchHub.cs83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/slskd/Search/API/Hubs/SearchHub.cs b/src/slskd/Search/API/Hubs/SearchHub.cs
new file mode 100644
index 00000000..1bb45574
--- /dev/null
+++ b/src/slskd/Search/API/Hubs/SearchHub.cs
@@ -0,0 +1,83 @@
+// <copyright file="SearchHub.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
+
+using Microsoft.Extensions.Options;
+
+namespace slskd.Search.API
+{
+ using System;
+ using System.Threading.Tasks;
+ using Microsoft.AspNetCore.Authorization;
+ using Microsoft.AspNetCore.SignalR;
+
+ public static class SearchHubMethods
+ {
+ public static readonly string Response = "RESPONSE";
+ public static readonly string Update = "UPDATE";
+ }
+
+ /// <summary>
+ /// Extension methods for the search SignalR hub.
+ /// </summary>
+ public static class SearchHubExtensions
+ {
+ /// <summary>
+ /// Broadcast an update for a search.
+ /// </summary>
+ /// <param name="hub">The hub.</param>
+ /// <param name="search">The search to broadcast.</param>
+ /// <returns>The operation context.</returns>
+ public static Task BroadcastUpdateAsync(this IHubContext<SearchHub> hub, Search search)
+ {
+ return hub.Clients.All.SendAsync(SearchHubMethods.Update, search);
+ }
+
+ /// <summary>
+ /// Broadcast the present application options.
+ /// </summary>
+ /// <param name="hub">The hub.</param>
+ /// <param name="searchId">The ID of the search associated with the response.</param>
+ /// <param name="response">The response to broadcast.</param>
+ /// <returns>The operation context.</returns>
+ public static Task BroadcastResponseAsync(this IHubContext<SearchHub> hub, Guid searchId, Soulseek.SearchResponse response)
+ {
+ return hub.Clients.All.SendAsync(SearchHubMethods.Response, new { searchId, response });
+ }
+ }
+
+ /// <summary>
+ /// The search SignalR hub.
+ /// </summary>
+ [Authorize]
+ public class SearchHub : Hub
+ {
+ public SearchHub(
+ IStateMonitor<State> stateMonitor,
+ IOptionsMonitor<Options> optionsMonitor)
+ {
+ StateMonitor = stateMonitor;
+ OptionsMonitor = optionsMonitor;
+ }
+
+ private IStateMonitor<State> StateMonitor { get; }
+ private IOptionsMonitor<Options> OptionsMonitor { get; }
+
+ public override async Task OnConnectedAsync()
+ {
+ }
+ }
+} \ No newline at end of file