Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to share signalR hubConnection across multiple pages in Blazor server?

$
0
0

I'm following this tutorial creating a chat app.My chat app has multiple pages with different chatrooms. Every chatroom has the same code, I use this @page "/chat/{roomId:int}" to denote each of the chatrooms.My problem is that I don't want to create a new SignalR connection every time the user goes to another chat (I'm using a proxy, which introduces delays that i want to minimize).But I don't really know how to go about separating the hubConnection from the page, especially how to handle this part of the code _hubConnection.On<string, string>("Broadcast", BroadcastMessage); because it references a method inside this page and I'm not sure how to set this if the hubConnection was in a different file.

I was thinking of either creating a separate service for SignalR or putting the connection into App.razor, but I dont know how to handle hubConnection.On...I was thinking that this should be possible, given no refresh happens when i go to another chatroom.I would appreciate any advice.Thank you.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>