我曾经使用以下代码实现自己的连接id生成器:
public class MyConnectionFactory : IConnectionIdGenerator
{
public string GenerateConnectionId(IRequest request)
{
return MyUserManager.Instance.CurrentUserID.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
这在SignalR 0.5.3版本中运行良好,但在更新到SignalR 1.0rc2版本后,找不到命名空间或类名.另外,我无法找到任何音符这一重大更改这里https://github.com/SignalR/SignalR/blob/master/ReleaseNotes.md你能帮我解决这个问题?
这确实消失了,并且没有直接替换,因为您现在应该手动执行用户/连接映射.
我使用HubPipelineModule解决了这个问题,并为该用户的所有连接设置了一个组.
public class AuthenticationHubPipelineModule : HubPipelineModule
{
protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
{
var id = MyUserManager.Instance.CurrentUserID.ToString();
context.Hub.Groups.Add(context.Hub.Context.ConnectionId, id);
return base.OnBeforeIncoming(context);
}
}
Run Code Online (Sandbox Code Playgroud)
当您想要与用户联系时,您可以将其发送到该组,如下所示:
var context = GlobalHost.ConnectionManager.GetHubContext<YourHub>();
context.Clients.Group(userId).yourCallbackMethod();
Run Code Online (Sandbox Code Playgroud)
希望这有帮助,伊夫
| 归档时间: |
|
| 查看次数: |
1136 次 |
| 最近记录: |