Target specific user in group

爷,独闯天下 提交于 2021-01-07 06:31:52

问题


ASP.NET Core SignalR

I know we can send messages to a group. I know we can send messages to a user. Is there a way to send messages to a user in a group, i.e. the intersection of the previous audiences.

From what I understand: A group is a collection of connections with group name in metadata, and a user is a collection connections with user name in auth claims. A user in a group would be the collection of connections which belong to the specific user and are part of specific group.

Afaik from how SignalR works internally, this should be possible, but it's likely that no such method has been exposed.

The use-case: Say you have chat groups with a bunch of people, and you want to send a specific system message to one of the users in the group. For example, let's say the server needs to randomly select one of the users in the group and send them a secret code for a game, which the others should not know (assume that the server already has a list of all users in a group and that is unchanging, only connections may change). The message should go to the specific user, but not to all of his connections. He may have some other connections which are active for a different chat group, and so we don't want to notify those connections. We only want to target the connections belonging to that user which are currently part of the specific chat group.

I'm using Azure SignalR Service in Serverless Mode with NodeJS Azure Function Apps. Answers for Default server mode in C# would help as well.


回答1:


The solution is to create a group which is a combination of the base group name and the user id (eg: secondaryGroup = group + "::" + user).

Apart from adding the user/connection to the base group, add the user to this secondary group as well (in addition to the base group).

This secondary group would consist of all connections belonging to the user, and which are part of the base group.

To target all users in group - use the base group name.
To target specific user in group - use the secondary group name.

This would significantly increase the number of groups, but if would not create very significant load / performance impact.

See GitHub issue (linked in question comments) for more details.



来源:https://stackoverflow.com/questions/65200015/target-specific-user-in-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!