Adding a "allowApi" property to authorize the API in a website.

This commit is contained in:
David Négrier 2021-07-23 23:06:59 +02:00
parent ce3c53ae3f
commit 5bb29e99ba
3 changed files with 46 additions and 0 deletions

View file

@ -200,6 +200,7 @@ export class GameScene extends DirtyScene {
private startPositionCalculator!: StartPositionCalculator;
private sharedVariablesManager!: SharedVariablesManager;
private objectsByType = new Map<string, ITiledMapObject[]>();
private inMapIframes = new Array<HTMLIFrameElement>();
constructor(private room: Room, MapUrlFile: string, customKey?: string | undefined) {
super({
@ -497,6 +498,15 @@ export class GameScene extends DirtyScene {
iframe.style.border = "none";
this.add.dom(object.x, object.y).setElement(iframe).setOrigin(0, 0);
const allowApi = PropertyUtils.findBooleanProperty(
"allowApi",
object.properties,
);
if (allowApi) {
iframeListener.registerIframe(iframe);
this.inMapIframes.push(iframe);
}
}
}
}
@ -1293,6 +1303,9 @@ ${escapedMessage}
for (const script of scripts) {
iframeListener.unregisterScript(script);
}
for (const iframe of this.inMapIframes) {
iframeListener.unregisterIframe(iframe);
}
this.stopJitsi();
audioManager.unloadAudio();

View file

@ -8,6 +8,23 @@ export class PropertyUtils {
return properties?.find((property) => property.name === name)?.value;
}
public static findBooleanProperty(
name: string,
properties: ITiledMapProperty[] | undefined,
context?: string
): boolean | undefined {
const property = PropertyUtils.findProperty(name, properties);
if (property === undefined) {
return undefined;
}
if (typeof property !== "boolean") {
throw new Error(
'Expected property "' + name + '" to be a boolean. ' + (context ? " (" + context + ")" : "")
);
}
return property;
}
public static mustFindProperty(
name: string,
properties: ITiledMapProperty[] | undefined,