[backend/signalr] Remove ExampleHub
This commit is contained in:
parent
7a67b8a472
commit
68867aee90
5 changed files with 0 additions and 132 deletions
|
@ -1,12 +0,0 @@
|
|||
using Iceshrimp.Shared.Schemas.SignalR;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Iceshrimp.Backend.SignalR;
|
||||
|
||||
public class ExampleHub : Hub<IExampleHubClient>, IExampleHubServer
|
||||
{
|
||||
public async Task SendMessage(string user, string message)
|
||||
{
|
||||
await Clients.All.ReceiveMessage("SignalR", "ping!");
|
||||
}
|
||||
}
|
|
@ -66,7 +66,6 @@ app.UseCustomMiddleware();
|
|||
|
||||
app.MapControllers();
|
||||
app.MapFallbackToController("/api/{**slug}", "FallbackAction", "Fallback").WithOrder(int.MaxValue - 3);
|
||||
app.MapHub<ExampleHub>("/hubs/example");
|
||||
app.MapHub<StreamingHub>("/hubs/streaming");
|
||||
app.MapRazorPages();
|
||||
app.MapFrontendRoutes("/Shared/FrontendSPA");
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
@page "/hub"
|
||||
@inject NavigationManager Navigation
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<PageTitle>Home</PageTitle>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label>
|
||||
User:
|
||||
<input class="form-control" @bind="_userInput"/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label>
|
||||
Message:
|
||||
<input class="form-control" @bind="_messageInput" size="50"/>
|
||||
</label>
|
||||
</div>
|
||||
<button class="btn btn-primary" @onclick="Send" disabled="@(!IsConnected)">Send</button>
|
||||
|
||||
<hr>
|
||||
|
||||
<ul id="messagesList">
|
||||
@foreach (var message in _messages)
|
||||
{
|
||||
<li>@message</li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
@code {
|
||||
// See Hub.razor.cs
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
using Iceshrimp.Shared.Schemas.SignalR;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using TypedSignalR.Client;
|
||||
|
||||
namespace Iceshrimp.Frontend.Pages;
|
||||
|
||||
public partial class Hub
|
||||
{
|
||||
private IExampleHubServer? _hub;
|
||||
private HubConnection? _hubConnection;
|
||||
private string _messageInput = "";
|
||||
private readonly List<string> _messages = [];
|
||||
private string _userInput = "";
|
||||
|
||||
private bool IsConnected => _hubConnection?.State == HubConnectionState.Connected;
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_hubConnection is not null)
|
||||
{
|
||||
await _hubConnection.DisposeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_hubConnection = new HubConnectionBuilder()
|
||||
.WithUrl(Navigation.ToAbsoluteUri("/hubs/example"))
|
||||
.AddMessagePackProtocol()
|
||||
.Build();
|
||||
|
||||
// This must be in a .razor.cs file for the code generator to work correctly
|
||||
_hub = _hubConnection.CreateHubProxy<IExampleHubServer>();
|
||||
|
||||
//TODO: authentication is done like this:
|
||||
//options => { options.AccessTokenProvider = () => Task.FromResult("the_access_token")!; })
|
||||
|
||||
_hubConnection.Register<IExampleHubClient>(new ExampleHubClient(this));
|
||||
|
||||
await _hubConnection.StartAsync();
|
||||
}
|
||||
|
||||
private async Task Send()
|
||||
{
|
||||
if (_hub is not null)
|
||||
{
|
||||
await _hub.SendMessage(_userInput, _messageInput);
|
||||
}
|
||||
}
|
||||
|
||||
private class ExampleHubClient(Hub page) : IExampleHubClient, IHubConnectionObserver
|
||||
{
|
||||
public Task ReceiveMessage(string user, string message)
|
||||
{
|
||||
var encodedMsg = $"{user}: {message}";
|
||||
page._messages.Add(encodedMsg);
|
||||
page.InvokeAsync(page.StateHasChanged);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task OnClosed(Exception? exception)
|
||||
{
|
||||
return ReceiveMessage("System", "Connection closed.");
|
||||
}
|
||||
|
||||
public Task OnReconnected(string? connectionId)
|
||||
{
|
||||
return ReceiveMessage("System", "Reconnected.");
|
||||
}
|
||||
|
||||
public Task OnReconnecting(Exception? exception)
|
||||
{
|
||||
return ReceiveMessage("System", "Reconnecting...");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
namespace Iceshrimp.Shared.Schemas.SignalR;
|
||||
|
||||
public interface IExampleHubServer
|
||||
{
|
||||
public Task SendMessage(string user, string message);
|
||||
}
|
||||
|
||||
public interface IExampleHubClient
|
||||
{
|
||||
public Task ReceiveMessage(string user, string message);
|
||||
}
|
Loading…
Add table
Reference in a new issue