This commit is contained in:
Zef Hemel
2023-11-15 10:08:21 +01:00
parent 4acfd96011
commit 8a7c50599d
8 changed files with 51 additions and 2 deletions
+17 -1
View File
@@ -77,13 +77,29 @@ function claimIFrame(): PreloadedIFrame {
}
}
// Nothing available in the pool, let's spin up a new one and add it to the pool
console.log("Yeah this shouldn't happen");
console.warn("Had to create a new iframe on the fly, this shouldn't happen");
const newPreloadedIFrame = prepareSandboxIFrame();
newPreloadedIFrame.used = true;
iframePool.add(newPreloadedIFrame);
return newPreloadedIFrame;
}
export function broadcastReload() {
for (const preloadedIframe of iframePool) {
if (preloadedIframe.used) {
// Send a message to the global object, which the iframe is listening to
globalThis.dispatchEvent(
new MessageEvent("message", {
source: preloadedIframe.iframe.contentWindow,
data: {
type: "reload",
},
}),
);
}
}
}
export function mountIFrame(
preloadedIFrame: PreloadedIFrame,
client: Client,