Search code examples
asp.net-coresignalrblazor

VS Blazor Server App Template: Server to Client SignalR Communication


Since blazer server already establish a signalr connection with it's client, without creating new signalr connection is there any simple way for server to tap in blazorhub and push notification to client?


Solution

  • Each time you call StateHasChanged the DOM is updated if needed.

    You can trigger this update with a timer or with some other events.

    public async Task NewMessageAsync(Message message, CancellationToken cancel)
    {
          if (_tenant.MessageMatchTemplate(message, _template))
          {
              messagesDisplayList.Add(message.data);
              await InvokeAsync(StateHasChanged);
          }
    }
    

    Full chat example here

    https://github.com/iso8859/ThreadMessaging