Skip to content

Commit 007ef41

Browse files
committed
fix(play): a framing page can say that a file did not come, and the page then asks the person for it (#106)
1 parent cb6410a commit 007ef41

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The site of the [missing-elements](https://github.com/missing-elements) web comp
99
| `/` | 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) |
1010
| `/pdfjs-viewer/` | The docs of `<pdfjs-viewer-element>`, with a live preview | [src/pdfjs-viewer/](src/pdfjs-viewer/) |
1111
| `/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/) |
12-
| `/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/) |
12+
| `/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/) |
1313
| `/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/) |
1414
| `/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) |
1515
| `/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) |

‎src/h5p/play/play-page.ts‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,17 +453,37 @@ async function fetchFiles(): Promise<void> {
453453
} catch (error) {
454454
// Stopped for a file the person chose: that one is built from.
455455
if (stop.signal.aborted) return
456-
bringing = false
457-
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.`
458-
keepInstead.hidden = false
459-
keepProgress.hidden = true
460-
keepLabel.textContent = text
461-
download.removeAttribute('aria-disabled')
462-
downloadLabel.textContent = 'Try again'
463-
announce(text)
456+
notBrought(error instanceof Error ? error.message : String(error))
464457
}
465458
}
466459

460+
/** 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. */
461+
function notBrought(why = ''): void {
462+
bringing = false
463+
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.`
464+
keepInstead.hidden = false
465+
keepProgress.hidden = true
466+
keepLabel.textContent = text
467+
download.removeAttribute('aria-disabled')
468+
downloadLabel.textContent = 'Try again'
469+
announce(text)
470+
}
471+
472+
/**
473+
* The parent says a file it was asked for did not come (#106). For a download, that is said
474+
* under the stage. For a file the activity is waiting to be built with, the person is asked for
475+
* it, with the reason. At any other time it says nothing new.
476+
*/
477+
function failed(): void {
478+
if (bringing && previewed.length) return notBrought()
479+
if (main.dataset.state !== 'fetching' || whole || packing) return
480+
const { missing } = filesFor(wanted)
481+
if (!missing.length) return
482+
ask(missing)
483+
const one = missing.length === 1
484+
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.`
485+
}
486+
467487
/**
468488
* In a tab that only saves: the files fetched from the addresses the link carried, shown coming in
469489
* 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<string, unknown>, sizes: Record<string, unknown
774794
// From the frame's parent, which may hold what the person attached in the chat: the files, how
775795
// much of one has come so far, and the chat's theme where it is not the system's. And from one
776796
// that saves files itself: that it does, with the most it takes, and how a save went; and from
777-
// one that opens links itself, that it does.
797+
// one that opens links itself, that it does. And that a file it was asked for did not come.
778798
window.addEventListener('message', (event) => {
779799
if (!framed || event.source !== window.parent) return
780800
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
781801
if (message?.source !== 'h5p-play-host') return
782802
if (message.type === 'files' && Array.isArray(message.files)) take(message.files.filter((file): file is File => file instanceof File))
783803
else if (message.type === 'links' && message.links && typeof message.links === 'object') takeLinks(message.links as Record<string, unknown>, message.sizes && typeof message.sizes === 'object' ? message.sizes as Record<string, unknown> : {})
804+
else if (message.type === 'failed') failed()
784805
else if (message.type === 'saves') hostSaves = amount(message.max) ?? Infinity
785806
else if (message.type === 'opens') hostOpens = true
786807
else if (message.type === 'saved' && handedId && message.id === handedId && typeof message.ok === 'boolean' && (handed || message.ok)) saveDone(message.ok)

0 commit comments

Comments
 (0)