diff --git a/docker-compose.yml b/docker-compose.yml index b64be6106..f4fb5c89b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,8 @@ services: - /app/frontend/node_modules # Empty directory - /app/frontend/dist # Empty directory - ./romm_mock:/app/romm + # The dev server reads the player isolation URLs out of the nginx map. + - ./docker/nginx/templates:/app/docker/nginx/templates:ro - ~/.vite-plugin-mkcert:/app/.vite-plugin-mkcert depends_on: - romm-db-dev diff --git a/frontend/scripts/playerIsolationHeaders.ts b/frontend/scripts/playerIsolationHeaders.ts index ddc395d6d..7ed641061 100644 --- a/frontend/scripts/playerIsolationHeaders.ts +++ b/frontend/scripts/playerIsolationHeaders.ts @@ -1,10 +1,7 @@ /** - * playerIsolationHeaders: the dev server's stand-in for nginx's COOP/COEP map. - * - * Threaded EmulatorJS cores and js-dos need SharedArrayBuffer, which only a - * cross-origin isolated document exposes, and only the player URLs may be - * isolated, since the rest of the app embeds third-party images that COEP - * would block. The URLs come from the nginx template so there is one list. + * The dev server's stand-in for nginx's COOP/COEP map, reading its URLs from + * the nginx template so the two cannot drift. Only the player URLs are + * isolated: COEP would block the third-party images the rest of the app embeds. */ import { readFileSync } from "node:fs"; import type { Connect, Plugin } from "vite"; diff --git a/frontend/src/v2/composables/useIsolatedLaunch/index.ts b/frontend/src/v2/composables/useIsolatedLaunch/index.ts index febd5b84e..c4e93044e 100644 --- a/frontend/src/v2/composables/useIsolatedLaunch/index.ts +++ b/frontend/src/v2/composables/useIsolatedLaunch/index.ts @@ -1,9 +1,7 @@ // useIsolatedLaunch: reloading a player view into a cross-origin isolated -// document, which is the only kind that exposes SharedArrayBuffer. Nginx -// attaches the COOP/COEP headers to the player URLs, so reloading the view is -// what isolates it, and the pre-play selection crosses as an intent kept per -// tab. Pair it with usePlayerExit, which drops the isolation on the way out. -// EmulatorJS.vue and JsDos.vue are the two callers. +// document, the only kind that exposes SharedArrayBuffer. Nginx isolates the +// player URLs, so the reload is what earns it, and the pre-play selection +// crosses as an intent kept per tab. See also usePlayerExit. import { ref, type Ref } from "vue"; export function hasSharedArrayBuffer(): boolean { diff --git a/frontend/src/v2/composables/usePlayerExit/index.ts b/frontend/src/v2/composables/usePlayerExit/index.ts index d823ce7cb..76d789ded 100644 --- a/frontend/src/v2/composables/usePlayerExit/index.ts +++ b/frontend/src/v2/composables/usePlayerExit/index.ts @@ -1,10 +1,7 @@ -// usePlayerExit: how a player view hands the tab back to the app. -// -// Two things bind a player to its document: cross-origin isolation, which -// outlives every SPA navigation after it and blocks the third-party images the -// app embeds elsewhere, and a runtime that cannot be injected twice. Either -// leaves the app a fresh document to resume in; otherwise leaving is an SPA -// navigation. +// usePlayerExit: how a player view hands the tab back to the app. Cross-origin +// isolation outlives every SPA navigation after it and blocks the third-party +// images the app embeds elsewhere, and a runtime cannot always be injected +// twice, so a bound document is replaced rather than navigated away from. import { ref, type Ref } from "vue"; import { useRouter, type RouteLocationNormalized } from "vue-router"; @@ -13,18 +10,13 @@ export function usePlayerExit( runtimeBound: () => boolean = () => false, /** * Work the departing document still owes, awaited before it is replaced. - * A replace aborts the navigation, so the leave guards of the components - * below never run and whatever they would have flushed belongs here. + * A replace aborts the navigation, so the guards below never run. */ settle: () => Promise | void = () => undefined, ): { /** True once an exit is replacing the document, so an unload prompt can stand down. */ departing: Ref; - /** - * Go to `path` in place of the player, by a full navigation when the document - * is bound. The player is replaced either way, so Back never re-enters the - * view it just left and relaunches the game. - */ + /** Go to `path` in place of the player, so Back never re-enters it. */ leave: (path: string) => void; /** `onBeforeRouteLeave` guard: lets a departure through unless bound. */ guard: (to: Pick) => Promise; diff --git a/frontend/src/v2/views/Player/jsDosRuntime.ts b/frontend/src/v2/views/Player/jsDosRuntime.ts index 7ede9b449..4e1d2bee2 100644 --- a/frontend/src/v2/views/Player/jsDosRuntime.ts +++ b/frontend/src/v2/views/Player/jsDosRuntime.ts @@ -1,13 +1,11 @@ -// The js-dos runtime is a document-level singleton: one injection and one asset -// base however many launch views mount. Held as the in-flight promise, so a -// view mounting while another is still loading waits for that load instead of -// injecting a second copy of a runtime that declares its own globals. +// The js-dos runtime is a document-level singleton, held as the in-flight +// promise so a second mount waits for that load rather than injecting another +// copy of a runtime that declares its own globals. import { isJsResource, loadScript } from "@/v2/utils/scriptLoader"; export const LOCAL_BASE = "/assets/jsdos"; -// Fallback for slim images and the dev server, which ship no local copy. Pinned -// to the image's JSDOS_VERSION; jsDelivr sends the CORP a directly opened player -// document needs under its COEP. +// Fallback for slim images and the dev server, pinned to the image's +// JSDOS_VERSION. jsDelivr sends the CORP the player's COEP needs. export const CDN_BASE = "https://cdn.jsdelivr.net/npm/js-dos@8.4.1/dist"; let pending: Promise | null = null;