Add: SignalR real-time notifications for admin panel

- Created NotificationHub for instant browser notifications
- Updated CryptoPaymentService to broadcast via SignalR
- Added JavaScript client with toast notifications
- Works with custom SSL certificates (no FCM dependency)
- Automatic reconnection with exponential backoff
- Notification sound and visual indicators
- Bypasses all Web Push SSL certificate issues
This commit is contained in:
2025-10-06 17:57:10 +01:00
parent b8390162d9
commit be91b3efd7
5 changed files with 272 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
namespace LittleShop.Hubs;
[Authorize(Roles = "Admin")]
public class NotificationHub : Hub
{
private readonly ILogger<NotificationHub> _logger;
public NotificationHub(ILogger<NotificationHub> logger)
{
_logger = logger;
}
public override async Task OnConnectedAsync()
{
_logger.LogInformation("Admin user connected to notification hub: {ConnectionId}", Context.ConnectionId);
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception? exception)
{
_logger.LogInformation("Admin user disconnected from notification hub: {ConnectionId}", Context.ConnectionId);
await base.OnDisconnectedAsync(exception);
}
// Client can call this to test notifications
public async Task SendTestNotification()
{
await Clients.Caller.SendAsync("ReceiveNotification", new
{
title = "Test Notification",
message = "This is a test notification from SignalR!",
type = "info",
timestamp = DateTime.UtcNow
});
}
}