在第二个客户端连接

时间:2017-09-20 17:56:23

标签: javascript asp.net signalr

我正在使用

  • autofac.signalr2 v4.0.0
  • microsoft.aspnet.signalr 2.2.2
  • .net framework 4.6.1

使用owinstartup将IObservable传送到我的集线器 一切都很好(AFAICT)

但是在我的JavaScript和.NET客户端中,我发现了一个问题:

  1. 启动第一个客户端 - 成功启动()。没有消息(没有成功调用我的javascript回调)
  2. 启动第二个客户端 - 现在第一个客户端开始工作,第二个客户端没有消息
  3. 启动第三个客户端 - 现在是第一个,第二个客户端工作,第三个没有消息
  4. 这是第二个客户发送的消息(当它不工作时)

    Sending outgoing message. Connection id: 12e1a17f-5f48-4e66-aece-166957d645cf, transport: WebSocketTransport, 
    message: {"C":"d-142AA7E2-B,0|J,0|K,2|E,B3","M":[]}
    

    然后连接第三个客户端 第二个客户得到这个(这确实有效):

    Sending outgoing message. Connection id: 12e1a17f-5f48-4e66-aece-166957d645cf, transport: WebSocketTransport, 
    message: {"C":"d-142AA7E2-B,0\|J,0\|K,2\|E,B4","M":[{"H":"StreamHub","M":"receiveCallCanceled","A":[{"BaseTime":717006987,"BedIndex":2,"CallIndex":4,"EscalationIndex":5,"CallPlacedUTCTime":"2017-09-20T04:52:12.9831051Z","ServerSentUTCTime":"2017-09-20T04:52:15.4492756Z","FacilityGuid":"11111111-1bad-f00d-1111-111111111111","DialString":"1*111"}]}]}
    

    注意connectionid是一样的 似乎" M":[]是客户端没有收到回调的原因。是什么造成的?

    StartupOwin.cs

    builder.Register(c =>
                {
                    try
                    {
                        return new PCConsoleStreamObservable(c.Resolve<IClientGrainFactory>(),
                            c.Resolve<IFacilityConfigurationClient>());
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.TraceError($"{ex}");
                        throw;
                    }
                })
                .As<IObservable<XXXClientBase>>()
                .InstancePerLifetimeScope()
                .AutoActivate();
    
    builder.RegisterHubs(typeof(WebApiApplication).Assembly);
    
                var hubConfiguration = new HubConfiguration()
            {
                //EnableJavaScriptProxies = true,
                //EnableJSONP = false,
                EnableDetailedErrors = true,
                Resolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(container)
            };
    
            app.UseAutofacMiddleware(container);
    
            app.UseAutofacWebApi(httpConfig);
            app.UseAutofacMvc();
            app.UseWebApi(httpConfig);
    
            app.Map("/signalr", map =>
            {
                map.RunSignalR(hubConfiguration);
            });
    

    StreamHub.cs

    public class StreamHub : Hub
    {
        private readonly IObservable<XXXClientBase> _observer;
    
        public StreamHub(IObservable<XXXClientBase> observer) : base()
        {
            this._observer = observer;
        }
    

1 个答案:

答案 0 :(得分:0)

群组似乎是问题

        Clients
            .OthersInGroup(SignalRNameHelpers.GenerateStreamHubName(subscription))
            .receiveCallPlaced(outbound);

删除该群组并发送至All修复此问题

        Clients
            .All 
            .receiveCallPlaced(outbound);