Adding button clicked handling
This commit is contained in:
parent
1e002f93ed
commit
18464e4942
5 changed files with 51 additions and 6 deletions
11
front/src/Api/Events/ButtonClickedEvent.ts
Normal file
11
front/src/Api/Events/ButtonClickedEvent.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isButtonClickedEvent =
|
||||
new tg.IsInterface().withProperties({
|
||||
popupId: tg.isNumber,
|
||||
buttonId: tg.isNumber,
|
||||
}).get();
|
||||
/**
|
||||
* A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property.
|
||||
*/
|
||||
export type ButtonClickedEvent = tg.GuardedType<typeof isButtonClickedEvent>;
|
|
@ -6,14 +6,13 @@ const isButtonDescriptor =
|
|||
className: tg.isOptional(tg.isString),
|
||||
closeOnClick: tg.isOptional(tg.isBoolean)
|
||||
}).get();
|
||||
type ButtonDescriptor = tg.GuardedType<typeof isButtonDescriptor>;
|
||||
|
||||
export const isOpenPopupEvent =
|
||||
new tg.IsInterface().withProperties({
|
||||
popupId: tg.isNumber,
|
||||
targetObject: tg.isString,
|
||||
message: tg.isString,
|
||||
buttons: tg.isAny //tg.isArray<ButtonDescriptor>,
|
||||
buttons: tg.isArray(isButtonDescriptor)
|
||||
}).get();
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@ import * as crypto from "crypto";
|
|||
import {HtmlUtils} from "../WebRtc/HtmlUtils";
|
||||
import {EnterLeaveEvent} from "./Events/EnterLeaveEvent";
|
||||
import {isOpenPopupEvent, OpenPopupEvent} from "./Events/OpenPopupEvent";
|
||||
import {ButtonClickedEvent} from "./Events/ButtonClickedEvent";
|
||||
|
||||
|
||||
|
||||
|
@ -40,13 +41,10 @@ class IframeListener {
|
|||
}
|
||||
|
||||
const payload = message.data;
|
||||
console.log('FOO');
|
||||
if (isIframeEventWrapper(payload)) {
|
||||
console.log('FOOBAR', payload);
|
||||
if (payload.type === 'chat' && isChatEvent(payload.data)) {
|
||||
this._chatStream.next(payload.data);
|
||||
} else if (payload.type === 'openPopup' && isOpenPopupEvent(payload.data)) {
|
||||
console.log('OPENPOPUP called');
|
||||
this._openPopupStream.next(payload.data);
|
||||
}
|
||||
}
|
||||
|
@ -158,6 +156,16 @@ class IframeListener {
|
|||
});
|
||||
}
|
||||
|
||||
sendButtonClickedEvent(popupId: number, buttonId: number): void {
|
||||
this.postMessage({
|
||||
'type': 'buttonClickedEvent',
|
||||
'data': {
|
||||
popupId,
|
||||
buttonId
|
||||
} as ButtonClickedEvent
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the message... to all allowed iframes.
|
||||
*/
|
||||
|
@ -166,6 +174,7 @@ class IframeListener {
|
|||
iframe.contentWindow?.postMessage(message, '*');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const iframeListener = new IframeListener();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue