mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 21:50:34 +03:00
TSK-1092: Fix reconnect for Safari (#2929)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
2a7492ff3f
commit
d7f9615a8e
@ -68,6 +68,8 @@ class Connection implements ClientConnection {
|
||||
private readonly sessionId = generateId() as string
|
||||
private closed = false
|
||||
|
||||
private pingResponse: number = Date.now()
|
||||
|
||||
constructor (
|
||||
private readonly url: string,
|
||||
private readonly handler: TxHandler,
|
||||
@ -78,7 +80,25 @@ class Connection implements ClientConnection {
|
||||
console.log('connection created')
|
||||
this.interval = setInterval(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.sendRequest({ method: 'ping', params: [] })
|
||||
|
||||
if (this.pingResponse !== 0 && Date.now() - this.pingResponse > 3 * pingTimeout) {
|
||||
// No ping response from server.
|
||||
const s = this.websocket
|
||||
|
||||
if (!(s instanceof Promise)) {
|
||||
console.log('no ping response from server. Closing socket.', s, (s as any).readyState)
|
||||
// Trying to close connection and re-establish it.
|
||||
s?.close()
|
||||
} else {
|
||||
console.log('no ping response from server. Closing socket.', s)
|
||||
void s.then((s) => s.close())
|
||||
}
|
||||
this.websocket = null
|
||||
}
|
||||
|
||||
void this.sendRequest({ method: 'ping', params: [] }).then(() => {
|
||||
this.pingResponse = Date.now()
|
||||
})
|
||||
}, pingTimeout)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user