Hi!
I am trying to make something like customer service chat with signalr.
I am able to use signalr to send message to every client but struggle with getting connectionID value anywhere outside of ChatHub so i could send to induvidual clients.
Here is my controller code
public IActionResult PosaljiPoruku(PorukaVM model)
{
_hubContext.Clients.All.SendAsync("PrimljenaPoruka",model.Poruka );
return PartialView("SubmitFormPartial");
}
my js file
var connection = new signalR.HubConnectionBuilder()
.withUrl("/chatt", {
accessTokenFactory: () => "testing"
})
.build();
connection.on("PrimljenaPoruka", function (poruka) {
});
connection.start().catch(function (err) {
return console.error(err.toString());
});
and my hub code
public class ChatHub : Hub
{
public string GetConnectionId()
{
return Context.ConnectionId;
}
}
What I have tried:
Tried some stuff that doesn't work like creating ChatHub instance in controller, accesing GetConnectionId() with ihubContext...
Saw somewhere that this code could be used to access connectionID on client side but not sure how to call it?
I am really stuck on this for some time now any help is really appreciated!!!!!
Thanks for reading and trying to help!