2021-05-12 09:13:25 +02:00
|
|
|
import type { ChatEvent } from "./Api/Events/ChatEvent";
|
2021-05-10 21:27:17 +02:00
|
|
|
import { IframeEvent, IframeEventMap, isIframeResponseEventWrapper } from "./Api/Events/IframeEvent";
|
2021-05-09 21:30:29 +02:00
|
|
|
import { isUserInputChatEvent, UserInputChatEvent } from "./Api/Events/UserInputChatEvent";
|
|
|
|
import { Subject } from "rxjs";
|
|
|
|
import { EnterLeaveEvent, isEnterLeaveEvent } from "./Api/Events/EnterLeaveEvent";
|
2021-05-12 09:13:25 +02:00
|
|
|
import type { OpenPopupEvent } from "./Api/Events/OpenPopupEvent";
|
2021-05-09 21:30:29 +02:00
|
|
|
import { isButtonClickedEvent } from "./Api/Events/ButtonClickedEvent";
|
2021-05-12 09:13:25 +02:00
|
|
|
import type { ClosePopupEvent } from "./Api/Events/ClosePopupEvent";
|
|
|
|
import type { OpenTabEvent } from "./Api/Events/OpenTabEvent";
|
|
|
|
import type { GoToPageEvent } from "./Api/Events/GoToPageEvent";
|
|
|
|
import type { OpenCoWebSiteEvent } from "./Api/Events/OpenCoWebSiteEvent";
|
2021-05-18 11:50:03 +02:00
|
|
|
import type { LayerEvent } from "./Api/Events/LayerEvent";
|
|
|
|
import type { SetPropertyEvent } from "./Api/Events/setPropertyEvent";
|
2021-05-18 11:33:16 +02:00
|
|
|
import { GameStateEvent, isGameStateEvent } from './Api/Events/GameStateEvent';
|
|
|
|
import { HasPlayerMovedEvent, HasPlayerMovedEventCallback, isHasPlayerMovedEvent } from './Api/Events/HasPlayerMovedEvent';
|
2021-05-18 15:41:16 +02:00
|
|
|
import { DataLayerEvent, isDataLayerEvent } from "./Api/Events/DataLayerEvent";
|
2021-05-19 09:36:11 +02:00
|
|
|
import type { ITiledMap } from "./Phaser/Map/ITiledMap";
|
|
|
|
import type { MenuItemRegisterEvent } from "./Api/Events/MenuItemRegisterEvent";
|
|
|
|
import { isMenuItemClickedEvent } from "./Api/Events/MenuItemClickedEvent";
|
2021-03-05 16:50:54 +01:00
|
|
|
|
2021-03-04 19:00:00 +01:00
|
|
|
interface WorkAdventureApi {
|
|
|
|
sendChatMessage(message: string, author: string): void;
|
2021-03-05 16:50:54 +01:00
|
|
|
onChatMessage(callback: (message: string) => void): void;
|
2021-03-08 18:57:59 +01:00
|
|
|
onEnterZone(name: string, callback: () => void): void;
|
|
|
|
onLeaveZone(name: string, callback: () => void): void;
|
2021-03-09 18:51:30 +01:00
|
|
|
openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[]): Popup;
|
2021-05-10 21:27:17 +02:00
|
|
|
openTab(url: string): void;
|
|
|
|
goToPage(url: string): void;
|
|
|
|
openCoWebSite(url: string): void;
|
2021-03-25 17:12:53 +01:00
|
|
|
closeCoWebSite(): void;
|
2021-05-10 14:45:41 +02:00
|
|
|
disablePlayerControls() : void;
|
|
|
|
restorePlayerControls() : void;
|
2021-03-12 16:39:29 +01:00
|
|
|
displayBubble() : void;
|
|
|
|
removeBubble() : void;
|
2021-05-10 11:19:18 +02:00
|
|
|
showLayer(layer: string) : void;
|
|
|
|
hideLayer(layer: string) : void;
|
2021-05-12 14:30:12 +02:00
|
|
|
setProperty(layerName: string, propertyName: string, propertyValue: string | number | boolean | undefined): void;
|
2021-05-10 12:14:31 +02:00
|
|
|
disablePlayerControls(): void;
|
|
|
|
restorePlayerControls(): void;
|
2021-05-09 21:30:29 +02:00
|
|
|
displayBubble(): void;
|
|
|
|
removeBubble(): void;
|
2021-04-27 11:59:22 +02:00
|
|
|
registerMenuCommand(commandDescriptor: string, callback: (commandDescriptor: string) => void): void
|
2021-05-18 11:33:16 +02:00
|
|
|
getMapUrl(): Promise<string>;
|
|
|
|
getUuid(): Promise<string | undefined>;
|
|
|
|
getRoomId(): Promise<string>;
|
|
|
|
getStartLayerName(): Promise<string | null>;
|
2021-05-18 15:41:16 +02:00
|
|
|
getNickName(): Promise<string | null>;
|
2021-05-10 21:27:17 +02:00
|
|
|
|
2021-05-18 11:33:16 +02:00
|
|
|
|
|
|
|
onPlayerMove(callback: (playerMovedEvent: HasPlayerMovedEvent) => void): void
|
2021-05-18 17:05:16 +02:00
|
|
|
getMap(): Promise<ITiledMap>
|
2021-03-04 19:00:00 +01:00
|
|
|
}
|
|
|
|
|
2021-03-05 16:50:54 +01:00
|
|
|
declare global {
|
|
|
|
// eslint-disable-next-line no-var
|
|
|
|
var WA: WorkAdventureApi
|
2021-03-25 17:12:53 +01:00
|
|
|
|
2021-03-05 16:50:54 +01:00
|
|
|
}
|
2021-03-04 19:00:00 +01:00
|
|
|
|
2021-03-06 15:26:07 +01:00
|
|
|
type ChatMessageCallback = (message: string) => void;
|
2021-03-09 18:51:30 +01:00
|
|
|
type ButtonClickedCallback = (popup: Popup) => void;
|
2021-03-06 15:26:07 +01:00
|
|
|
|
|
|
|
const userInputChatStream: Subject<UserInputChatEvent> = new Subject();
|
2021-03-08 18:57:59 +01:00
|
|
|
const enterStreams: Map<string, Subject<EnterLeaveEvent>> = new Map<string, Subject<EnterLeaveEvent>>();
|
|
|
|
const leaveStreams: Map<string, Subject<EnterLeaveEvent>> = new Map<string, Subject<EnterLeaveEvent>>();
|
2021-03-09 18:51:30 +01:00
|
|
|
const popups: Map<number, Popup> = new Map<number, Popup>();
|
|
|
|
const popupCallbacks: Map<number, Map<number, ButtonClickedCallback>> = new Map<number, Map<number, ButtonClickedCallback>>();
|
2021-04-27 11:59:22 +02:00
|
|
|
const menuCallbacks: Map<string, (command: string) => void> = new Map()
|
2021-03-09 16:21:14 +01:00
|
|
|
let popupId = 0;
|
|
|
|
interface ButtonDescriptor {
|
|
|
|
/**
|
|
|
|
* The label of the button
|
|
|
|
*/
|
|
|
|
label: string,
|
|
|
|
/**
|
|
|
|
* The type of the button. Can be one of "normal", "primary", "success", "warning", "error", "disabled"
|
|
|
|
*/
|
2021-05-09 21:30:29 +02:00
|
|
|
className?: "normal" | "primary" | "success" | "warning" | "error" | "disabled",
|
2021-03-09 16:21:14 +01:00
|
|
|
/**
|
|
|
|
* Callback called if the button is pressed
|
|
|
|
*/
|
2021-03-09 18:57:25 +01:00
|
|
|
callback: ButtonClickedCallback,
|
2021-03-09 16:21:14 +01:00
|
|
|
}
|
2021-03-06 15:26:07 +01:00
|
|
|
|
2021-03-09 18:51:30 +01:00
|
|
|
class Popup {
|
|
|
|
constructor(private id: number) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the popup
|
|
|
|
*/
|
|
|
|
public close(): void {
|
|
|
|
window.parent.postMessage({
|
|
|
|
'type': 'closePopup',
|
|
|
|
'data': {
|
|
|
|
'popupId': this.id,
|
|
|
|
} as ClosePopupEvent
|
|
|
|
}, '*');
|
|
|
|
}
|
|
|
|
}
|
2021-05-10 21:27:17 +02:00
|
|
|
function uuidv4() {
|
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
|
|
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
|
|
return v.toString(16);
|
|
|
|
});
|
|
|
|
}
|
2021-05-18 11:33:16 +02:00
|
|
|
function getGameState(): Promise<GameStateEvent> {
|
|
|
|
if (immutableData) {
|
|
|
|
return Promise.resolve(immutableData);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return new Promise<GameStateEvent>((resolver, thrower) => {
|
2021-05-18 15:41:16 +02:00
|
|
|
gameStateResolver.push(resolver);
|
2021-05-18 11:33:16 +02:00
|
|
|
window.parent.postMessage({
|
|
|
|
type: "getState"
|
|
|
|
}, "*")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-05-10 21:27:17 +02:00
|
|
|
|
2021-05-18 17:05:16 +02:00
|
|
|
function getDataLayer(): Promise<DataLayerEvent> {
|
|
|
|
return new Promise<DataLayerEvent>((resolver, thrower) => {
|
|
|
|
dataLayerResolver.push(resolver);
|
|
|
|
postToParent({
|
|
|
|
type: "getDataLayer",
|
|
|
|
data: undefined
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-18 15:41:16 +02:00
|
|
|
const gameStateResolver: Array<(event: GameStateEvent) => void> = []
|
|
|
|
const dataLayerResolver: Array<(event: DataLayerEvent) => void> = []
|
2021-05-18 11:33:16 +02:00
|
|
|
let immutableData: GameStateEvent;
|
2021-03-09 18:51:30 +01:00
|
|
|
|
2021-05-18 11:33:16 +02:00
|
|
|
const callbackPlayerMoved: { [type: string]: HasPlayerMovedEventCallback | ((arg?: HasPlayerMovedEvent | never) => void) } = {}
|
2021-04-21 15:51:01 +02:00
|
|
|
|
2021-05-10 21:27:17 +02:00
|
|
|
|
|
|
|
function postToParent(content: IframeEvent<keyof IframeEventMap>) {
|
|
|
|
window.parent.postMessage(content, "*")
|
|
|
|
}
|
2021-05-18 11:33:16 +02:00
|
|
|
let playerUuid: string | undefined;
|
2021-03-09 18:51:30 +01:00
|
|
|
|
2021-03-04 19:00:00 +01:00
|
|
|
window.WA = {
|
2021-04-21 15:51:01 +02:00
|
|
|
|
2021-05-18 11:33:16 +02:00
|
|
|
onPlayerMove(callback: HasPlayerMovedEventCallback): void {
|
|
|
|
playerUuid = uuidv4();
|
|
|
|
callbackPlayerMoved[playerUuid] = callback;
|
2021-05-10 21:27:17 +02:00
|
|
|
postToParent({
|
2021-05-18 11:33:16 +02:00
|
|
|
type: "onPlayerMove",
|
2021-05-10 21:27:17 +02:00
|
|
|
data: undefined
|
|
|
|
})
|
2021-05-18 11:33:16 +02:00
|
|
|
},
|
2021-04-21 15:51:01 +02:00
|
|
|
|
2021-05-18 17:05:16 +02:00
|
|
|
|
|
|
|
getMap(): Promise<ITiledMap> {
|
|
|
|
return getDataLayer().then((res) => {
|
|
|
|
return res.data as ITiledMap;
|
2021-05-18 11:33:16 +02:00
|
|
|
})
|
2021-05-10 21:27:17 +02:00
|
|
|
},
|
2021-04-21 15:51:01 +02:00
|
|
|
|
2021-05-18 17:05:16 +02:00
|
|
|
getNickName(): Promise<string | null> {
|
2021-05-18 15:41:16 +02:00
|
|
|
return getGameState().then((res) => {
|
|
|
|
return res.nickname;
|
|
|
|
})
|
|
|
|
},
|
2021-05-18 11:33:16 +02:00
|
|
|
|
2021-05-18 17:05:16 +02:00
|
|
|
getMapUrl(): Promise<string> {
|
2021-05-18 11:33:16 +02:00
|
|
|
return getGameState().then((res) => {
|
|
|
|
return res.mapUrl;
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2021-05-18 17:05:16 +02:00
|
|
|
getUuid(): Promise<string | undefined> {
|
2021-05-18 11:33:16 +02:00
|
|
|
return getGameState().then((res) => {
|
|
|
|
return res.uuid;
|
2021-04-21 15:51:01 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2021-05-18 17:05:16 +02:00
|
|
|
getRoomId(): Promise<string> {
|
2021-05-18 11:33:16 +02:00
|
|
|
return getGameState().then((res) => {
|
|
|
|
return res.roomId;
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2021-05-18 17:05:16 +02:00
|
|
|
getStartLayerName(): Promise<string | null> {
|
2021-05-18 11:33:16 +02:00
|
|
|
return getGameState().then((res) => {
|
|
|
|
return res.startLayerName;
|
|
|
|
})
|
|
|
|
},
|
2021-04-21 15:51:01 +02:00
|
|
|
|
2021-03-04 19:00:00 +01:00
|
|
|
/**
|
2021-03-05 16:50:54 +01:00
|
|
|
* Send a message in the chat.
|
2021-03-04 19:00:00 +01:00
|
|
|
* Only the local user will receive this message.
|
|
|
|
*/
|
|
|
|
sendChatMessage(message: string, author: string) {
|
|
|
|
window.parent.postMessage({
|
|
|
|
'type': 'chat',
|
|
|
|
'data': {
|
|
|
|
'message': message,
|
|
|
|
'author': author
|
2021-03-05 16:50:54 +01:00
|
|
|
} as ChatEvent
|
2021-03-04 19:00:00 +01:00
|
|
|
}, '*');
|
2021-03-05 16:50:54 +01:00
|
|
|
},
|
2021-05-10 11:19:18 +02:00
|
|
|
showLayer(layer: string) : void {
|
|
|
|
window.parent.postMessage({
|
|
|
|
'type' : 'showLayer',
|
|
|
|
'data' : {
|
|
|
|
'name' : layer
|
|
|
|
} as LayerEvent
|
|
|
|
}, '*');
|
|
|
|
},
|
|
|
|
hideLayer(layer: string) : void {
|
|
|
|
window.parent.postMessage({
|
|
|
|
'type' : 'hideLayer',
|
|
|
|
'data' : {
|
|
|
|
'name' : layer
|
|
|
|
} as LayerEvent
|
|
|
|
}, '*');
|
|
|
|
},
|
2021-05-12 14:30:12 +02:00
|
|
|
setProperty(layerName: string, propertyName: string, propertyValue: string | number | boolean | undefined): void {
|
|
|
|
window.parent.postMessage({
|
|
|
|
'type' : 'setProperty',
|
|
|
|
'data' : {
|
|
|
|
'layerName' : layerName,
|
|
|
|
'propertyName' : propertyName,
|
|
|
|
'propertyValue' : propertyValue
|
|
|
|
} as SetPropertyEvent
|
|
|
|
}, '*');
|
|
|
|
},
|
2021-05-10 12:14:31 +02:00
|
|
|
disablePlayerControls(): void {
|
|
|
|
window.parent.postMessage({ 'type': 'disablePlayerControls' }, '*');
|
2021-03-12 16:39:29 +01:00
|
|
|
},
|
|
|
|
|
2021-05-10 12:14:31 +02:00
|
|
|
restorePlayerControls(): void {
|
|
|
|
window.parent.postMessage({ 'type': 'restorePlayerControls' }, '*');
|
2021-03-12 16:39:29 +01:00
|
|
|
},
|
|
|
|
|
2021-05-09 21:30:29 +02:00
|
|
|
displayBubble(): void {
|
|
|
|
window.parent.postMessage({ 'type': 'displayBubble' }, '*');
|
2021-03-12 16:39:29 +01:00
|
|
|
},
|
|
|
|
|
2021-05-09 21:30:29 +02:00
|
|
|
removeBubble(): void {
|
|
|
|
window.parent.postMessage({ 'type': 'removeBubble' }, '*');
|
2021-03-12 16:39:29 +01:00
|
|
|
},
|
|
|
|
|
2021-05-09 21:30:29 +02:00
|
|
|
openTab(url: string): void {
|
2021-03-25 17:12:53 +01:00
|
|
|
window.parent.postMessage({
|
2021-05-09 21:30:29 +02:00
|
|
|
"type": 'openTab',
|
|
|
|
"data": {
|
2021-03-25 17:12:53 +01:00
|
|
|
url
|
|
|
|
} as OpenTabEvent
|
2021-05-09 21:30:29 +02:00
|
|
|
}, '*');
|
2021-03-25 17:12:53 +01:00
|
|
|
},
|
|
|
|
|
2021-05-09 21:30:29 +02:00
|
|
|
goToPage(url: string): void {
|
2021-03-25 17:12:53 +01:00
|
|
|
window.parent.postMessage({
|
2021-05-09 21:30:29 +02:00
|
|
|
"type": 'goToPage',
|
|
|
|
"data": {
|
2021-03-25 17:12:53 +01:00
|
|
|
url
|
|
|
|
} as GoToPageEvent
|
2021-05-09 21:30:29 +02:00
|
|
|
}, '*');
|
2021-03-25 17:12:53 +01:00
|
|
|
},
|
|
|
|
|
2021-05-10 21:27:17 +02:00
|
|
|
openCoWebSite(url: string): void {
|
2021-03-25 17:12:53 +01:00
|
|
|
window.parent.postMessage({
|
2021-05-10 21:27:17 +02:00
|
|
|
"type": 'openCoWebSite',
|
|
|
|
"data": {
|
2021-03-25 17:12:53 +01:00
|
|
|
url
|
|
|
|
} as OpenCoWebSiteEvent
|
2021-05-09 21:30:29 +02:00
|
|
|
}, '*');
|
2021-03-25 17:12:53 +01:00
|
|
|
},
|
|
|
|
|
2021-05-09 21:30:29 +02:00
|
|
|
closeCoWebSite(): void {
|
2021-03-25 17:12:53 +01:00
|
|
|
window.parent.postMessage({
|
2021-05-09 21:30:29 +02:00
|
|
|
"type": 'closeCoWebSite'
|
|
|
|
}, '*');
|
2021-03-25 17:12:53 +01:00
|
|
|
},
|
|
|
|
|
2021-03-09 18:51:30 +01:00
|
|
|
openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[]): Popup {
|
2021-03-09 16:21:14 +01:00
|
|
|
popupId++;
|
2021-03-09 18:51:30 +01:00
|
|
|
const popup = new Popup(popupId);
|
|
|
|
const btnMap = new Map<number, () => void>();
|
|
|
|
popupCallbacks.set(popupId, btnMap);
|
|
|
|
let id = 0;
|
|
|
|
for (const button of buttons) {
|
|
|
|
const callback = button.callback;
|
|
|
|
if (callback) {
|
|
|
|
btnMap.set(id, () => {
|
|
|
|
callback(popup);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
|
2021-03-11 10:58:48 +01:00
|
|
|
|
2021-03-09 16:21:14 +01:00
|
|
|
window.parent.postMessage({
|
|
|
|
'type': 'openPopup',
|
|
|
|
'data': {
|
|
|
|
popupId,
|
|
|
|
targetObject,
|
|
|
|
message,
|
|
|
|
buttons: buttons.map((button) => {
|
|
|
|
return {
|
|
|
|
label: button.label,
|
2021-03-09 18:57:25 +01:00
|
|
|
className: button.className
|
2021-03-09 16:21:14 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
} as OpenPopupEvent
|
|
|
|
}, '*');
|
2021-03-09 18:51:30 +01:00
|
|
|
|
|
|
|
popups.set(popupId, popup)
|
|
|
|
return popup;
|
2021-03-09 16:21:14 +01:00
|
|
|
},
|
2021-04-27 11:59:22 +02:00
|
|
|
|
|
|
|
registerMenuCommand(commandDescriptor: string, callback: (commandDescriptor: string) => void) {
|
|
|
|
menuCallbacks.set(commandDescriptor, callback);
|
|
|
|
window.parent.postMessage({
|
|
|
|
'type': 'registerMenuCommand',
|
|
|
|
'data': {
|
|
|
|
menutItem: commandDescriptor
|
|
|
|
} as MenuItemRegisterEvent
|
|
|
|
}, '*');
|
|
|
|
},
|
2021-03-05 16:50:54 +01:00
|
|
|
/**
|
|
|
|
* Listen to messages sent by the local user, in the chat.
|
|
|
|
*/
|
2021-03-06 15:26:07 +01:00
|
|
|
onChatMessage(callback: ChatMessageCallback): void {
|
|
|
|
userInputChatStream.subscribe((userInputChatEvent) => {
|
|
|
|
callback(userInputChatEvent.message);
|
|
|
|
});
|
2021-03-08 18:57:59 +01:00
|
|
|
},
|
|
|
|
onEnterZone(name: string, callback: () => void): void {
|
|
|
|
let subject = enterStreams.get(name);
|
|
|
|
if (subject === undefined) {
|
|
|
|
subject = new Subject<EnterLeaveEvent>();
|
|
|
|
enterStreams.set(name, subject);
|
|
|
|
}
|
|
|
|
subject.subscribe(callback);
|
|
|
|
},
|
|
|
|
onLeaveZone(name: string, callback: () => void): void {
|
|
|
|
let subject = leaveStreams.get(name);
|
|
|
|
if (subject === undefined) {
|
|
|
|
subject = new Subject<EnterLeaveEvent>();
|
|
|
|
leaveStreams.set(name, subject);
|
|
|
|
}
|
|
|
|
subject.subscribe(callback);
|
|
|
|
},
|
2021-03-04 19:00:00 +01:00
|
|
|
}
|
2021-03-06 15:26:07 +01:00
|
|
|
|
|
|
|
window.addEventListener('message', message => {
|
|
|
|
if (message.source !== window.parent) {
|
|
|
|
return; // Skip message in this event listener
|
|
|
|
}
|
|
|
|
|
|
|
|
const payload = message.data;
|
2021-03-08 18:57:59 +01:00
|
|
|
|
2021-05-09 21:30:29 +02:00
|
|
|
console.debug(payload);
|
2021-03-08 18:57:59 +01:00
|
|
|
|
2021-05-09 21:30:29 +02:00
|
|
|
if (isIframeResponseEventWrapper(payload)) {
|
2021-03-08 18:57:59 +01:00
|
|
|
const payloadData = payload.data;
|
|
|
|
if (payload.type === 'userInputChat' && isUserInputChatEvent(payloadData)) {
|
|
|
|
userInputChatStream.next(payloadData);
|
|
|
|
} else if (payload.type === 'enterEvent' && isEnterLeaveEvent(payloadData)) {
|
|
|
|
enterStreams.get(payloadData.name)?.next();
|
|
|
|
} else if (payload.type === 'leaveEvent' && isEnterLeaveEvent(payloadData)) {
|
|
|
|
leaveStreams.get(payloadData.name)?.next();
|
2021-03-09 18:05:07 +01:00
|
|
|
} else if (payload.type === 'buttonClickedEvent' && isButtonClickedEvent(payloadData)) {
|
|
|
|
const callback = popupCallbacks.get(payloadData.popupId)?.get(payloadData.buttonId);
|
2021-03-09 18:51:30 +01:00
|
|
|
const popup = popups.get(payloadData.popupId);
|
|
|
|
if (popup === undefined) {
|
2021-05-09 21:30:29 +02:00
|
|
|
throw new Error('Could not find popup with ID "' + payloadData.popupId + '"');
|
2021-03-09 18:51:30 +01:00
|
|
|
}
|
2021-03-09 18:05:07 +01:00
|
|
|
if (callback) {
|
2021-03-09 18:51:30 +01:00
|
|
|
callback(popup);
|
2021-03-09 18:05:07 +01:00
|
|
|
}
|
2021-05-10 21:27:17 +02:00
|
|
|
} else if (payload.type == "gameState" && isGameStateEvent(payloadData)) {
|
2021-05-18 15:41:16 +02:00
|
|
|
gameStateResolver.forEach(resolver => {
|
2021-04-21 15:51:01 +02:00
|
|
|
resolver(payloadData);
|
|
|
|
})
|
2021-05-18 11:33:16 +02:00
|
|
|
immutableData = payloadData;
|
|
|
|
} else if (payload.type == "hasPlayerMoved" && isHasPlayerMovedEvent(payloadData) && playerUuid) {
|
|
|
|
callbackPlayerMoved[playerUuid](payloadData)
|
2021-05-18 15:41:16 +02:00
|
|
|
} else if (payload.type == "dataLayer" && isDataLayerEvent(payloadData)) {
|
|
|
|
dataLayerResolver.forEach(resolver => {
|
|
|
|
resolver(payloadData);
|
|
|
|
})
|
2021-04-27 11:59:22 +02:00
|
|
|
} else if (payload.type == "menuItemClicked" && isMenuItemClickedEvent(payload.data)) {
|
|
|
|
const callback = menuCallbacks.get(payload.data.menuItem);
|
|
|
|
if (callback) {
|
|
|
|
callback(payload.data.menuItem)
|
|
|
|
}
|
2021-03-06 15:26:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...
|
|
|
|
});
|