From 280c59e6b5734b9821a62cb438f3e5e5d9660f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 2 Jul 2021 17:26:28 +0200 Subject: [PATCH] Changing callback signature of registerAnswerer so that it can return a value and not necessarily a promise. --- docs/maps/api-room.md | 2 +- front/src/Api/IframeListener.ts | 6 +++--- front/src/Phaser/Game/GameScene.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/maps/api-room.md b/docs/maps/api-room.md index 17e3d48e..9d08ce1b 100644 --- a/docs/maps/api-room.md +++ b/docs/maps/api-room.md @@ -81,7 +81,7 @@ WA.room.getCurrentRoom(): Promise ``` Return a promise that resolves to a `Room` object with the following attributes : * **id (string) :** ID of the current room -* **map (ITiledMap) :** contains the JSON map file with the properties that were setted by the script if `setProperty` was called. +* **map (ITiledMap) :** contains the JSON map file with the properties that were set by the script if `setProperty` was called. * **mapUrl (string) :** Url of the JSON map file * **startLayer (string | null) :** Name of the layer where the current user started, only if different from `start` layer diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index 334535a5..314d5d2e 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -33,7 +33,7 @@ import { isLoadPageEvent } from "./Events/LoadPageEvent"; import { handleMenuItemRegistrationEvent, isMenuItemRegisterIframeEvent } from "./Events/ui/MenuItemRegisterEvent"; import { SetTilesEvent, isSetTilesEvent } from "./Events/SetTilesEvent"; -type AnswererCallback = (query: IframeQueryMap[T]['query']) => Promise; +type AnswererCallback = (query: IframeQueryMap[T]['query']) => IframeQueryMap[T]['answer']|Promise; /** * Listens to messages from iframes and turn those messages into easy to use observables. @@ -164,7 +164,7 @@ class IframeListener { return; } - answerer(query.data).then((value) => { + Promise.resolve(answerer(query.data)).then((value) => { iframe?.contentWindow?.postMessage({ id: queryId, type: query.type, @@ -411,7 +411,7 @@ class IframeListener { * @param key The "type" of the query we are answering * @param callback */ - public registerAnswerer(key: T, callback: (query: IframeQueryMap[T]['query']) => Promise ): void { + public registerAnswerer(key: T, callback: (query: IframeQueryMap[T]['query']) => IframeQueryMap[T]['answer']|Promise ): void { this.answerers[key] = callback; } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 6cb5284d..d767f0f4 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -1045,14 +1045,14 @@ ${escapedMessage} ); iframeListener.registerAnswerer('getState', () => { - return Promise.resolve({ + return { mapUrl: this.MapUrlFile, startLayerName: this.startPositionCalculator.startLayerName, uuid: localUserStore.getLocalUser()?.uuid, nickname: localUserStore.getName(), roomId: this.RoomId, tags: this.connection ? this.connection.getAllTags() : [], - }); + }; }); this.iframeSubscriptionList.push( iframeListener.setTilesStream.subscribe((eventTiles) => {