aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

@aspnet/signalr - make connection id available

Open Nathan-Ryan opened this issue 8 years ago • 3 comments

I have a reactive angular app where its services contain observables to allow components to react to certain events. i.e. saving a form will cause the adjacent index component to reload. This all works reasonably well, until I have added SignalR into the mix to broadcast these same events between clients. Essentially the same services/observables used to perform the intra-client events are now emitting events when the socket receives the respective event too.

The problem i now have is that the components receive two events per action, one raised internally when the http request completes (client service -> obserable -> component), and the other from the socket (controller -> hubcontext -> client hubconnection -> client service -> observable -> component). I need both event sources as I don't want to rely on the socket to perform intra-app communication and it also provides a consistent way, from the subscribing components perspective, to get events.

Ideally I would like to ignore the client who sent the http from getting the signalr message so dont have to do any hacky buffering and grouping on the client app. A good solution would be to include the signalr connection id as a header in the http request which i could then use to filter hubcontext clients.

In the meantime, accessing the connection id via sending an initial message to the client will suffice. Seems odd that the connection id is unavailable client-side. Using groups only works in certain situations.

Appreciate any feedback.

Nathan-Ryan avatar Jul 03 '18 23:07 Nathan-Ryan

Further more, the broadcast via HubContext is targeting a group which the client, who performed the action which the event is for, is a member of. How would I broadcast the event to all members of the group except one?

Nathan-Ryan avatar Jul 04 '18 00:07 Nathan-Ryan

We've been very cautious to avoid exposing the connection ID outside of the server because we don't provide any guarantees that the ID will be unique outside of the specific server on which it was generated.

Having said that, this isn't the first time we've heard this kind of request, so we'll do some thinking on the issue and see if we're able to make the ID public.

In the meantime, I'd suggest hardening your notification logic to be able to detect duplicate notifications like this in order to avoid it.

analogrelay avatar Jul 05 '18 17:07 analogrelay

That has actually been done in the 3.0 wave.

BrennanConroy avatar Jun 10 '19 19:06 BrennanConroy