littleshop/LittleShop/Hubs/NotificationHub.cs
SysAdmin be91b3efd7 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
2025-10-06 17:57:10 +01:00

40 lines
1.1 KiB
C#

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
});
}
}