Add re-registration request in case of timeouts

This commit is contained in:
Andrey Sobolev
2025-09-30 12:37:58 +07:00
parent aeffd44939
commit c213db6539
3 changed files with 19 additions and 1 deletions
+14
View File
@@ -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) {
+3
View File
@@ -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
}
+2 -1
View File
@@ -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 }