/
kochkatech
/
Queue
Обзор
Документация
Войти
/
kochkatech
/
Queue
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
dev
src/Queue.Display/Services/QueueApiClient.cs
45 строк
2 KB
kochkareal
feat: табло очереди
24 июл 2026, 22:27
24 июл 2026, 22:27
2805d52
Код
Авторство
О чём код?
using System; using System.Net.Http; using System.Net.Http.Json; using System.Text.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR.Client; using Queue.Display.Models; namespace Queue.Display.Services; // Тонкий клиент Queue.Server — только чтение (GET /api/tickets/board) + подписка на QueueChanged // по SignalR. Табло не выполняет вход и не хранит идентичность сотрудника (см. Queue.OperatorApp // для сравнения — там тот же приём применён к операторскому сценарию с логином). public class QueueApiClient { private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web); private readonly HttpClient _http = new(); private HubConnection? _hubConnection; public string BaseAddress { get; private set; } = "http://localhost:5080"; public event Action? QueueChanged; public void Configure(string baseAddress) { BaseAddress = baseAddress.TrimEnd('/'); _http.BaseAddress = new Uri(BaseAddress); } public async Task ConnectHubAsync() { _hubConnection = new HubConnectionBuilder() .WithUrl($"{BaseAddress}/hubs/queue") .WithAutomaticReconnect() .Build(); _hubConnection.On("QueueChanged", () => QueueChanged?.Invoke()); await _hubConnection.StartAsync(); } public async Task<BoardSnapshotDto?> GetBoardAsync() => await _http.GetFromJsonAsync<BoardSnapshotDto>("/api/tickets/board", JsonOptions); }