Ping from server (#5039)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2024-03-22 15:56:17 +07:00
committed by GitHub
parent fe5d787250
commit 3d2b60ac99
4 changed files with 32 additions and 5 deletions
+5 -2
View File
@@ -89,8 +89,6 @@ class Connection implements ClientConnection {
readonly onConnect?: (event: ClientConnectEvent) => Promise<void>
) {
this.interval = setInterval(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
if (this.pingResponse !== 0 && Date.now() - this.pingResponse > hangTimeout) {
// No ping response from server.
const s = this.websocket
@@ -108,6 +106,7 @@ class Connection implements ClientConnection {
this.websocket = null
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
void this.sendRequest({ method: 'ping', params: [] }).then(() => {
this.pingResponse = Date.now()
})
@@ -229,6 +228,10 @@ class Connection implements ClientConnection {
)
return
}
if (resp.result === 'ping') {
void this.sendRequest({ method: 'ping', params: [] })
return
}
if (resp.id !== undefined) {
const promise = this.requests.get(resp.id)
if (promise === undefined) {