feat(play): a video from the chat plays from its link at once, and is fetched whole only for Download (#92)

Merged
AL
1d ago
+264-24

Closes #92. Part of missing-elements/h5p-toolkit#210.

A video or a recording attached in a chat now plays in the play page at once, from its link, instead of after the whole file has come. The whole file is fetched only when the person presses Download.

For the page that frames this one

All optional; a framing page that sends files as before is served as before.

MessageWayWhat it does
{ type: 'links', links: { 'clip.mp4': 'https://…' } }to the pageA video's or a recording's address instead of its bytes. The activity is built with it left there (h5p-author 0.16.0's linked) and plays at once. A picture, or an address that is not http(s), is left out.
{ type: 'needs-bytes', names }from the pageDownload was pressed on a preview: send the files' bytes, as files. progress messages meanwhile are drawn under the stage. Sent once, however often Download is pressed.
files, while a preview playsto the pageAsked for or not, they make the package with the files in it, and the activity plays on. It is saved only where Download was pressed; sent unasked, they make Download a link to it.
files, once the package with its files in it playsto the pageChange nothing: the activity is not started again.
builtfrom the pageNot sent for a preview, since its address expires. Sent once, when the package with the files in it is built.

What a person sees

  • The video plays at once. In a framed test, ready 1.1 s after the page opened. Under the stage: "Interactive Video · its video plays from the chat", not a size.
  • Download of a preview: the button says "Preparing…", and a row under the stage shows "Getting your video for the download… 1.0 MB of 2.1 MB" with a bar, while the activity keeps playing. The person can choose the file from their computer instead. Then the package is built with the file in it, saved, and given to the framing page; the row goes and the size shows.
  • Nothing is saved that was not pressed for, and one package is saved for one press.
  • No flash of "Add your video" when the framing page holds the file: framed, the question waits 1.2 s for its answer, an address or a count of a file on its way, with the loader showing. Where nothing comes, it appears as before.
  • The activity's own frame has square corners (owner's review): the stage rounded its corners in every state and cut the activity's. It now rounds only what the page draws there: the loader, the question for a file, a problem.
  • The author pin moves to 0.16.0.

Review

A review of the first commit found these, fixed in the second; the first two cubic found too.

  • Files sent unasked while a preview played saved a download nobody pressed for.
  • Files from the person and from the framing page at once built and saved two packages.
  • A file that came after the whole package was built started the activity again under the person.
  • "Try again" after a build that failed asked the framing page for bytes the page already held.
  • A count of a file on its way, sent while the question was held back, was dropped, and the question flashed up.
  • An address given while a build with every file was running started that build again.
  • The preview's Download linked to #download, a damaged link where opened in a new tab; it links to the page itself.

Testing

By hand, as this repository has no page tests: the built site served locally and framed by a page of another origin acting as the card, with a store on a third origin that answers for parts and sends no CORS header to a video element.

  • Light and dark at 720 px, light at 360 px: the activity reaches ready in 1.0–1.3 s. The player's only request to the store is bytes=0-, a request for part of the file; nothing is fetched whole before Download.
  • Download answered by the card: one needs-bytes; the count drawn; one package with the video saved, 6.3 MB, as construction-site-walkthrough.h5p; one built; the activity still ready, never started again.
  • Download pressed twice, then the file chosen from the computer while the card still brings its copy: one needs-bytes, one package saved, one built, and nothing happens when the card's copy comes.
  • A card that sends the file unasked after the address: nothing saved, no row, one built, Download a link to the 6.3 MB package, which a press then saves.
  • A card that sends no address, only the file with its count: fetching, then building, then ready; the question is never shown.
  • With no answer at all: "Add your video" after the wait, and a file given still builds and plays; the ready and problem states as in #91.
  • No page error in any run. pnpm build and pnpm typecheck pass. Screenshots of each state looked at.

Not verified

  • Not in ChatGPT: the card has to send links and answer needs-bytes first, the next step of h5p-toolkit#210.
  • A build of the package to keep that fails, and its "Try again": nothing in the tests made that build fail.
  • A link that expires while the activity is open (under an hour on ChatGPT) is not handled here: the video would stop loading. To do with the card, which can ask ChatGPT for a fresh one.
  • Whether the browser saves the file from inside a chat's card frame; where it does not, the card has the file from built.
  • A framing page that never answers needs-bytes leaves "Preparing…" and the row, with the choice of the file from the computer.
  • Chromium only.

Summary by cubic

A video or a recording attached in a chat now plays in the play page immediately, from the address the framing page provides, instead of after the whole file has downloaded. The whole file is fetched only when the person presses Download.

For the framing page

  • A links message gives a video's or a recording's address instead of its bytes; the activity is built with it left in and plays at once. A picture, or an address that is not http(s), is left out.
  • Download sends needs-bytes for the preview's files, and the page draws progress under the stage while the activity plays on.
  • Files sent unasked only enable the Download link: nothing is saved or shown without Download pressed, one package is built at a time, and a file that arrives late does not restart the activity or take the place of one being built into a download.
  • built is not sent for a preview, since its address expires; it is sent once the package with the files in it is built.

What a person sees

  • The video starts in about a second; under the stage, "its video plays from the chat" replaces the size.
  • Download says "Preparing…" and a progress row shows how much of the file has come, or the person can choose the file from their computer instead.
  • If a build for Download fails, "Try again" builds from the files already brought, without asking for them again.
  • The "Add your video" question waits for the framing page to answer, so it does not flash up.
  • @missing-elements/h5p-author moves to 0.16.0.