diff --git a/clients/ts/signalr/src/HubConnection.ts b/clients/ts/signalr/src/HubConnection.ts index c1c2419850..0af04f33d2 100644 --- a/clients/ts/signalr/src/HubConnection.ts +++ b/clients/ts/signalr/src/HubConnection.ts @@ -48,7 +48,7 @@ export class HubConnection { * The default value is 15,000 milliseconds (15 seconds). * Allows the server to detect hard disconnects (like when a client unplugs their computer). */ - public pingIntervalInMilliseconds: number; + public keepAliveIntervalInMilliseconds: number; /** @internal */ // Using a public static factory method means we can have a private constructor and an _internal_ @@ -65,7 +65,7 @@ export class HubConnection { Arg.isRequired(protocol, "protocol"); this.serverTimeoutInMilliseconds = DEFAULT_TIMEOUT_IN_MS; - this.pingIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS; + this.keepAliveIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS; this.logger = logger; this.protocol = protocol; @@ -114,7 +114,7 @@ export class HubConnection { // defensively cleanup timeout in case we receive a message from the server before we finish start this.cleanupTimeout(); this.resetTimeoutPeriod(); - this.resetPingInterval(); + this.resetKeepAliveInterval(); this.connectionState = HubConnectionState.Connected; } @@ -179,7 +179,7 @@ export class HubConnection { } private sendMessage(message: any) { - this.resetPingInterval(); + this.resetKeepAliveInterval(); return this.connection.send(message); } @@ -386,9 +386,9 @@ export class HubConnection { return remainingData; } - private resetPingInterval() { + private resetKeepAliveInterval() { this.cleanupPingTimer(); - this.pingServerHandle = setTimeout(() => this.sendMessage(this.cachedPingMessage), this.pingIntervalInMilliseconds); + this.pingServerHandle = setTimeout(() => this.sendMessage(this.cachedPingMessage), this.keepAliveIntervalInMilliseconds); } private resetTimeoutPeriod() { diff --git a/clients/ts/signalr/tests/HubConnection.test.ts b/clients/ts/signalr/tests/HubConnection.test.ts index 36bb18ceb6..e09d9acad6 100644 --- a/clients/ts/signalr/tests/HubConnection.test.ts +++ b/clients/ts/signalr/tests/HubConnection.test.ts @@ -53,11 +53,11 @@ describe("HubConnection", () => { const connection = new TestConnection(); const hubConnection = createHubConnection(connection); - hubConnection.pingIntervalInMilliseconds = 5; + hubConnection.keepAliveIntervalInMilliseconds = 5; try { await hubConnection.start(); - await delay(32); + await delay(500); const numPings = connection.sentData.filter((s) => JSON.parse(s).type === MessageType.Ping).length; expect(numPings).toBeGreaterThanOrEqual(2); diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs index 7a5c02da93..6b1522a49d 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.SignalR.Client { public static readonly TimeSpan DefaultServerTimeout = TimeSpan.FromSeconds(30); // Server ping rate is 15 sec, this is 2 times that. public static readonly TimeSpan DefaultHandshakeTimeout = TimeSpan.FromSeconds(15); - public static readonly TimeSpan DefaultPingInterval = TimeSpan.FromSeconds(15); + public static readonly TimeSpan DefaultKeepAliveInterval = TimeSpan.FromSeconds(15); // This lock protects the connection state. private readonly SemaphoreSlim _connectionLock = new SemaphoreSlim(1, 1); @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.SignalR.Client /// /// Sending any message resets the timer to the start of the interval. /// - public TimeSpan PingInterval { get; set; } = DefaultPingInterval; + public TimeSpan KeepAliveInterval { get; set; } = DefaultKeepAliveInterval; /// /// Gets or sets the timeout for the initial handshake. @@ -846,7 +846,7 @@ namespace Microsoft.AspNetCore.SignalR.Client public void ResetSendPing() { - Volatile.Write(ref _nextActivationSendPing, (DateTime.UtcNow + PingInterval).Ticks); + Volatile.Write(ref _nextActivationSendPing, (DateTime.UtcNow + KeepAliveInterval).Ticks); } public void ResetTimeout() diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Protocol.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Protocol.cs index c1603c55ff..e3a55351f4 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Protocol.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Protocol.cs @@ -574,7 +574,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var hubConnection = CreateHubConnection(connection); hubConnection.TickRate = TimeSpan.FromMilliseconds(30); - hubConnection.PingInterval = TimeSpan.FromMilliseconds(80); + hubConnection.KeepAliveInterval = TimeSpan.FromMilliseconds(80); try {