简体   繁体   English

ASP.NET Core SignalR中的客户端生命周期事件

[英]Client Lifecycle events in ASP.NET Core SignalR

I'm currently upgrading a project from ASP.NET SignalR 2.2.3 (OWIN) to ASP.NET Core SignalR 1.0.2 (Kestrel). 我目前正在将一个项目从ASP.NET SignalR 2.2.3 (OWIN)升级到ASP.NET Core SignalR 1.0.2 (Kestrel)。

SignalR 2.2.3 supported several client sided lifetime events like reconnecting , connectionSlow , stateChanged , ... . SignalR 2.2.3支持多个客户端生命周期事件,reconnectingconnectionSlowstateChanged ,.... Our javascript client used those events and displayed something like "Reconnecting" or "Connection is currently slow". 我们的javascript客户端使用这些事件并显示类似“重新连接”或“连接当前很慢”的内容。

Are there or will there be equivalents in ASP.NET Core SignalR? 是否存在或将存在ASP.NET Core SignalR中的等价物? I only found two lifetime events so far: 到目前为止我只发现了两个终生事件:

let c = new signalR.HubConnectionBuilder().("/signalR");
c.connection.onClose(function(error) {});
c.connection.onReceive(function(data) {});

I also saw this question , but the user only asked for the onClose event. 我也看到了这个问题 ,但是用户只询问了onClose事件。

And no, I'm not looking for server sided lifetime events . 不,我不是在寻找服务器端的终身事件

Update - Reconnect events 更新 - 重新连接事件

Okay since there is no reconnect (yet?) according to the docs and this Github issue , I'm okay with the missing Reconnecting and Reconnected . 好吧,因为根据文档和这个Github问题 ,没有重新连接(但是?),我很好,缺少ReconnectingReconnected But what about connectionSlow , starting and stateChanged ? 但是connectionSlowstartingstateChanged呢?

Looks like currently there are only 2 states for a HubConnection : 看起来目前HubConnection只有2种状态:

  • Disconnected 断开的
  • Connected 连接的

Those states are exposed through a state property in the connection but there are no states for anything else. 这些州通过连接中的state财产暴露,但没有其他任何状态。

However, there is an ILogger instance that is used prominently throughout the standard operations. 但是,有一个ILogger实例在整个标准操作中占据显着位置。 A custom ILogger can be provided to the HubConnectionBuilder via the configureLogging method. 可以通过configureLogging方法将自定义ILogger提供给HubConnectionBuilder You can use your custom logger to capture all the individual events and react accordingly. 您可以使用自定义记录器捕获所有单个事件并做出相应的反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM