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:
39
LittleShop/Hubs/NotificationHub.cs
Normal file
39
LittleShop/Hubs/NotificationHub.cs
Normal 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
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user