Check connection state in ping Typescript client (#2753)

This commit is contained in:
BrennanConroy 2018-08-07 14:14:32 -07:00 committed by GitHub
parent 02d1d4b1aa
commit cef7dfcdbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -406,7 +406,11 @@ export class HubConnection {
private resetKeepAliveInterval() {
this.cleanupPingTimer();
this.pingServerHandle = setTimeout(() => this.sendMessage(this.cachedPingMessage), this.keepAliveIntervalInMilliseconds);
this.pingServerHandle = setTimeout(async () => {
if (this.connectionState === HubConnectionState.Connected) {
await this.sendMessage(this.cachedPingMessage);
}
}, this.keepAliveIntervalInMilliseconds);
}
private resetTimeoutPeriod() {