RT state managment and rectangle support
This commit is contained in:
1
dotnet/AipsRT/Hubs/Dtos/AddRectangleDto.cs
Normal file
1
dotnet/AipsRT/Hubs/Dtos/AddRectangleDto.cs
Normal file
@@ -0,0 +1 @@
|
||||
namespace AipsRT.Hubs.Dtos;
|
||||
@@ -1,9 +1,19 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AipsRT.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class TestHub : Hub
|
||||
{
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
Console.WriteLine($"LOOOOOOOOOG: [{Context.UserIdentifier}] User identifier connected");
|
||||
Console.WriteLine($"LOOOOOG222: [{Context.User?.Identity?.Name}] User identity name connected");
|
||||
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
public async Task SendText(string text)
|
||||
{
|
||||
await Clients.All.SendAsync("ReceiveText", text);
|
||||
|
||||
49
dotnet/AipsRT/Hubs/WhiteboardHub.cs
Normal file
49
dotnet/AipsRT/Hubs/WhiteboardHub.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using AipsRT.Model.Whiteboard;
|
||||
using AipsRT.Model.Whiteboard.Shapes;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AipsRT.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class WhiteboardHub : Hub
|
||||
{
|
||||
private readonly WhiteboardManager _whiteboardManager;
|
||||
|
||||
public WhiteboardHub(WhiteboardManager whiteboardManager)
|
||||
{
|
||||
_whiteboardManager = whiteboardManager;
|
||||
}
|
||||
|
||||
public async Task JoinWhiteboard(Guid whiteboardId)
|
||||
{
|
||||
if (!_whiteboardManager.WhiteboardExists(whiteboardId))
|
||||
await _whiteboardManager.AddWhiteboard(whiteboardId);
|
||||
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, whiteboardId.ToString());
|
||||
|
||||
var state = _whiteboardManager.GetWhiteboard(whiteboardId)!;
|
||||
|
||||
_whiteboardManager.AddUserToWhiteboard(Guid.Parse(Context.UserIdentifier!), whiteboardId);
|
||||
|
||||
await Clients.Caller.SendAsync("InitWhiteboard", state);
|
||||
await Clients.GroupExcept(whiteboardId.ToString(), Context.ConnectionId)
|
||||
.SendAsync("Joined", Context.UserIdentifier!);
|
||||
}
|
||||
|
||||
public async Task LeaveWhiteboard(Guid whiteboardId)
|
||||
{
|
||||
await Clients.GroupExcept(whiteboardId.ToString(), Context.ConnectionId)
|
||||
.SendAsync("Leaved", Context.UserIdentifier!);
|
||||
}
|
||||
|
||||
public async Task AddRectangle(Rectangle rectangle)
|
||||
{
|
||||
var whiteboard = _whiteboardManager.GetWhiteboardForUser(Guid.Parse(Context.UserIdentifier!))!;
|
||||
|
||||
whiteboard.AddRectangle(rectangle);
|
||||
|
||||
await Clients.GroupExcept(whiteboard.WhiteboardId.ToString(), Context.ConnectionId)
|
||||
.SendAsync("AddedRectangle", rectangle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user