Merge branch 'main' into feature-join-whiteboard-by-code

# Conflicts:
#	dotnet/AipsRT/Hubs/WhiteboardHub.cs
#	dotnet/AipsRT/Services/Interfaces/IMessagingService.cs
#	front/src/stores/whiteboard.ts
This commit is contained in:
2026-03-07 21:40:09 +01:00
18 changed files with 167 additions and 15 deletions

View File

@@ -31,7 +31,7 @@ public class WhiteboardHub : Hub
{
if (!_whiteboardManager.WhiteboardExists(whiteboardId))
{
await _whiteboardManager.AddWhiteboard(whiteboardId);
await _whiteboardManager.LoadWhiteboard(whiteboardId);
}
await Groups.AddToGroupAsync(Context.ConnectionId, whiteboardId.ToString());
@@ -210,6 +210,6 @@ public class WhiteboardHub : Hub
await MoveShape(moveShape);
await _messagingService.MoveShape(moveShape);
await _messagingService.MoveShape(CurrentWhiteboard.WhiteboardId, moveShape);
}
}

View File

@@ -14,7 +14,7 @@ public class WhiteboardManager
_scopeFactory = scopeFactory;
}
public async Task AddWhiteboard(Guid whiteboardId)
public async Task LoadWhiteboard(Guid whiteboardId)
{
var getWhiteboardService = _scopeFactory.CreateScope().ServiceProvider.GetRequiredService<GetWhiteboardService>();
var whiteboard = await getWhiteboardService.GetWhiteboard(whiteboardId);

View File

@@ -1,3 +1,4 @@
using AipsCore.Application.Common.Message.ErrorMessage;
using AipsCore.Infrastructure.DI;
using AipsRT.Hubs;
using AipsRT.Model.Whiteboard;
@@ -15,6 +16,10 @@ builder.Configuration.AddEnvironmentVariables();
builder.Services.AddSignalR();
builder.Services.AddAips(builder.Configuration);
builder.Services.AddAipsMessageHandlers();
builder.Services.AddSingleton<IErrorMessageHandleStrategy, RtErrorHandleStrategy>();
builder.Services.AddHostedService<ErrorSubscriberBackgroundService>();
builder.Services.AddScoped<GetWhiteboardService>();
builder.Services.AddSingleton<WhiteboardManager>();

View File

@@ -0,0 +1,25 @@
using AipsCore.Application.Abstract;
using AipsCore.Application.Abstract.MessageBroking;
using AipsCore.Application.Common.Message.ErrorMessage;
namespace AipsRT.Services;
public class ErrorSubscriberBackgroundService : BackgroundService
{
private readonly IMessageSubscriber _subscriber;
private readonly IDispatcher _dispatcher;
public ErrorSubscriberBackgroundService(IMessageSubscriber subscriber, IDispatcher dispatcher)
{
_subscriber = subscriber;
_dispatcher = dispatcher;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _subscriber.SubscribeAsync<ErrorMessage>(async (errorMessage, ct) =>
{
await _dispatcher.Execute(errorMessage, ct);
});
}
}

View File

@@ -12,8 +12,8 @@ public interface IMessagingService
Task CreatedArrow(Guid whiteboardId, Arrow arrow);
Task CreateLine(Guid whiteboardId, Line line);
Task CreateTextShape(Guid whiteboardId, TextShape textShape);
Task MoveShape(MoveShapeCommand moveShape);
Task MoveShape(Guid whiteboardId, MoveShapeCommand moveShape);
Task AcceptedUser(AcceptUserRequestToJoinCommand command);
Task RejectedUser(RejectUserRequestToJoinCommand command);

View File

@@ -99,9 +99,9 @@ public class MessagingService : IMessagingService
await _messagePublisher.PublishAsync(message);
}
public async Task MoveShape(MoveShapeCommand moveShape)
public async Task MoveShape(Guid whiteboardId, MoveShapeCommand moveShape)
{
var message = new MoveShapeMessage(moveShape);
var message = new MoveShapeMessage(whiteboardId, moveShape);
await _messagePublisher.PublishAsync(message);
}

View File

@@ -0,0 +1,29 @@
using AipsCore.Application.Common.Message.ErrorMessage;
using AipsRT.Hubs;
using AipsRT.Model.Whiteboard;
using Microsoft.AspNetCore.SignalR;
namespace AipsRT.Services;
public class RtErrorHandleStrategy : IErrorMessageHandleStrategy
{
private readonly IHubContext<WhiteboardHub> _hubContext;
private readonly WhiteboardManager _whiteboardManager;
public RtErrorHandleStrategy(IHubContext<WhiteboardHub> hubContext, WhiteboardManager whiteboardManager)
{
_hubContext = hubContext;
_whiteboardManager = whiteboardManager;
}
public async Task Handle(ErrorMessage message, CancellationToken cancellationToken)
{
await _whiteboardManager.LoadWhiteboard(message.WhiteboardId);
var whiteboard = _whiteboardManager.GetWhiteboard(message.WhiteboardId)!;
await _hubContext.Clients
.Group(whiteboard.WhiteboardId.ToString())
.SendAsync("InitWhiteboard", whiteboard, cancellationToken);
}
}