Skip to content

Commit

Permalink
fix(wasm-api-dom): fix fullscreen support for Safari
Browse files Browse the repository at this point in the history
- ofc Safari doesn't support the standard API =;-(
  • Loading branch information
postspectacular committed Oct 29, 2022
1 parent 1d9c543 commit 1ad855a
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions packages/wasm-api-dom/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ export class WasmDom implements IWasmAPI<DOMExports> {
info.scrollX = window.scrollX;
info.scrollY = window.scrollY;
info.fullscreen =
(document.fullscreenElement ? 1 : 0) |
(document.fullscreenEnabled ? 2 : 0);
(document.fullscreenElement ||
(<any>document).webkitFullscreenElement
? 1
: 0) |
(document.fullscreenEnabled ||
(<any>document).webkitFullscreenEnabled
? 2
: 0);
},

createElement: (optsAddr: number) => {
Expand Down Expand Up @@ -303,19 +309,33 @@ export class WasmDom implements IWasmAPI<DOMExports> {
},

_requestFullscreen: async (elementID: number) => {
if (!document.fullscreenElement) {
if (
!(
document.fullscreenElement ||
(<any>document).webkitFullscreenElement
)
) {
const el =
elementID <= 0
? document.documentElement
: this.elements.get(elementID);
await el.requestFullscreen();
const method =
el.requestFullscreen ||
(<any>el).webkitRequestFullscreen;
await method.bind(el)();
this.parent.exports.dom_fullscreenChanged();
}
},

_exitFullscreen: async () => {
if (document.fullscreenElement) {
await document.exitFullscreen();
if (
document.fullscreenElement ||
(<any>document).webkitFullscreenElement
) {
const method =
document.exitFullscreen ||
(<any>document).webkitExitFullscreen;
await method.bind(document)();
this.parent.exports.dom_fullscreenChanged();
}
},
Expand Down

0 comments on commit 1ad855a

Please sign in to comment.