Implementation of openPopup script method (WIP)
This commit is contained in:
parent
ed2ce68f37
commit
1e002f93ed
7 changed files with 184 additions and 36 deletions
22
front/src/Api/Events/OpenPopupEvent.ts
Normal file
22
front/src/Api/Events/OpenPopupEvent.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
const isButtonDescriptor =
|
||||
new tg.IsInterface().withProperties({
|
||||
label: tg.isString,
|
||||
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>,
|
||||
}).get();
|
||||
|
||||
/**
|
||||
* A message sent from the iFrame to the game to add a message in the chat.
|
||||
*/
|
||||
export type OpenPopupEvent = tg.GuardedType<typeof isOpenPopupEvent>;
|
|
@ -5,6 +5,7 @@ import {UserInputChatEvent} from "./Events/UserInputChatEvent";
|
|||
import * as crypto from "crypto";
|
||||
import {HtmlUtils} from "../WebRtc/HtmlUtils";
|
||||
import {EnterLeaveEvent} from "./Events/EnterLeaveEvent";
|
||||
import {isOpenPopupEvent, OpenPopupEvent} from "./Events/OpenPopupEvent";
|
||||
|
||||
|
||||
|
||||
|
@ -16,6 +17,9 @@ class IframeListener {
|
|||
private readonly _chatStream: Subject<ChatEvent> = new Subject();
|
||||
public readonly chatStream = this._chatStream.asObservable();
|
||||
|
||||
private readonly _openPopupStream: Subject<OpenPopupEvent> = new Subject();
|
||||
public readonly openPopupStream = this._openPopupStream.asObservable();
|
||||
|
||||
private readonly iframes = new Set<HTMLIFrameElement>();
|
||||
private readonly scripts = new Map<string, HTMLIFrameElement>();
|
||||
|
||||
|
@ -36,9 +40,14 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue