From 5d360c877086415848df4c90948504eb6ff866a6 Mon Sep 17 00:00:00 2001 From: CEC Date: Tue, 19 Apr 2022 10:50:01 +0200 Subject: [PATCH] Add custom image from errors thrown by the API --- front/src/Components/UI/ErrorScreen.svelte | 17 +++++++++++---- messages/protos/messages.proto | 1 + pusher/src/Controller/IoSocketController.ts | 14 ++----------- pusher/src/Services/SocketManager.ts | 23 ++------------------- 4 files changed, 18 insertions(+), 37 deletions(-) diff --git a/front/src/Components/UI/ErrorScreen.svelte b/front/src/Components/UI/ErrorScreen.svelte index ed8e5505..b6eed03a 100644 --- a/front/src/Components/UI/ErrorScreen.svelte +++ b/front/src/Components/UI/ErrorScreen.svelte @@ -2,6 +2,8 @@ import { fly } from "svelte/transition"; import { errorScreenStore } from "../../Stores/ErrorScreenStore"; import { gameManager } from "../../Phaser/Game/GameManager"; + import { get } from "svelte/store"; + import {onDestroy} from "svelte"; import logoImg from "../images/logo-min-white.png"; let logo = gameManager?.currentStartedRoom?.loginSceneLogo ?? logoImg; @@ -9,22 +11,25 @@ import cup from "../images/cup.png"; import reload from "../images/reload.png"; import external from "../images/external-link.png"; - import { get } from "svelte/store"; let errorScreen = get(errorScreenStore); - function click() { + const image = errorScreen.image ?? (errorScreen.type === "retry" ? cup : error); + + function click() { if (errorScreen.urlToRedirect) window.location.replace(errorScreen.urlToRedirect); else if (errorScreen.type === "redirect" && window.history.length > 2) history.back(); else window.location.reload(); } let details = errorScreen.details; let timeVar = errorScreen.timeToRetry ?? 0; + if (errorScreen.type === "retry") { - setInterval(() => { + let interval = setInterval(() => { if (timeVar <= 1000) click(); timeVar -= 1000; }, 1000); + onDestroy(() => clearInterval(interval)); } $: detailsStylized = details.replace("{time}", `${timeVar / 1000}`); @@ -33,7 +38,7 @@
-
+
{#if $errorScreenStore.type !== "retry"}

{$errorScreenStore.title}

{/if}

{$errorScreenStore.subtitle}

{#if $errorScreenStore.type !== "retry"}

Code : {$errorScreenStore.code}

{/if} @@ -74,10 +79,14 @@ .logo { width: 50%; margin-bottom: 50px; + max-height: 10vh; + max-width: 50vw; } .icon { height: 125px; margin-bottom: 25px; + max-height: 10vh; + max-width: 50vw; } h2 { font-family: "Press Start 2P"; diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index cf861d70..1291d6f3 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -234,6 +234,7 @@ message ErrorScreenMessage { bool canRetryManual = 7; string urlToRedirect = 8; string buttonTitle = 9; + string image = 10; } message ItemStateMessage { diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index 97af0faf..7795e448 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -22,6 +22,7 @@ import { FollowAbortMessage, VariableMessage, LockGroupPromptMessage, + ErrorScreenMessage } from "../Messages/generated/messages_pb"; import { UserMovesMessage } from "../Messages/generated/messages_pb"; import { parse } from "query-string"; @@ -486,18 +487,7 @@ export class IoSocketController { } else if (ws.reason === "textureInvalid") { socketManager.emitInvalidTextureMessage(ws); } else if (ws.reason === "error") { - socketManager.emitErrorScreenMessage( - ws, - ws.error.type, - ws.error.code, - ws.error.title, - ws.error.subtitle, - ws.error.details, - ws.error.timeToRetry, - ws.error.canRetryManual, - ws.error.urlToRedirect, - ws.error.buttonTitle - ); + socketManager.emitErrorScreenMessage(ws, ws.error as ErrorScreenMessage); } else { socketManager.emitConnexionErrorMessage(ws, ws.message); } diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index 545144b7..4984b96f 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -646,29 +646,10 @@ export class SocketManager implements ZoneEventListener { public emitErrorScreenMessage( client: compressors.WebSocket, - type: string, - code: string, - title: string, - subtitle: string, - details: string, - timeToRetry: number, - canRetryManual: boolean, - urlToRedirect: string, - buttonTitle: string + error: ErrorScreenMessage ) { - const errorMessage = new ErrorScreenMessage(); - errorMessage.setType(type); - errorMessage.setCode(code); - errorMessage.setTitle(title); - errorMessage.setSubtitle(subtitle); - errorMessage.setDetails(details); - errorMessage.setTimetoretry(timeToRetry); - errorMessage.setCanretrymanual(canRetryManual); - errorMessage.setUrltoredirect(urlToRedirect); - errorMessage.setButtontitle(buttonTitle); - const serverToClientMessage = new ServerToClientMessage(); - serverToClientMessage.setErrorscreenmessage(errorMessage); + serverToClientMessage.setErrorscreenmessage(error); //if (!client.disconnecting) { client.send(serverToClientMessage.serializeBinary().buffer, true);