add exitUrl script

This commit is contained in:
_Bastler
2021-05-16 14:52:07 +02:00
parent c7623300f2
commit 6ebec9ce68
4 changed files with 37 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
import * as tg from "generic-type-guard";
export const isExitUrlEvent =
new tg.IsInterface().withProperties({
url: tg.isString,
}).get();
/**
* A message sent from the iFrame to the game to trigger Exit Url
*/
export type ExitUrlEvent = tg.GuardedType<typeof isExitUrlEvent>;
+7
View File
@@ -12,6 +12,7 @@ import {ClosePopupEvent, isClosePopupEvent} from "./Events/ClosePopupEvent";
import {scriptUtils} from "./ScriptUtils";
import {GoToPageEvent, isGoToPageEvent} from "./Events/GoToPageEvent";
import {isOpenCoWebsite, OpenCoWebSiteEvent} from "./Events/OpenCoWebSiteEvent";
import { isExitUrlEvent } from './Events/ExitUrlEvent';
/**
@@ -55,6 +56,9 @@ class IframeListener {
private readonly _unregisterIFrameStream: Subject<void> = new Subject();
public readonly unregisterIFrameStream = this._unregisterIFrameStream.asObservable();
private readonly _exitUrlStream: Subject<string> = new Subject();
public readonly exitUrlStream = this._exitUrlStream.asObservable();
private readonly iframes = new Set<HTMLIFrameElement>();
private readonly scripts = new Map<string, HTMLIFrameElement>();
@@ -109,6 +113,9 @@ class IframeListener {
}
else if (payload.type === 'removeBubble'){
this._removeBubbleStream.next();
}
else if (payload.type === 'exitUrl' && isExitUrlEvent(payload.data)){
this._exitUrlStream.next(payload.data.url);
}
}