Merge 935e1f5909 into d5f82611f5
commit
8c11dd52a2
|
|
@ -6,10 +6,12 @@ import { updateUserInfo } from "#app/account";
|
||||||
|
|
||||||
export default class UnavailableModalUiHandler extends ModalUiHandler {
|
export default class UnavailableModalUiHandler extends ModalUiHandler {
|
||||||
private reconnectTimer: number;
|
private reconnectTimer: number;
|
||||||
|
private reconnectInterval: number;
|
||||||
private reconnectCallback: () => void;
|
private reconnectCallback: () => void;
|
||||||
|
|
||||||
constructor(scene: BattleScene, mode?: Mode) {
|
constructor(scene: BattleScene, mode?: Mode) {
|
||||||
super(scene, mode);
|
super(scene, mode);
|
||||||
|
this.reconnectInterval = 5000;
|
||||||
}
|
}
|
||||||
|
|
||||||
getModalTitle(): string {
|
getModalTitle(): string {
|
||||||
|
|
@ -41,6 +43,26 @@ export default class UnavailableModalUiHandler extends ModalUiHandler {
|
||||||
this.modalContainer.add(label);
|
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;
|
||||||
|
if (this.reconnectInterval > 60000) {
|
||||||
|
this.reconnectInterval = 60000; // 1 minute maximum delay.
|
||||||
|
}
|
||||||
|
this.reconnectTimer = setTimeout(this.tryReconnect, this.reconnectInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
show(args: any[]): boolean {
|
show(args: any[]): boolean {
|
||||||
if (args.length >= 1 && args[0] instanceof Function) {
|
if (args.length >= 1 && args[0] instanceof Function) {
|
||||||
const config: ModalConfig = {
|
const config: ModalConfig = {
|
||||||
|
|
@ -49,20 +71,11 @@ export default class UnavailableModalUiHandler extends ModalUiHandler {
|
||||||
|
|
||||||
this.reconnectCallback = args[0];
|
this.reconnectCallback = args[0];
|
||||||
|
|
||||||
this.reconnectTimer = setInterval(() => {
|
this.reconnectTimer = setInterval(this.tryReconnect, this.reconnectInterval);
|
||||||
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);
|
|
||||||
|
|
||||||
return super.show([ config ]);
|
return super.show([ config ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue