From 91148035ec0f9c221b53f22d74b56222312ae4e1 Mon Sep 17 00:00:00 2001 From: jonny Date: Sun, 9 May 2021 21:46:40 +0200 Subject: [PATCH] polyfill generic message event --- front/src/Api/Events/IframeEvent.ts | 4 ++++ front/src/Api/IframeListener.ts | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/front/src/Api/Events/IframeEvent.ts b/front/src/Api/Events/IframeEvent.ts index 0657b15a..1ed853c9 100644 --- a/front/src/Api/Events/IframeEvent.ts +++ b/front/src/Api/Events/IframeEvent.ts @@ -11,6 +11,10 @@ import { OpenTabEvent } from './OpenTabEvent'; import { UserInputChatEvent } from './UserInputChatEvent'; +export interface TypedMessageEvent extends MessageEvent { + data: T +} + export type IframeEventMap = { //getState: GameStateEvent, // updateTile: UpdateTileEvent diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index 03f81210..d3b8ce4f 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -10,7 +10,7 @@ import { ClosePopupEvent, isClosePopupEvent } from "./Events/ClosePopupEvent"; import { scriptUtils } from "./ScriptUtils"; import { GoToPageEvent, isGoToPageEvent } from "./Events/GoToPageEvent"; import { isOpenCoWebsite, OpenCoWebSiteEvent } from "./Events/OpenCoWebSiteEvent"; -import { IframeEventMap, IframeEvent, IframeResponseEvent, IframeResponseEventMap, isIframeEventWrapper } from "./Events/IframeEvent"; +import { IframeEventMap, IframeEvent, IframeResponseEvent, IframeResponseEventMap, isIframeEventWrapper, TypedMessageEvent } from "./Events/IframeEvent"; import { UserInputChatEvent } from "./Events/UserInputChatEvent"; @@ -56,7 +56,7 @@ class IframeListener { private readonly scripts = new Map(); init() { - window.addEventListener("message", (message: MessageEvent>) => { + window.addEventListener("message", (message: TypedMessageEvent>) => { // Do we trust the sender of this message? // Let's only accept messages from the iframe that are allowed. // Note: maybe we could restrict on the domain too for additional security (in case the iframe goes to another domain).