Reputation: 379
If i have the following scenario for a connected user
`clientwebsiteA -> hubA -> groupA -> id:[email protected]`
and
`cliebtwebsiteB -> hubA -> groupB -> id:[email protected]`
A user george is connected logged in to 2 different websites clients(at the same time), each of which connects to a signalr hubA (note: hub a is a single webapp , hosting multiple hubs).
If I wanted to only send a message to hubA.groupA.id:@george.email.com.
is this possible?
or if i send a message to
`clients.User("[email protected]")`
will he get the message on both of his connections?
I was hoping to see a method like
clients.Group("A").User("[email protected]").SayHello()
or clients.UserInGroup("A",id:[email protected]").SayHello()
if this isn't possible can it be achieved if I use 2 different hubs( with 2 different routes)
M$ says that multiple hubs share the same connection to the signalr sever. https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server#multiplehubs
Upvotes: 0
Views: 223
Reputation: 27793
If I wanted to only send a message to hubA.groupA.id:@george.email.com. is this possible?
If user george connect to same hub server (hubA) from two different client apps (clientwebsiteA and clientwebsiteB), user george would establish two connections (with two different ConnectionIds) to hub server. Under this scenario, to send message(s) to that specific client user george (from clientwebsiteA), you can mapping user to connections (implement user-site-connectionId mapping) on hub server, so that you can get connectionId based on user and site, then send message to specific user with connectionId, like below.
await Clients.Client(connectionId_here).SendAsync("SayHello");
Or you can implement and use single-user group.
//join group while george connect from site A
await Groups.AddToGroupAsync(connectionId_here, "SiteAGroupAGeorge");
then you can send a message to that group when you want to reach only that user.
await Clients.Group("SiteAGroupAGeorge").SendAsync("SayHello");
Upvotes: 1