From 5df45ff6fb9881e43d80acbe363e579cd5632c88 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Thu, 12 Jan 2023 15:20:15 +0100 Subject: [PATCH 01/12] added withServerTimeout and withKeepAliveInterval to HubConnectionBuilder ts client --- .../clients/ts/signalr/src/HubConnection.ts | 31 ++++++++++++++++--- .../ts/signalr/src/HubConnectionBuilder.ts | 31 ++++++++++++++++++- .../tests/HubConnectionBuilder.test.ts | 22 +++++++++++++ 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/src/SignalR/clients/ts/signalr/src/HubConnection.ts b/src/SignalR/clients/ts/signalr/src/HubConnection.ts index b257ec5eafa9..ff4a9e957f85 100644 --- a/src/SignalR/clients/ts/signalr/src/HubConnection.ts +++ b/src/SignalR/clients/ts/signalr/src/HubConnection.ts @@ -92,17 +92,38 @@ export class HubConnection { // create method that can be used by HubConnectionBuilder. An "internal" constructor would just // be stripped away and the '.d.ts' file would have no constructor, which is interpreted as a // public parameter-less constructor. - public static create(connection: IConnection, logger: ILogger, protocol: IHubProtocol, reconnectPolicy?: IRetryPolicy): HubConnection { - return new HubConnection(connection, logger, protocol, reconnectPolicy); + public static create( + connection: IConnection, + logger: ILogger, + protocol: IHubProtocol, + reconnectPolicy?: IRetryPolicy, + serverTimeoutInMilliseconds?: number, + keepAliveIntervalInMilliseconds?: number): HubConnection { + return new HubConnection(connection, logger, protocol, reconnectPolicy, serverTimeoutInMilliseconds, keepAliveIntervalInMilliseconds); } - private constructor(connection: IConnection, logger: ILogger, protocol: IHubProtocol, reconnectPolicy?: IRetryPolicy) { + private constructor( + connection: IConnection, + logger: ILogger, + protocol: IHubProtocol, + reconnectPolicy?: IRetryPolicy, + serverTimeoutInMilliseconds?: number, + keepAliveIntervalInMilliseconds?: number) { Arg.isRequired(connection, "connection"); Arg.isRequired(logger, "logger"); Arg.isRequired(protocol, "protocol"); - this.serverTimeoutInMilliseconds = DEFAULT_TIMEOUT_IN_MS; - this.keepAliveIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS; + if (serverTimeoutInMilliseconds !== undefined) { + this.serverTimeoutInMilliseconds = serverTimeoutInMilliseconds; + } else { + this.serverTimeoutInMilliseconds = DEFAULT_TIMEOUT_IN_MS; + } + + if (keepAliveIntervalInMilliseconds !== undefined) { + this.keepAliveIntervalInMilliseconds = keepAliveIntervalInMilliseconds; + } else { + this.keepAliveIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS; + } this._logger = logger; this._protocol = protocol; diff --git a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts index 2cf4e09a3dbf..3353cb19d117 100644 --- a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts +++ b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts @@ -39,6 +39,9 @@ function parseLogLevel(name: string): LogLevel { /** A builder for configuring {@link @microsoft/signalr.HubConnection} instances. */ export class HubConnectionBuilder { + private _serverTimeoutInMilliseconds?: number; + private _keepAliveIntervalInMilliseconds ?: number; + /** @internal */ public protocol?: IHubProtocol; /** @internal */ @@ -183,6 +186,30 @@ export class HubConnectionBuilder { return this; } + /** Configures serverTimeoutInMilliseconds for the {@link @microsoft/signalr.HubConnection}. + * + * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining. + */ + public withServerTimeout(milliseconds: number): HubConnectionBuilder{ + Arg.isRequired(milliseconds, "milliseconds"); + + this._serverTimeoutInMilliseconds = milliseconds; + + return this; + } + + /** Configures keepAliveIntervalInMilliseconds for the {@link @microsoft/signalr.HubConnection}. + * + * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining. + */ + public withKeepAliveInterval(milliseconds: number): HubConnectionBuilder{ + Arg.isRequired(milliseconds, "milliseconds"); + + this._keepAliveIntervalInMilliseconds = milliseconds; + + return this; + } + /** Creates a {@link @microsoft/signalr.HubConnection} from the configuration options specified in this builder. * * @returns {HubConnection} The configured {@link @microsoft/signalr.HubConnection}. @@ -208,7 +235,9 @@ export class HubConnectionBuilder { connection, this.logger || NullLogger.instance, this.protocol || new JsonHubProtocol(), - this.reconnectPolicy); + this.reconnectPolicy, + this._serverTimeoutInMilliseconds, + this._keepAliveIntervalInMilliseconds); } } diff --git a/src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts b/src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts index d342038f2a59..a04e00e1259c 100644 --- a/src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts +++ b/src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts @@ -384,6 +384,28 @@ describe("HubConnectionBuilder", () => { expect(builder.reconnectPolicy!.nextRetryDelayInMilliseconds(retryContextFinal)).toBe(null); }); + + it("can configure serverTimeoutInMilliseconds for HubConnection", async () => { + const milliseconds = 60000; + + const connection = createConnectionBuilder() + .withUrl("http://example.com") + .withServerTimeout(milliseconds) + .build(); + + expect(connection.serverTimeoutInMilliseconds).toBe(milliseconds); + }); + + it("can configure keepAliveIntervalInMilliseconds for HubConnection", async () => { + const milliseconds = 60000; + + const connection = createConnectionBuilder() + .withUrl("http://example.com") + .withKeepAliveInterval(milliseconds) + .build(); + + expect(connection.keepAliveIntervalInMilliseconds).toBe(milliseconds); + }); }); class CaptureLogger implements ILogger { From 80caba8fd4c4df10e473029a2aab57592c5eb875 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Thu, 12 Jan 2023 20:17:37 +0100 Subject: [PATCH 02/12] Added WithServerTimeout and WithKeepAliveInterval to HubConnectionBuilder for csharp client --- .../csharp/Client.Core/src/HubConnection.cs | 17 ++++++++++++ .../src/HubConnectionBuilderExtensions.cs | 24 +++++++++++++++++ .../Client.Core/src/HubConnectionOptions.cs | 26 +++++++++++++++++++ .../Client.Core/src/PublicAPI.Unshipped.txt | 8 ++++++ .../UnitTests/HubConnectionBuilderTests.cs | 26 +++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs index ae2216913683..d036d42ce1a9 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs @@ -21,8 +21,10 @@ using Microsoft.AspNetCore.SignalR.Client.Internal; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Protocol; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.SignalR.Client; @@ -226,6 +228,21 @@ public HubConnection(IConnectionFactory connectionFactory, _state = new ReconnectingConnectionState(_logger); _logScope = new ConnectionLogScope(); + + var options = serviceProvider.GetService>(); + + if (options != null) + { + if (options.Value.ServerTimeout.HasValue) + { + ServerTimeout = options.Value.ServerTimeout.Value; + } + + if (options.Value.KeepAliveInterval.HasValue) + { + KeepAliveInterval = options.Value.KeepAliveInterval.Value; + } + } } /// diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs index 5979127fa4e4..8c48c2ef922f 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs @@ -63,4 +63,28 @@ public static IHubConnectionBuilder WithAutomaticReconnect(this IHubConnectionBu hubConnectionBuilder.Services.AddSingleton(retryPolicy); return hubConnectionBuilder; } + + /// + /// Configures ServerTimeout for the . + /// + /// The to configure. + /// ServerTimeout for the . + /// The same instance of the for chaining. + public static IHubConnectionBuilder WithServerTimeout(this IHubConnectionBuilder hubConnectionBuilder, TimeSpan timeout) + { + hubConnectionBuilder.Services.Configure(o => o.ServerTimeout = timeout); + return hubConnectionBuilder; + } + + /// + /// Configures KeepAliveInterval for the . + /// + /// The to configure. + /// KeepAliveInterval for the . + /// The same instance of the for chaining. + public static IHubConnectionBuilder WithKeepAliveInterval(this IHubConnectionBuilder hubConnectionBuilder, TimeSpan timeout) + { + hubConnectionBuilder.Services.Configure(o => o.KeepAliveInterval = timeout); + return hubConnectionBuilder; + } } diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs new file mode 100644 index 000000000000..6fde0dab2b0d --- /dev/null +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.SignalR.Client; + +/// +/// Configures timeouts for the . +/// +public class HubConnectionOptions +{ + /// + /// Configures ServerTimeout for the . + /// + public TimeSpan? ServerTimeout { get; set; } + + /// + /// Configures KeepAliveInterval for the . + /// + public TimeSpan? KeepAliveInterval { get; set; } +} diff --git a/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt b/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt index 40077fde5c02..50f713bafeaa 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt +++ b/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt @@ -1,4 +1,12 @@ #nullable enable +Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions +Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.HubConnectionOptions() -> void +Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.KeepAliveInterval.get -> System.TimeSpan? +Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.KeepAliveInterval.set -> void +Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.ServerTimeout.get -> System.TimeSpan? +Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.ServerTimeout.set -> void +static Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithKeepAliveInterval(this Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! hubConnectionBuilder, System.TimeSpan timeout) -> Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! +static Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithServerTimeout(this Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! hubConnectionBuilder, System.TimeSpan timeout) -> Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! static Microsoft.AspNetCore.SignalR.Client.HubConnectionExtensions.On(this Microsoft.AspNetCore.SignalR.Client.HubConnection! hubConnection, string! methodName, System.Func!>! handler) -> System.IDisposable! static Microsoft.AspNetCore.SignalR.Client.HubConnectionExtensions.On(this Microsoft.AspNetCore.SignalR.Client.HubConnection! hubConnection, string! methodName, System.Func! handler) -> System.IDisposable! static Microsoft.AspNetCore.SignalR.Client.HubConnectionExtensions.On(this Microsoft.AspNetCore.SignalR.Client.HubConnection! hubConnection, string! methodName, System.Func!>! handler) -> System.IDisposable! diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionBuilderTests.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionBuilderTests.cs index f9473ae9a1b5..6768ed452f46 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionBuilderTests.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionBuilderTests.cs @@ -77,4 +77,30 @@ public void AddMessagePackProtocolSetsHubProtocolToMsgPack() Assert.IsType(serviceProvider.GetService()); } + + [Fact] + public void CanConfigureServerTimeout() + { + var serverTimeout = TimeSpan.FromMinutes(1); + var builder = new HubConnectionBuilder(); + builder.WithUrl("http://example.com") + .WithServerTimeout(serverTimeout); + + var connection = builder.Build(); + + Assert.Equal(serverTimeout, connection.ServerTimeout); + } + + [Fact] + public void CanConfigureKeepAliveInterval() + { + var keepAliveInterval = TimeSpan.FromMinutes(1); + var builder = new HubConnectionBuilder(); + builder.WithUrl("http://example.com") + .WithKeepAliveInterval(keepAliveInterval); + + var connection = builder.Build(); + + Assert.Equal(keepAliveInterval, connection.KeepAliveInterval); + } } From a5a380c87581b76837d62b5b913899438c58392b Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Fri, 13 Jan 2023 15:18:52 +0100 Subject: [PATCH 03/12] make HubConnectionOptions internal --- .../clients/csharp/Client.Core/src/HubConnectionOptions.cs | 2 +- .../clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs index 6fde0dab2b0d..1fa320b2c081 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.SignalR.Client; /// /// Configures timeouts for the . /// -public class HubConnectionOptions +internal class HubConnectionOptions { /// /// Configures ServerTimeout for the . diff --git a/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt b/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt index 50f713bafeaa..41d409ecba49 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt +++ b/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt @@ -1,10 +1,4 @@ #nullable enable -Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions -Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.HubConnectionOptions() -> void -Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.KeepAliveInterval.get -> System.TimeSpan? -Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.KeepAliveInterval.set -> void -Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.ServerTimeout.get -> System.TimeSpan? -Microsoft.AspNetCore.SignalR.Client.HubConnectionOptions.ServerTimeout.set -> void static Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithKeepAliveInterval(this Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! hubConnectionBuilder, System.TimeSpan timeout) -> Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! static Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithServerTimeout(this Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! hubConnectionBuilder, System.TimeSpan timeout) -> Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! static Microsoft.AspNetCore.SignalR.Client.HubConnectionExtensions.On(this Microsoft.AspNetCore.SignalR.Client.HubConnection! hubConnection, string! methodName, System.Func!>! handler) -> System.IDisposable! From cf4a24f4dc362effadf58fe6e43894228d946ec2 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada <114938397+surayya-MS@users.noreply.github.com> Date: Tue, 17 Jan 2023 19:49:14 +0100 Subject: [PATCH 04/12] Update src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs Co-authored-by: Brennan --- .../clients/csharp/Client.Core/src/HubConnectionOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs index 1fa320b2c081..5ebae3958898 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionOptions.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.SignalR.Client; /// /// Configures timeouts for the . /// -internal class HubConnectionOptions +internal sealed class HubConnectionOptions { /// /// Configures ServerTimeout for the . From b65bbb3a8ea44087003b016769a0aafc3dff3254 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada <114938397+surayya-MS@users.noreply.github.com> Date: Tue, 17 Jan 2023 19:49:34 +0100 Subject: [PATCH 05/12] Update src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts Co-authored-by: Brennan --- src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts index 3353cb19d117..5ea7bb429e9b 100644 --- a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts +++ b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts @@ -186,7 +186,7 @@ export class HubConnectionBuilder { return this; } - /** Configures serverTimeoutInMilliseconds for the {@link @microsoft/signalr.HubConnection}. + /** Configures {@link @microsoft/signalr.HubConnection.serverTimeoutInMilliseconds} for the {@link @microsoft/signalr.HubConnection}. * * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining. */ From 66e5d5070bfd71516c41b55c6cd0bc5520a2349d Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada <114938397+surayya-MS@users.noreply.github.com> Date: Tue, 17 Jan 2023 19:49:57 +0100 Subject: [PATCH 06/12] Update src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts Co-authored-by: Brennan --- src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts index 5ea7bb429e9b..5c19815189c4 100644 --- a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts +++ b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts @@ -198,7 +198,7 @@ export class HubConnectionBuilder { return this; } - /** Configures keepAliveIntervalInMilliseconds for the {@link @microsoft/signalr.HubConnection}. + /** Configures {@link @microsoft/signalr.HubConnection.keepAliveIntervalInMilliseconds} for the {@link @microsoft/signalr.HubConnection}. * * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining. */ From 47e594de211deb91e9e150d58c341307e0c5496f Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada <114938397+surayya-MS@users.noreply.github.com> Date: Tue, 17 Jan 2023 19:50:22 +0100 Subject: [PATCH 07/12] Update src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs Co-authored-by: Brennan --- .../csharp/Client.Core/src/HubConnectionBuilderExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs index 8c48c2ef922f..af23d0d86450 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs @@ -82,7 +82,7 @@ public static IHubConnectionBuilder WithServerTimeout(this IHubConnectionBuilder /// The to configure. /// KeepAliveInterval for the . /// The same instance of the for chaining. - public static IHubConnectionBuilder WithKeepAliveInterval(this IHubConnectionBuilder hubConnectionBuilder, TimeSpan timeout) + public static IHubConnectionBuilder WithKeepAliveInterval(this IHubConnectionBuilder hubConnectionBuilder, TimeSpan interval) { hubConnectionBuilder.Services.Configure(o => o.KeepAliveInterval = timeout); return hubConnectionBuilder; From 4788af17281fe0d7bcbf9cd0560266237d1b5f26 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Tue, 17 Jan 2023 20:29:30 +0100 Subject: [PATCH 08/12] 1. Changed initialization of ServerTimeout and KeepAliveInterval in HubConnection 2. Added test to HubConnectionBuilderTests --- .../csharp/Client.Core/src/HubConnection.cs | 17 ++++------------- .../test/UnitTests/HubConnectionBuilderTests.cs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs index d036d42ce1a9..a82dfa23003e 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs @@ -153,7 +153,7 @@ public partial class HubConnection : IAsyncDisposable /// /// The client times out if it hasn't heard from the server for `this` long. /// - public TimeSpan ServerTimeout { get; set; } = DefaultServerTimeout; + public TimeSpan ServerTimeout { get; set; } /// /// Gets or sets the interval at which the client sends ping messages. @@ -161,7 +161,7 @@ public partial class HubConnection : IAsyncDisposable /// /// Sending any message resets the timer to the start of the interval. /// - public TimeSpan KeepAliveInterval { get; set; } = DefaultKeepAliveInterval; + public TimeSpan KeepAliveInterval { get; set; } /// /// Gets or sets the timeout for the initial handshake. @@ -231,18 +231,9 @@ public HubConnection(IConnectionFactory connectionFactory, var options = serviceProvider.GetService>(); - if (options != null) - { - if (options.Value.ServerTimeout.HasValue) - { - ServerTimeout = options.Value.ServerTimeout.Value; - } + ServerTimeout = options?.Value.ServerTimeout ?? DefaultServerTimeout; - if (options.Value.KeepAliveInterval.HasValue) - { - KeepAliveInterval = options.Value.KeepAliveInterval.Value; - } - } + KeepAliveInterval = options?.Value.KeepAliveInterval ?? DefaultKeepAliveInterval; } /// diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionBuilderTests.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionBuilderTests.cs index 6768ed452f46..cb0938bf5720 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionBuilderTests.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionBuilderTests.cs @@ -103,4 +103,20 @@ public void CanConfigureKeepAliveInterval() Assert.Equal(keepAliveInterval, connection.KeepAliveInterval); } + + [Fact] + public void CanConfigureServerTimeoutAndKeepAliveInterval() + { + var serverTimeout = TimeSpan.FromMinutes(2); + var keepAliveInterval = TimeSpan.FromMinutes(3); + var builder = new HubConnectionBuilder(); + builder.WithUrl("http://example.com") + .WithServerTimeout(serverTimeout) + .WithKeepAliveInterval(keepAliveInterval); + + var connection = builder.Build(); + + Assert.Equal(serverTimeout, connection.ServerTimeout); + Assert.Equal(keepAliveInterval, connection.KeepAliveInterval); + } } From 74e38b1675c1090c6fc9edc4a34dc2fd12562200 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Tue, 17 Jan 2023 21:00:17 +0100 Subject: [PATCH 09/12] rename parameter in WithKeepAliveInterval --- .../csharp/Client.Core/src/HubConnectionBuilderExtensions.cs | 4 ++-- .../clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs index af23d0d86450..6dbd4fd98e22 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnectionBuilderExtensions.cs @@ -80,11 +80,11 @@ public static IHubConnectionBuilder WithServerTimeout(this IHubConnectionBuilder /// Configures KeepAliveInterval for the . /// /// The to configure. - /// KeepAliveInterval for the . + /// KeepAliveInterval for the . /// The same instance of the for chaining. public static IHubConnectionBuilder WithKeepAliveInterval(this IHubConnectionBuilder hubConnectionBuilder, TimeSpan interval) { - hubConnectionBuilder.Services.Configure(o => o.KeepAliveInterval = timeout); + hubConnectionBuilder.Services.Configure(o => o.KeepAliveInterval = interval); return hubConnectionBuilder; } } diff --git a/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt b/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt index 0ff8d85e374b..a9937988d626 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt +++ b/src/SignalR/clients/csharp/Client.Core/src/PublicAPI.Unshipped.txt @@ -1,3 +1,3 @@ #nullable enable -static Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithKeepAliveInterval(this Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! hubConnectionBuilder, System.TimeSpan timeout) -> Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! -static Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithServerTimeout(this Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! hubConnectionBuilder, System.TimeSpan timeout) -> Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! \ No newline at end of file +static Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithKeepAliveInterval(this Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! hubConnectionBuilder, System.TimeSpan interval) -> Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! +static Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithServerTimeout(this Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! hubConnectionBuilder, System.TimeSpan timeout) -> Microsoft.AspNetCore.SignalR.Client.IHubConnectionBuilder! From 16198125449da3c631b8e0dee0d4ec5d5e5f7b6c Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada <114938397+surayya-MS@users.noreply.github.com> Date: Wed, 18 Jan 2023 18:44:47 +0100 Subject: [PATCH 10/12] Update src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts Co-authored-by: Brennan --- src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts index 5c19815189c4..0613870a8bed 100644 --- a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts +++ b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts @@ -190,7 +190,7 @@ export class HubConnectionBuilder { * * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining. */ - public withServerTimeout(milliseconds: number): HubConnectionBuilder{ + public withServerTimeout(milliseconds: number): HubConnectionBuilder { Arg.isRequired(milliseconds, "milliseconds"); this._serverTimeoutInMilliseconds = milliseconds; From c4e145dc62bbc225a2a74e79dab465933c8cf5d3 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada <114938397+surayya-MS@users.noreply.github.com> Date: Wed, 18 Jan 2023 18:45:10 +0100 Subject: [PATCH 11/12] Update src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts Co-authored-by: Brennan --- src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts index 0613870a8bed..8cd9c1361440 100644 --- a/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts +++ b/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts @@ -202,7 +202,7 @@ export class HubConnectionBuilder { * * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining. */ - public withKeepAliveInterval(milliseconds: number): HubConnectionBuilder{ + public withKeepAliveInterval(milliseconds: number): HubConnectionBuilder { Arg.isRequired(milliseconds, "milliseconds"); this._keepAliveIntervalInMilliseconds = milliseconds; From 95df822b697c794f35569ec61adadeb9dd36f1c9 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Thu, 19 Jan 2023 12:05:32 +0100 Subject: [PATCH 12/12] changed initialization of serverTimeoutInMilliseconds and keepAliveIntervalInMilliseconds in HubConnection ts client --- src/SignalR/clients/ts/signalr/src/HubConnection.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/SignalR/clients/ts/signalr/src/HubConnection.ts b/src/SignalR/clients/ts/signalr/src/HubConnection.ts index ff4a9e957f85..ef17a3ccfa07 100644 --- a/src/SignalR/clients/ts/signalr/src/HubConnection.ts +++ b/src/SignalR/clients/ts/signalr/src/HubConnection.ts @@ -113,17 +113,8 @@ export class HubConnection { Arg.isRequired(logger, "logger"); Arg.isRequired(protocol, "protocol"); - if (serverTimeoutInMilliseconds !== undefined) { - this.serverTimeoutInMilliseconds = serverTimeoutInMilliseconds; - } else { - this.serverTimeoutInMilliseconds = DEFAULT_TIMEOUT_IN_MS; - } - - if (keepAliveIntervalInMilliseconds !== undefined) { - this.keepAliveIntervalInMilliseconds = keepAliveIntervalInMilliseconds; - } else { - this.keepAliveIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS; - } + this.serverTimeoutInMilliseconds = serverTimeoutInMilliseconds ?? DEFAULT_TIMEOUT_IN_MS; + this.keepAliveIntervalInMilliseconds = keepAliveIntervalInMilliseconds ?? DEFAULT_PING_INTERVAL_IN_MS; this._logger = logger; this._protocol = protocol;