简体   繁体   中英

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).

SignalR 2.2.3 supported several client sided lifetime events like reconnecting , connectionSlow , stateChanged , ... . Our javascript client used those events and displayed something like "Reconnecting" or "Connection is currently slow".

Are there or will there be equivalents in 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.

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 . But what about connectionSlow , starting and stateChanged ?

Looks like currently there are only 2 states for a HubConnection :

  • Disconnected
  • Connected

Those states are exposed through a state property in the connection but there are no states for anything else.

However, there is an ILogger instance that is used prominently throughout the standard operations. A custom ILogger can be provided to the HubConnectionBuilder via the configureLogging method. You can use your custom logger to capture all the individual events and react accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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