PingInterval -> KeepAliveInterval (#2384)
This commit is contained in:
parent
e3835b3c94
commit
f0f1df9b4a
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// <remarks>
|
||||
/// Sending any message resets the timer to the start of the interval.
|
||||
/// </remarks>
|
||||
public TimeSpan PingInterval { get; set; } = DefaultPingInterval;
|
||||
public TimeSpan KeepAliveInterval { get; set; } = DefaultKeepAliveInterval;
|
||||
|
||||
/// <summary>
|
||||
/// 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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue