Home > Blockchain >  VS Blazor Server App Template: Server to Client SignalR Communication
VS Blazor Server App Template: Server to Client SignalR Communication

Time:06-12

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?

CodePudding user response:

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

  • Related