From 732d0ee66a61d02cfc956b1ff91de4dbce08e268 Mon Sep 17 00:00:00 2001 From: Jesse Selover Date: Wed, 8 May 2024 02:18:18 -0700 Subject: [PATCH] Attempt 1 at exponential backoff in server-down behavior. --- src/ui/unavailable-modal-ui-handler.ts | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/ui/unavailable-modal-ui-handler.ts b/src/ui/unavailable-modal-ui-handler.ts index 4481746c7..4f6001d9f 100644 --- a/src/ui/unavailable-modal-ui-handler.ts +++ b/src/ui/unavailable-modal-ui-handler.ts @@ -6,10 +6,12 @@ import { updateUserInfo } from "#app/account"; export default class UnavailableModalUiHandler extends ModalUiHandler { private reconnectTimer: number; + private reconnectInterval: number; private reconnectCallback: () => void; constructor(scene: BattleScene, mode?: Mode) { super(scene, mode); + this.reconnectInterval = 5000; } getModalTitle(): string { @@ -41,6 +43,23 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { this.modalContainer.add(label); } + tryReconnect(): void { + updateUserInfo().then(response => { + if (response[0] || [200, 400].includes(response[1])) { + clearInterval(this.reconnectTimer); + this.reconnectTimer = null; + this.reconnectInterval = 5000; + this.scene.playSound('pb_bounce_1'); + this.reconnectCallback(); + } + else { + clearInterval(this.reconnectTimer); + this.reconnectInterval *= 2; + this.reconnectTimer = setInterval(this.tryReconnect, reconnectInterval); + } + }); + } + show(args: any[]): boolean { if (args.length >= 1 && args[0] instanceof Function) { const config: ModalConfig = { @@ -49,20 +68,11 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { this.reconnectCallback = args[0]; - this.reconnectTimer = setInterval(() => { - updateUserInfo().then(response => { - if (response[0] || [200, 400].includes(response[1])) { - clearInterval(this.reconnectTimer); - this.reconnectTimer = null; - this.scene.playSound('pb_bounce_1'); - this.reconnectCallback(); - } - }) - }, 5000); + this.reconnectTimer = setInterval(this.tryReconnect, this.reconnectInterval); return super.show([ config ]); } return false; } -} \ No newline at end of file +}