add exitUrl script
This commit is contained in:
parent
c7623300f2
commit
6ebec9ce68
11
front/src/Api/Events/ExitUrlEvent.ts
Normal file
11
front/src/Api/Events/ExitUrlEvent.ts
Normal 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>;
|
@ -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>();
|
||||
|
||||
@ -110,6 +114,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,6 +82,7 @@ import CanvasTexture = Phaser.Textures.CanvasTexture;
|
||||
import GameObject = Phaser.GameObjects.GameObject;
|
||||
import FILE_LOAD_ERROR = Phaser.Loader.Events.FILE_LOAD_ERROR;
|
||||
import DOMElement = Phaser.GameObjects.DOMElement;
|
||||
import EVENT_TYPE =Phaser.Scenes.Events;
|
||||
import {Subscription} from "rxjs";
|
||||
import {worldFullMessageStream} from "../../Connexion/WorldFullMessageStream";
|
||||
import { lazyLoadCompanionResource } from "../Companion/CompanionTexturesLoadingManager";
|
||||
@ -898,6 +899,14 @@ export class GameScene extends ResizableScene implements CenterListener {
|
||||
}, this.userInputManager);
|
||||
}
|
||||
}));
|
||||
|
||||
this.iframeSubscriptionList.push(iframeListener.exitUrlStream.subscribe((url:string)=>{
|
||||
this.loadNextGame(url).then(()=>{
|
||||
this.events.once(EVENT_TYPE.POST_UPDATE,()=>{
|
||||
this.onMapExit(url);
|
||||
})
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
private getMapDirUrl(): string {
|
||||
|
@ -9,6 +9,7 @@ import {ClosePopupEvent, isClosePopupEvent} from "./Api/Events/ClosePopupEvent";
|
||||
import {OpenTabEvent} from "./Api/Events/OpenTabEvent";
|
||||
import {GoToPageEvent} from "./Api/Events/GoToPageEvent";
|
||||
import {OpenCoWebSiteEvent} from "./Api/Events/OpenCoWebSiteEvent";
|
||||
import {ExitUrlEvent} from "./Api/Events/ExitUrlEvent";
|
||||
|
||||
interface WorkAdventureApi {
|
||||
sendChatMessage(message: string, author: string): void;
|
||||
@ -25,6 +26,7 @@ interface WorkAdventureApi {
|
||||
restorePlayerControl(): void;
|
||||
displayBubble(): void;
|
||||
removeBubble(): void;
|
||||
exitUrl(url : string): void;
|
||||
}
|
||||
|
||||
declare global {
|
||||
@ -210,6 +212,14 @@ window.WA = {
|
||||
}
|
||||
subject.subscribe(callback);
|
||||
},
|
||||
exitUrl(url : string) : void{
|
||||
window.parent.postMessage({
|
||||
"type" : 'exitUrl',
|
||||
"data" : {
|
||||
url
|
||||
} as ExitUrlEvent
|
||||
},'*');
|
||||
},
|
||||
}
|
||||
|
||||
window.addEventListener('message', message => {
|
||||
|
Loading…
Reference in New Issue
Block a user