SignalR 获取用户所在的组
SignalR get groups user is in
我正在制作一个 1 对 1 的聊天应用程序,我正在为此使用群组。
您加入了 Groups.Add(Context.ConnectionId, roomName)
的群组。
每当发送消息时,我都想打电话给
Clients.Group(roomName).addMessage(username, text);
但是为此我需要一个 roomName
变量。如何检索用户加入的房间?
没有特定的 api 来管理组,您需要自己保存此信息。
There is a related question here
如需更完整的信息,您可以查看 Signalr 主题
Working with Groups in SignalR
Groups in SignalR provide a method for broadcasting messages to
specified subsets of connected clients. A group can have any number of
clients, and a client can be a member of any number of groups. You
don't have to explicitly create groups. In effect, a group is
automatically created the first time you specify its name in a call to
Groups.Add, and it is deleted when you remove the last connection from
membership in it. For an introduction to using groups, see How to
manage group membership from the Hub class in the Hubs API - Server
Guide.
如何从中心管理群组成员class
Groups in SignalR provide a method for broadcasting messages to
specified subsets of connected clients. A group can have any number of
clients, and a client can be a member of any number of groups.
To manage group membership, use the Add and Remove methods provided by
the Groups property of the Hub class.
此外
SignalR tracks connections, not users, so if you want a user to be in
the same group every time the user establishes a connection, you have
to call Groups.Add every time the user establishes a new connection.
简而言之,你必须自己做。 Working with Groups in SignalR 中有一个示例,说明如何将用户和组信息保存到数据库中。
我正在制作一个 1 对 1 的聊天应用程序,我正在为此使用群组。
您加入了 Groups.Add(Context.ConnectionId, roomName)
的群组。
每当发送消息时,我都想打电话给
Clients.Group(roomName).addMessage(username, text);
但是为此我需要一个 roomName
变量。如何检索用户加入的房间?
没有特定的 api 来管理组,您需要自己保存此信息。
There is a related question here
如需更完整的信息,您可以查看 Signalr 主题
Working with Groups in SignalR
Groups in SignalR provide a method for broadcasting messages to specified subsets of connected clients. A group can have any number of clients, and a client can be a member of any number of groups. You don't have to explicitly create groups. In effect, a group is automatically created the first time you specify its name in a call to Groups.Add, and it is deleted when you remove the last connection from membership in it. For an introduction to using groups, see How to manage group membership from the Hub class in the Hubs API - Server Guide.
如何从中心管理群组成员class
Groups in SignalR provide a method for broadcasting messages to specified subsets of connected clients. A group can have any number of clients, and a client can be a member of any number of groups.
To manage group membership, use the Add and Remove methods provided by the Groups property of the Hub class.
此外
SignalR tracks connections, not users, so if you want a user to be in the same group every time the user establishes a connection, you have to call Groups.Add every time the user establishes a new connection.
简而言之,你必须自己做。 Working with Groups in SignalR 中有一个示例,说明如何将用户和组信息保存到数据库中。