//
// 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/.
//
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";
}
///
/// Extension methods for the search SignalR hub.
///
public static class SearchHubExtensions
{
///
/// Broadcast an update for a search.
///
/// The hub.
/// The search to broadcast.
/// The operation context.
public static Task BroadcastUpdateAsync(this IHubContext hub, Search search)
{
return hub.Clients.All.SendAsync(SearchHubMethods.Update, search);
}
///
/// Broadcast the present application options.
///
/// The hub.
/// The ID of the search associated with the response.
/// The response to broadcast.
/// The operation context.
public static Task BroadcastResponseAsync(this IHubContext hub, Guid searchId, Soulseek.SearchResponse response)
{
return hub.Clients.All.SendAsync(SearchHubMethods.Response, new { searchId, response });
}
}
///
/// The search SignalR hub.
///
[Authorize]
public class SearchHub : Hub
{
public SearchHub(
IStateMonitor stateMonitor,
IOptionsMonitor optionsMonitor)
{
StateMonitor = stateMonitor;
OptionsMonitor = optionsMonitor;
}
private IStateMonitor StateMonitor { get; }
private IOptionsMonitor OptionsMonitor { get; }
}
}