From 007ef41383820db0f331e3c0c3c8d718d269f653 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Tue, 24 Nov 2026 14:10:37 +0200 Subject: [PATCH 1/2] fix(play): a framing page can say that a file did not come, and the page then asks the person for it (#106) --- README.md | 2 +- src/h5p/play/play-page.ts | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f21b644..af12b47 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The site of the [missing-elements](https://github.com/missing-elements) web comp | `/` | The project list, the tools (the build page first, with its how-to), and a footer of links | [src/index.njk](src/index.njk); the lists are in [src/_data/site.js](src/_data/site.js) | | `/pdfjs-viewer/` | The docs of ``, with a live preview | [src/pdfjs-viewer/](src/pdfjs-viewer/) | | `/h5p/build/` | The build page, for people: what it makes, a sample that plays, and the build of a chat's source into a `.h5p`, in the visitor's browser | [src/h5p/build/](src/h5p/build/) | -| `/h5p/play/` | The play page, for a chat app to show in its reply (h5p-toolkit#210); no page links to it. It builds the activity in a link's `#source=` in the visitor's browser, as the build page does, and plays it with nothing beside it but its download and a link to the build page. A file of the visitor's own that the source names is chosen there or given by the page that frames it. A video or a recording can be given as its address: it plays from there at once and is fetched whole only for the download. A framing page that saves files itself is handed the download. A package bigger than that page saves stays behind the Download link, and the page says how to save it from such a frame. A framing page that opens links itself is handed the link to the build page. A link to the page may also carry the files' addresses and a wish to save (`&links=`, `&save=1`): in a tab of its own the page then draws no player: it fetches the files itself, builds the package and tries to save it with no press. Saved, it counts five seconds while it is looked at and then tries to close the tab; a tab the browser keeps open says to press Download where nothing was saved. That is how a framing page that opens links gets a package saved that it cannot save itself. | [src/h5p/play/](src/h5p/play/) | +| `/h5p/play/` | The play page, for a chat app to show in its reply (h5p-toolkit#210); no page links to it. It builds the activity in a link's `#source=` in the visitor's browser, as the build page does, and plays it with nothing beside it but its download and a link to the build page. A file of the visitor's own that the source names is chosen there or given by the page that frames it. A video or a recording can be given as its address: it plays from there at once and is fetched whole only for the download. A framing page that could not bring a file it was asked for says so, and the page asks the visitor for it. A framing page that saves files itself is handed the download. A package bigger than that page saves stays behind the Download link, and the page says how to save it from such a frame. A framing page that opens links itself is handed the link to the build page. A link to the page may also carry the files' addresses and a wish to save (`&links=`, `&save=1`): in a tab of its own the page then draws no player: it fetches the files itself, builds the package and tries to save it with no press. Saved, it counts five seconds while it is looked at and then tries to close the tab; a tab the browser keeps open says to press Download where nothing was saved. That is how a framing page that opens links gets a package saved that it cannot save itself. | [src/h5p/play/](src/h5p/play/) | | `/h5p/create-with-ai/` | The how-to, for people: installing the skill, asking a chat, the prompts to start from, the types, and what to do when something goes wrong | [src/h5p/create-with-ai/](src/h5p/create-with-ai/) | | `/h5p/skill/` | The skill as zips to install: `h5p-author.zip`, installed once in a chat's place for skills, or attached to the message in each new chat where it has none, and `h5p-author-chatgpt.zip`, the same skill laid out as a plugin; and a page that lists them and the bundles' addresses, each in full, which no page links to | [src/h5p/skill/](src/h5p/skill/); the zips written by [vite.config.ts](vite.config.ts) | | `/h5p/bundles/` | The skill's build tool and a library bundle per content type, for a chat that runs Node but cannot reach npm; and `h5p-author-build.tar.gz`, the tool and every library in one archive, for a person to attach to a chat whose code can download nothing | written by [vite.config.ts](vite.config.ts) | diff --git a/src/h5p/play/play-page.ts b/src/h5p/play/play-page.ts index 390494c..b744be9 100644 --- a/src/h5p/play/play-page.ts +++ b/src/h5p/play/play-page.ts @@ -453,17 +453,37 @@ async function fetchFiles(): Promise { } catch (error) { // Stopped for a file the person chose: that one is built from. if (stop.signal.aborted) return - bringing = false - const text = `Your ${previewedAs()} could not be fetched from the chat (${error instanceof Error ? error.message : String(error)}): its address may have run out. Choose it from your computer instead.` - keepInstead.hidden = false - keepProgress.hidden = true - keepLabel.textContent = text - download.removeAttribute('aria-disabled') - downloadLabel.textContent = 'Try again' - announce(text) + notBrought(error instanceof Error ? error.message : String(error)) } } +/** The files for a download did not come, to this page or to the parent that was asked for them: said under the stage, with the way on. */ +function notBrought(why = ''): void { + bringing = false + const text = `Your ${previewedAs()} could not be fetched from the chat${why ? ` (${why})` : ''}: its address may have run out. Choose it from your computer instead.` + keepInstead.hidden = false + keepProgress.hidden = true + keepLabel.textContent = text + download.removeAttribute('aria-disabled') + downloadLabel.textContent = 'Try again' + announce(text) +} + +/** + * The parent says a file it was asked for did not come (#106). For a download, that is said + * under the stage. For a file the activity is waiting to be built with, the person is asked for + * it, with the reason. At any other time it says nothing new. + */ +function failed(): void { + if (bringing && previewed.length) return notBrought() + if (main.dataset.state !== 'fetching' || whole || packing) return + const { missing } = filesFor(wanted) + if (!missing.length) return + ask(missing) + const one = missing.length === 1 + askText.textContent = `Your ${one ? called(missing[0]!) : 'files'} could not be fetched from the chat. Choose ${one ? 'it' : 'them'} from your computer; ${one ? 'it stays' : 'they stay'} in your browser.` +} + /** * In a tab that only saves: the files fetched from the addresses the link carried, shown coming in * the stage, and then built from. One that cannot be fetched is asked for, as where none was given. @@ -774,13 +794,14 @@ function takeLinks(given: Record, sizes: Record { if (!framed || event.source !== window.parent) return const message = event.data as { source?: unknown, type?: unknown, files?: unknown, links?: unknown, sizes?: unknown, name?: unknown, received?: unknown, total?: unknown, theme?: unknown, max?: unknown, id?: unknown, ok?: unknown } | null if (message?.source !== 'h5p-play-host') return if (message.type === 'files' && Array.isArray(message.files)) take(message.files.filter((file): file is File => file instanceof File)) else if (message.type === 'links' && message.links && typeof message.links === 'object') takeLinks(message.links as Record, message.sizes && typeof message.sizes === 'object' ? message.sizes as Record : {}) + else if (message.type === 'failed') failed() else if (message.type === 'saves') hostSaves = amount(message.max) ?? Infinity else if (message.type === 'opens') hostOpens = true else if (message.type === 'saved' && handedId && message.id === handedId && typeof message.ok === 'boolean' && (handed || message.ok)) saveDone(message.ok) From 611edcdb8eebf544bbd9afeb70affb373b6c239c Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Tue, 24 Nov 2026 14:15:19 +0200 Subject: [PATCH 2/2] fix(play): a file that did not come is said also before any of it came, and with the question shown (#106) --- src/h5p/play/play-page.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/h5p/play/play-page.ts b/src/h5p/play/play-page.ts index b744be9..61ef404 100644 --- a/src/h5p/play/play-page.ts +++ b/src/h5p/play/play-page.ts @@ -472,12 +472,15 @@ function notBrought(why = ''): void { /** * The parent says a file it was asked for did not come (#106). For a download, that is said * under the stage. For a file the activity is waiting to be built with, the person is asked for - * it, with the reason. At any other time it says nothing new. + * it, with the reason: while it is shown coming, while the question is held back a moment for + * the parent's answer, and where the question is shown already. At any other time it says + * nothing new. */ function failed(): void { if (bringing && previewed.length) return notBrought() - if (main.dataset.state !== 'fetching' || whole || packing) return - const { missing } = filesFor(wanted) + const waiting = main.dataset.state === 'fetching' || main.dataset.state === 'asking' || askTimer !== undefined + if (!waiting || whole || packing) return + const { missing } = linksFor(filesFor(wanted).missing) if (!missing.length) return ask(missing) const one = missing.length === 1