mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-08 02:37:44 +02:00
Add re-registration request in case of timeouts
This commit is contained in:
@@ -48,6 +48,8 @@ export class BackRPCClient<ClientT extends string = ClientId> {
|
||||
|
||||
stopTick?: () => void
|
||||
|
||||
lastPong: number = 0
|
||||
|
||||
constructor (
|
||||
readonly clientId: ClientT,
|
||||
readonly client: BackRPCClientHandler,
|
||||
@@ -190,6 +192,18 @@ export class BackRPCClient<ClientT extends string = ClientId> {
|
||||
)
|
||||
})
|
||||
}
|
||||
break
|
||||
}
|
||||
case backrpcOperations.pong: {
|
||||
// Server it all fine
|
||||
this.lastPong = this.tickMgr.now()
|
||||
break
|
||||
}
|
||||
case backrpcOperations.askHello: {
|
||||
// Server ask us to re-hello, probably because it has restarted
|
||||
this.serverId = '' // Clear server id for re-register to be performed
|
||||
await this.sendHello()
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
|
||||
@@ -209,6 +209,9 @@ export class BackRPCServer<ClientT extends string = ClientId> {
|
||||
void this.doSend([clientId, backrpcOperations.pong, this.uuid, ''])
|
||||
if (client !== undefined) {
|
||||
this.handlers.onPing?.(client?.id)
|
||||
} else {
|
||||
// Ping from undefined client mean, we remove it because of inactivity, so we could ask for hello.
|
||||
void this.doSend([clientId, backrpcOperations.askHello, this.uuid, ''])
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ export const backrpcOperations = {
|
||||
ping: 5,
|
||||
pong: 6,
|
||||
retry: 7,
|
||||
close: 8
|
||||
close: 8,
|
||||
askHello: 9
|
||||
}
|
||||
|
||||
export type ClientId = string & { __clientId: string }
|
||||
|
||||
Reference in New Issue
Block a user