Skip to content

Commit

Permalink
fix for extra signalr handlers firing
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Feb 24, 2024
1 parent 2b94993 commit 322b2e1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/web/Jordnaer/SignalR/AuthenticatedSignalRClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected AuthenticatedSignalRClientBase(
}

HubConnection = new HubConnectionBuilder()
.WithUrl(navigationManager.ToAbsoluteUri(hubPath),
.WithUrl(navigationManager.ToAbsoluteUri(hubPath),
options => options.Cookies = cookieContainer)
.WithAutomaticReconnect()
.Build();
Expand All @@ -48,13 +48,17 @@ public async Task StartAsync(CancellationToken cancellationToken = default)

public async Task StopAsync(CancellationToken cancellationToken = default)
{
if (Started && HubConnection is not null)
if (HubConnection?.State is HubConnectionState.Connected)
{
_logger.LogDebug("Stopping SignalR Client");
await HubConnection.StopAsync(cancellationToken);
Started = false;
_logger.LogDebug("SignalR Client stopped");
}
else
{
_logger.LogDebug("Stop SignalR was called, but the Connection is currently in the {State} state. " +
"No further action is taken.", HubConnection?.State);
}
}

public async ValueTask DisposeAsync()
Expand Down

0 comments on commit 322b2e1

Please sign in to comment.