Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<pdfjs-viewer-element>`, 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) |
Expand Down
42 changes: 33 additions & 9 deletions src/h5p/play/play-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,40 @@ async function fetchFiles(): Promise<void> {
} 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: 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()
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
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.
Expand Down Expand Up @@ -774,13 +797,14 @@ function takeLinks(given: Record<string, unknown>, sizes: Record<string, unknown
// From the frame's parent, which may hold what the person attached in the chat: the files, how
// much of one has come so far, and the chat's theme where it is not the system's. And from one
// that saves files itself: that it does, with the most it takes, and how a save went; and from
// one that opens links itself, that it does.
// one that opens links itself, that it does. And that a file it was asked for did not come.
window.addEventListener('message', (event) => {
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<string, unknown>, message.sizes && typeof message.sizes === 'object' ? message.sizes as Record<string, unknown> : {})
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)
Expand Down