Search code examples
signalrblazor

How to display SignalR Notification when Browser is in Minimize Mode


I have created notification apps using SignalR in Blazor Web Application.It works fine as per our requirement, but when I minimize Web Browser then the notification Toast message showing within that application (in minimize mode).I would like to know how to display notification Toast message when browser is minimize (Notification Toast should display in task bar)

C# Code:-

protected async override Task OnInitializedAsync()
{
    base.OnInitialized();
   
    bpmHubConnection = new HubConnectionBuilder()
            .WithUrl(ONEERP.Web.Models.SessionManager.BpmApiBaseAddress + "hubs/BPMBroadCastHub")
            .Build();

    bpmHubConnection.On<int, int, string, string>("SendNotification", (userGroupID, userID, name, message) =>
    {
        if (SessionManager.UserID == userID)
        {
            CallLoadNotification();
            StateHasChanged();
        }
    });

}

.razor Code :-

 <SfToast ID="toastNotification" ShowCloseButton="true" @ref="ToastNotificationObj" Title="Notification" Content="@ToastNotificationContent" CssClass="@ToastNotificationStyle" Timeout=@ConstantClass.ToastTimeout Icon="e-meeting">
            <ToastPosition X="Right" Y="Bottom"></ToastPosition>
        </SfToast>

Solution

  • Technically what you're trying to do is impossible. You do have one option, using Browser notifications (see link below). Rather than using toast notifications, you could "push" a notification to the browser. The user will have to allow it, but it sounds like you're developing something for a relatively small set of users.

    https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API