Client Lifecycle events in ASP.NET Core SignalR
Asked Answered
G

1

18

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?

Gilroy answered 12/7, 2018 at 12:34 Comment(2)
May Be this link could help you : #21927055Sneeze
Thx @AymenRagguem for your comment, but the mentioned SignalR in your linked SO question is a quite old version of SignalR (.NET 4.x era). I was specifically asking for the new .NET Core version of it.Gilroy
L
0

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.

Lapides answered 3/4, 2019 at 22:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.